@comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/misc.texi,v 1.28 2019/06/06 04:33:11 takayama Exp $ \BJP @node その他,,, 組み込み函数 @section その他 \E \BEG @node Miscellaneouses,,, Built-in Function @section Miscellaneouses \E @menu * ctrl:: * debug:: * error:: * help:: * time:: * cputime tstart tstop:: * timer:: * currenttime:: * sleep:: * heap:: * version:: * shell:: * map:: * flist:: * delete_history:: * get_rootdir:: * getopt:: * getenv:: @end menu \JP @node ctrl,,, その他 \EG @node ctrl,,, Miscellaneouses @subsection @code{ctrl} @findex ctrl @table @t @item ctrl("@var{switch}"[,@var{obj}]) \JP :: 環境設定 \EG :: Sets the value of @var{switch}. @item ctrl() \JP :: 環境の表示 \EG :: Show the values of @var{switch}'s. @item ctrl(|desc=1) \JP :: 環境およびその短い説明の表示 \EG :: Show the values of @var{swtich}'s and short descriptions @end table @table @var @item return \JP 設定されている値 \EG value of @var{switch} @item switch \JP スイッチ名 \EG switch name @item obj \JP パラメタ \EG parameter @end table @itemize @bullet \BJP @item @b{Asir} の実行環境の設定変更, 参照を行う. @item @var{switch} のみの場合, そのスイッチの現在の状態を返す. @item @var{obj} が与えられているとき, その値を設定する. @item スイッチは文字列として入力する. すなわちダブルクォートで囲む. @item スイッチは次の通り. @table @code @item adj ガーベッジコレクションの頻度の変更. 1 以上の有理数が指定できる. デフォルト値は 3. 1 に近い程, ガーベッジコレクションせずにヒープを 大きくとるようになる. 整数値はコマンドラインで指定できる. @xref{コマンドラインオプション}. @item allow_laurent 1 の時, 単項式の指数に負の整数を許す. @item bigfloat 1 の時, 入力された浮動小数は @b{bigfloat} に変換され, 浮動小数演算は @b{PARI} (@ref{pari}) により行われる. デフォルトの有効桁数は 9 桁である. 有効桁数を増やしたい時には @code{setprec()} を用いる. 0 の時, 入力された浮動小数は, 倍精度浮動小数に変換される. @cindex PARI @item cputime 1 の時 CPU time および GC time を表示, 0 の時表示しない. @code{cputime()} を参照. @code{ctrl("cputime",@var{onoff})} は @code{cputime(@var{onoff})} と同じである. @item debug_plot 1 の時, @code{ox_plot} がメッセージウィンドウつきで起動される. @item debug_up 1の時, 1変数専用多項式環関数(@code{umul()}など)実行時にメッセージを表示する. @item debug_window 1 の時 debug_window がポップアップして開く. (デフォルト値は 0.) @item diag_period @code{nd_gr()}, @code{nd_gr_trace()} を斉次イデアルに対して実行する際, 途中で実行される中間基底間の相互簡約 の頻度を指定する. 値が @code{n} なら, 新しく基底が @code{n}個生成されるたびに相互簡約が 実行される. @item double_output 1 の時, 倍精度浮動小数はつねに ddd.ddd の形で表示される. @item echo 1 の時は標準入力を繰り返して出力し, 0 の時は標準入力を繰り返さない. @code{output} コマンドを用いる際に有効である. @item evalef 0 の時 eval の引数が評価されたときそれ以上評価できなくなった場合, 不定元リストに 登録される. たとえば eval(sin(0.1)) と実行すると sin(0.1) がそれ以上評価できないため 不定元リストに登録される. 1 の時は, 登録されない. 初等関数の数値評価を繰り返し行う時はこのオプションを使用すべきである. (デフォルト値は 0.) @xref{ord} @item error_in_timer 1 の時, タイマー終了時に通常のエラー処理が実行される. @item f4_nocheck 1の時, @code{nd_f4}, @code{nd_f4_trace} における行列の簡約をCRTで行う際に, 結果の チェックを行わない. @item fake_ox_reset @itemx no_ox_reset 1 のとき, ox_reset を実装してないサーバーには代わりに ox_shutdown を送信する. ox_reset の実装の有無は mathcap の optional argument (第四引数) に文字列 no_ox_reset が設定されているかどうかで判断する. ox_pari を利用するときはこのフラグを1にしておくことが望ましい. (デフォルト値は 0.) @xref{分散計算}. @item fortran_output 1 の時, 多項式の表示が FORTRAN スタイルになる. すなわち冪が @samp{^} の代わりに @samp{**} で表される. (デフォルト値は 0.) @item hex 1 の時, 整数は 0x で始まる 16 進数として表示される. -1 のとき, 16 進数は, 間に @samp{|} をはさんで 8 桁ごとに区切って表示される. @item hideargs 1の時, 関数呼び出しを表示する際に引数が表示されない. @item loadpath @code{ASIRLOADPATH} を上書きする. @item message 1 の時, @code{ox_asir}, @code{ox_plot} 実行時に開始メッセージを表示する. @item new_hensel 1 の時, 有理数体上の1変数多項式の因数分解において, 関数 @code{hensel2()} が用いられる. @item nez EZGCD のアルゴリズムの切替え. デフォルトで 1 であり, とくに切替える必要 はない. @item no_debug_on_error 1 の時, エラー時にデバッグモードに入らない. @item no_prompt 1の時, プロンプトが表示されない. @item outputstyle 1 の時, 行列, ベクトルが @code{mat(...)}, @code{vect(...)} の形で表示される. @item ox_batch 1 のとき, 送信バッファがいっぱいになった時のみ自動的に flush. 0 のとき, データ, コマンド送信毎に flush. (デフォルト値は 0.) @xref{分散計算}. @item ox_check 1 のとき, 送信データを相手プロセスが受け取れるかどうかチェックする. 0 のときしない. (デフォルト値は 1.) @xref{分散計算}. @item ox_exchange_mathcap 1 のとき, OX server との接続開始時に, 自動的に mathcap の交換を行う. (デフォルト値は 1.) @xref{分散計算}. @item plot_by_bigfloat N のとき, 10進数での精度を N 桁として, bigfloat を用いて plot を行う. (デフォルトでは double を用いて plot を行う.) @item print_quote quote データの表示方法を指定する. 0 の時, quote データは単に @code{<...quoted...>}と表示される. 1 の時, リスト形式で表示される. 2 の時, 自然な数式の形で表示される. @item prompt 0 のときプロンプトを表示しない. 1 のとき標準プロンプトを表示. C スタイルのフォマット文字列をもちいるとユーザ定義のプロンプト. 例(asirgui では不可): @code{ ctrl("prompt","\033[32m[%d]:= \033[0m")} @item quiet_mode 1 のとき, 起動時に著作権表示を行わない. @xref{コマンドラインオプション}. @item real_binary 1の時, 倍精度浮動小数を2進表示する. @item real_digit 倍精度浮動小数の表示の桁数を指定する. @item show_crossref 1 の時, 関数定義を読み込む際に, クロスリファレンスが表示される. @item show_orderspec 1 の時, dp 系関数によるグレブナー基底計算関数に対する複合的な項順序の指定時に その詳細を表示する. @item StrassenSize Strassen-Winograd による行列の高速乗算アルゴリズム実行におけるパラメタの値を設定する. @item terse 1 の時, ユーザ定義 callback 実行時にメッセージを表示しない. @item weight_check 1 の時, nd 系関数によるグレブナー基底において, 指定された weight を用いたweight のoverflow チェックを行う. @item verbose 1 の時, 函数の再定義時にメッセージを表示する. @end table \E \BEG @item This function is used to set or to get the values of switches. The switches are used to control an execution of @b{Asir}. @item If @var{obj} is not specified, the value of @var{switch} is returned. @item If @var{obj} is specified, the value of @var{switch} is set to @var{obj}. @item Switches are specified by strings, namely, enclosed by two double quotes. @item Here are of switches of @b{Asir}. @table @code @item cputime If `on', CPU time and GC time is displayed at every top level evaluation of @b{Asir} command; if `off', not displayed. @xref{cputime tstart tstop}. (The switch is also set by command @code{cputime(1)}, and reset by @code{cputime(0)}.) @item nez Selection for EZGCD algorithm. It is set to 1 by default. Ordinary users need not change this setting. @item echo If `on', inputs from the standard input will be echoed onto the standard output. When executing to load a file, the contents of the file will be written onto the standard output. If `off', the inputs will not be echoed. This command will be useful when used with command @code{output}. @item bigfloat If `on', floating operations will be done by @b{PARI} system with arbitrary precision floating point operations. Default precision is set to 9 digits. To change the precision, use command @code{setbprec setprec}. If `off', floating operations will be done by @b{Asir}'s own floating operation routines with a fixed precision operations of standard floating double. @cindex PARI @item adj Sets the frequency of garbage collection. A rational number greater than or equal to 1 can be specified. The default value is 3. If a value closer to 1 is specified, larger heap is allocated and as a result, the frequency of garbage collection decreases. @xref{Command line options}. @item verbose If `on' a warning messages is displayed when a function is redefined. @item quiet_mode If 1 is set, the copyright notice has been displayed at boot time. @item prompt If the value is 0, then prompt is not output. If the value is 1, then the standard prompt is output. Asir prompt can be customized by giving a C-style format string. Example (for unix asir); @code{ ctrl("prompt","\033[32m[%d]:= \033[0m")} @item hex If 1 is set, integers are displayed as hexadecimal numbers with prefix @code{0x}. if -1 is set, hexadecimal numbers are displayed with @samp{|} inserted at every 8 hexadecimal digits. @item real_digit Sets the number of digits used to print a floating double. @item double_output If set to 1, any floating double is printed in the style ddd.ddd. @item fortran_output If `on' polynomials are displayed in FORTRAN style. That is, a power is represented by @samp{**} instead of @samp{^}. The default value is 'off. @item ox_batch If 'on', the OpenXM send buffer is flushed only when the buffer is full. If 'off', the buffer is always flushed at each sending of data or command. The default value is 'off'. @xref{Distributed computation}. @item ox_check If 'on' the check by mathcap is done before sending data. The default value is 'on'. @xref{Distributed computation}. @item ox_exchange_mathcap If 'on' Asir forces the exchange of mathcaps at the communication startup. The default value is 'on'. @xref{Distributed computation}. @item debug_window When 1, a debug window pops up. (The default value is 0.) @item no_debug_on_error When 1, asir or ox_asir do not get into the debug mode. @item fake_ox_reset When 1, the function ox_reset sends ox_shutdown insread of ox_reset to servers which do not implement ox_reset protocol. It is checked by the optional argument (the fourth argument) containing the string "no_ox_reset" of mathcap if ox_reset is implemented or not. When you use ox_pari, it is recommended to set this flag 1. (The default value is 0.) @xref{Distributed computation}. @item plot_by_bigfloat If its value N is not equal to zero, then plotting is done by bigfloat. (The double numbers are used as the default.) @item evalef When it is set to 0, the arguments of eval are registered to the list of indeterminants when arguments are no longer to be simplified. For example, when this flag is 0, sin(0.1) is registered to the list of indeterminants when eval(sin(0.1)) is evaluated. When it is set to 1, arguments are numerically evaluated. It is recommended to turn on this option, when you repeat to evaluate elementary functions numerically. (The default value is 0.) @xref{ord} @end table \E @end itemize @example [1917] ctrl(); [[oxpari_start,0],[oxpari_id,-1],... snip ....,[plot_by_bigfloat,0],[debug_plot,0]] [1918] map(print,ctrl(|desc=1)); [oxpari_start,0,oxpari starting function.] [oxpari_id,-1,Id of ox_pari.] ... snip ... [plot_by_bigfloat,0,If set to 1, computation is done by using MPFR bigfloat functions in ox_plot.] [debug_plot,0,If set to 1, ox_plot is executed with the message window.] @end example @table @t \JP @item 参照 \EG @item References @fref{cputime tstart tstop}, @fref{output}, @fref{pari}, @fref{setbprec setprec}, @fref{eval deval}. @end table @noindent ChangeLog @itemize @bullet @item @xref{ChangeLog} \BEG @item plot_by_bigfloat switch is added on 2017.09.04. The following files are changed. \E \BJP @item 欠けていたスイッチの説明を追加した (2018.3.29). @item plot_by_bigfloat スイッチは 2017.09.04 に加えられた. 変更を受けたファイルは下記のとおり. \E @item 1.54 ctrl.c, 1.14 bf.c, 1.75 tcpf.c, 1.13 calc.c, 1.36 if.c, 1.25 ifplot.h, 1.33 plotf.c @end itemize \JP @node debug,,, その他 \EG @node debug,,, Miscellaneouses @subsection @code{debug} @findex debug @table @t @item debug \JP :: デバッグモードに入る. \EG :: Forces to enter into debugging mode. @end table @itemize @bullet \BJP @item @code{debug} は無引数の函数であるが, @samp{()} なしで呼び出せる. @item デバッグモードに入るとプロンプトが @code{(debug)} となり, コマンド 受け付け状態となる. @code{quit} を入力するとデバッガから抜ける. @item デバッグモードについての詳細は @xref{デバッガ}. \E \BEG Function @code{debug} is a function with no argument. It can be called without @samp{()}. @item In the debug-mode, you are prompted by @code{(debug)} and the debugger is ready for commands. Typing in @code{quit} (Note! without a semicolon.) brings you to exit the debug-mode. @item See @ref{Debugger} for details. \E @end itemize @example [1] debug; (debug) quit 0 [2] @end example \JP @node error,,, その他 \EG @node error,,, Miscellaneouses @subsection @code{error} @findex error @table @t @item error(@var{message}) \JP :: プログラム中で強制的にエラーを発生させる. \EG :: Forces @b{Asir} to cause an error and enter debugging mode. @end table @table @var @item message \JP 文字列 \EG string @end table @itemize @bullet \BJP @item 一般に, 引数の間違いなど, 続行不可能なエラーが組み込み函数において 発生した時, トップレベルに戻る前に, 可能ならばそのエラーの時点で デバッグモードに入る. @code{error()} は, ユーザ函数の内部でこの 動作と同様の動作を行わせるための函数である. @item 引数は, @code{error()} が呼び出される際に表示されるメッセージで, 文字列である. @item ユーザ函数において, 変数をチェックして, あり得ない値の場合に @code{error()} を呼び出すようにしておけば, その時点で自動的にデバッグモードに入れる. \E \BEG @item When @b{Asir} encounters a serious error such that it finds difficult to continue execution, it, in general, tries to enter debugging mode before it returns to top level. The command @code{error()} forces a similar behavior in a user program. @item The argument is a string which will be displayed when @code{error()} will be executed. @item You can enter the debug-mode when your program encounters an illegal value for a program variable, if you have written the program so as to call @code{error()} upon finding such an error in your program text. \E @end itemize @example % cat mod3 def mod3(A) @{ if ( type(A) >= 2 ) error("invalid argument"); else return A % 3; @} end$ % asir [0] load("mod3"); 1 [3] mod3(5); 2 [4] mod3(x); invalid argument stopped in mod3 at line 3 in file "./mod3" 3 error("invalid argument"); (debug) print A A = x (debug) quit return to toplevel [4] @end example @table @t \JP @item 参照 \EG @item References @fref{debug}. @end table \JP @node help,,, その他 \EG @node help,,, Miscellaneouses @subsection @code{help} @findex help @table @t @item help(["@var{function}"]) \JP :: 函数の説明を表示する. \EG :: Displays the description of function @var{function}. @end table @table @var @item return 0 @item function \JP 函数名 \EG function name @end table @itemize @bullet \BJP @item 無引数の時, 最小限の説明が表示される. 函数名が引数として与えられた とき, 標準ライブラリディレクトリにある @samp{help} というディレクトリ に同名のファイルがあれば, 環境変数 @code{PAGER} に設定されているコマンド, あるいは @samp{more} を呼び出してそのファイルを表示する. @item 環境変数 @code{LANG} が設定されている場合, その値が @code{"japan"} または @code{"ja_JP"} で始まるなら, @samp{help} の代わりに @samp{help-ja} にあるファイルが表示される. そうでない場合, @samp{help-en} にあるファイルが表示される. @item Windows 版では, コマンドラインからのヘルプ呼び出しは未サポートだが, メニューから HTML 形式のものを呼び出し用いることができる. \E \BEG @item If invoked without argument, it displays rough usage of @b{Asir}. @item If a function name is given and if there exists a file with the same name in the directory @samp{help} under standard library directory, the file is displayed by a command set to the environmental variable @code{PAGER} or else command @samp{more}. @item If the @code{LANG} environment variable is set and its value begins with @code{"japan"} or @code{"ja_JP"}, then the file in @samp{help-ja} is displayed. If its value does not begin with @code{"japan"} or @code{"ja_JP"}, then the file in @samp{help-en} is displayed. @item On Windows HTML-style help is available from the menu. \E @end itemize \JP @node time,,, その他 \EG @node time,,, Miscellaneouses @subsection @code{time} @findex time @table @t @item time() \JP :: セッション開始から現在までの CPU 時間および GC 時間を表示する \BEG :: Returns a four element list consisting of total CPU time, GC time, the elapsed time and also total memory quantities requested from the start of current @b{Asir} session. \E @end table @table @var @item return \JP リスト \EG list @end table @itemize @bullet \BJP @item CPU 時間および GC 時間の表示に関するコマンドである. @item GC 時間とは, ガーベジコレクタにより消費されたと見なされる時間, CPU 時間は, 全体の CPU 時間から GC 時間を引いた残りで, 単位は秒である. @item @code{time()} は引数なしで, セッション開始から現在までの CPU 時間, GC 時間, 現在までに要求されたメモリののべ容量, およびセッション開始から 現在までの経過時間の表示をする. すなわち, @code{[CPU 時間 (秒), GC 時間 (秒), メモリ量 (ワード), 経過時間 (秒)]} なるリストを返す. 1 ワードは通常 4 バイトである. @item 計算の実行開始時, 終了時の @code{time()} から, その計算に対する CPU 時間, GC 時間がわかる. @item メモリ量は多倍長数ではないため, ある値を越えると無意味な値となるため あくまでも目安として用いるべきである. @item @code{ctrl()} や @code{cputime()} により @code{cputime} スイッチが on になっている場合には, トップレベルの文を一つの単位として, その実行時間が表示される. しかし, プログラムの内部などで, 特定の 計算に対する計算時間を知りたい時には, @code{time()} などを使う 必要がある. @item @code{getrusage()} が使える UNIX 上では @code{time()} は信頼性のある値 を返すが, Windows 95, 98 上では時刻を用いるほか方法がないため経過時間そのもの が表示される. よって, 待ち状態があると, それも経過時間に加算される. \E \BEG @item These are commands regarding CPU time and GC time. @item The GC time is the time regarded to spent by the garbage collector, and the CPU time is the time defined by subtracting the GC time from the total time consumed by command @b{Asir}. Their unit is `second.' @item Command @code{time()} returns total CPU time and GC time measured from the start of current @b{Asir} session. It also returns the elapsed time. Time unit is `second.' Moreover, it returns total memory quantities in words (usually 4 bytes) which are requested to the memory manager from the beginning of the current session. The return value is a list and the format is @code{[CPU time, GC time, Memory, Elapsed time]}. @item You can find the CPU time and GC time for some computation by taking the difference of the figure reported by @code{time()} at the beginning and the ending of the computation. @item Since arbitrary precision integers are NOT used for counting the total amount of memory request, the number will eventually happen to become meaningless due to integer overflow. @item When @code{cputime} switch is active by @code{ctrl()} or by @code{cputime()}, the execution time will be displayed after every evaluation of top level statement. In a program, however, in order to know the execution time for a sequence of computations, you have to use @code{time()} command, for an example. @item On UNIX, if @code{getrusage()} is available, @code{time()} reports reliable figures. On Windows NT it also gives reliable CPU time. However, on Windows 95/98, the reported time is nothing but the elapsed time of the real world. Therefore, the time elapsed in the debug-mode and the time of waiting for a reply to interruption prompting are added to the elapsed time. \E @end itemize @example [72] T0=time(); [2.390885,0.484358,46560,9.157768] [73] G=hgr(katsura(4),[u4,u3,u2,u1,u0],2)$ [74] T1=time(); [8.968048,7.705907,1514833,63.359717] [75] ["CPU",T1[0]-T0[0],"GC",T1[1]-T0[1]]; [CPU,6.577163,GC,7.221549] @end example @table @t \JP @item 参照 \EG @item References @fref{cputime tstart tstop}, @fref{currenttime}. @end table \JP @node cputime tstart tstop,,, その他 \EG @node cputime tstart tstop,,, Miscellaneouses @subsection @code{cputime}, @code{tstart}, @code{tstop} @findex cputime @findex tstart @findex tstop @table @t @item cputime(@var{onoff}) \JP :: 引数が 0 ならば @code{cputime} の表示を止める. それ以外ならば表示を行う. \BEG :: Stop displaying @code{cputime} if its argument is 0, otherwise start displaying @code{cputime} after every top level evaluation of Asir command. \E @item tstart() \JP :: CPU time 計測開始. \EG :: Resets and starts timer for CPU time and GC time. @item tstop() \JP :: CPU time 計測終了および表示. \BEG :: Stops timer and then displays CPU time GC time elapsed from the last time when timer was started. \E @end table @table @var @item return 0 @item onoff \JP フラグ (任意) \EG flag (arbitrary) @end table @itemize @bullet \BJP @item @code{cputime()} は, 引数が 0 ならば CPU time の表示を止める. それ以外ならば表示を行う. @item @code{tsart} は引数なし, @samp{()} なしで, CPU time 計測を開始する. @item @code{tstop} は引数なし, @samp{()} なしで, CPU time 計測を終了, および表示する. @item @code{cputime(@var{onoff})} は @code{ctrl("cputime",@var{onoff})} と同じである. @item @code{tstart}, @code{tstop} は, 入れ子にして使われることは想定していない ため, そのような可能性がある場合には, @code{time()} による計測を行う 必要がある. @item @code{cputime()} による on, off は, 単に表示の on, off であり, トップレベル の一つの文に対する計測は常に行われている. よって, 計算を始めてからでも, 計算終了前にデバッガに入って @code{cputime(1)} を実行させれば計算時間は 表示される. \E \BEG @item Command @code{cputime()} with NON-ZERO argument enables @b{Asir} to display CPU time and GC time after every evaluation of top level @b{Asir} command. The command with argument 0 disables displaying them. @item Command @code{tstart()} starts measuring CPU time and GC time without arguments. The parentheses @samp{()} may be omitted. @item Command @code{tstop()} stops measuring CPU time and GC time and displays them without arguments. The parentheses @samp{()} may be omitted. @item Command @code{cputime(@var{onoff})} has same meaning as @code{ctrl("cputime",@var{onoff})}. @item Nested use of @code{tstart()} and @code{tstop()} is not expected. If such an effect is desired, use @code{time()}. @item On and off states by @code{cputime()} have effects only to displaying mode. Time for evaluation of every top level statement is always measured. Therefore, even after a computation has already started, you can let @b{Asir} display the timings, whenever you enter the debug-mode and execute @code{cputime(1)}. \E @end itemize @example [49] tstart$ [50] fctr(x^10-y^10); [[1,1],[x+y,1],[x^4-y*x^3+y^2*x^2-y^3*x+y^4,1],[x-y,1], [x^4+y*x^3+y^2*x^2+y^3*x+y^4,1]] [51] tstop$ 80msec + gc : 40msec @end example @table @t \JP @item 参照 \EG @item References @fref{time}, @fref{currenttime}, @fref{ctrl}. @end table \JP @node timer,,, その他 \EG @node timer,,, Miscellaneouses @subsection @code{timer} @findex timer @table @t @item timer(@var{interval},@var{expr},@var{val}) \JP :: 制限時間つきで計算を実行する. \EG :: Compute an expression under the interval timer. @end table @table @var @item return \JP 結果 \EG result @item interval \JP 制限時間 (秒) \EG interval (second) @item expr \JP 計算する式 \EG expression to be computed @item val \JP タイマによる中断時の戻り値 \EG a value to be returned when the timer is expired @end table @itemize @bullet \BJP @item @code{timer()} は, 時間を指定して計算を実行する. 指定時間内に計算が完了 した場合その値を返す. 指定時間内に計算が完了しなかった場合, 第 3 引数 を返す. @item 第 3 引数の値は, 計算が完了した場合の値と区別できる必要がある. \E \BEG @item @code{timer()} computes an expression under the interval timer. If the computation finishes within the specified interval, it returns the result of the computation. Otherwise it returns the third argument. @item The third argument should be distinguishable from the result on success. \E @end itemize @example [0] load("cyclic"); 1 [10] timer(10,dp_gr_main(cyclic(7),[c0,c1,c2,c3,c4,c5,c6],1,1,0),0); interval timer expired (VTALRM) 0 [11] @end example \JP @node currenttime,,, その他 \EG @node currenttime,,, Miscellaneouses @subsection @code{currenttime} @findex currenttime @table @t @item currenttime() \JP :: 現在時刻を取得 \EG :: Get current time. @end table @table @var @item return \JP 1970年1月1日0時0分0秒からの経過秒数. \EG UNIX time. @end table @itemize @bullet @item \JP @code{currenttime()} は現在時刻を返す. UNIX の場合, time(3) を呼んでいるだけである. \EG See also time(3) in UNIX manuals. @end itemize @example [0] currenttime(); 1071639228 [1] @end example \JP @node sleep,,, その他 \EG @node sleep,,, Miscellaneouses @subsection @code{sleep} @findex sleep @table @t @item sleep(@var{interval}) \JP :: プロセスの実行を停止 \EG :: Suspend computation for an interval. @end table @table @var @item return 1 @item interval \JP 停止時間 (マイクロ秒) \EG interval (micro second) @end table @itemize @bullet @item \JP @code{sleep()} は, プロセスの実行を停止する. UNIX の場合, usleep を呼んでいるだけである. \EG See also usleep(3) in UNIX manuals. @end itemize @example [0] sleep(1000); 1 [1] @end example \JP @node heap,,, その他 \EG @node heap,,, Miscellaneouses @subsection @code{heap} @findex heap @table @t @item heap() \JP :: 現在のヒープの大きさを返す. (単位:バイト) \EG :: Heap area size currently in use. @end table @table @var @item return \JP 自然数 \EG non-negative integer @end table @itemize @bullet \BJP @item 現在のヒープの大きさ(単位 : バイト) を返す. ヒープとは, @b{Asir} の さまざまな数式や, ユーザプログラムなどがおかれるメモリの領域で, ガーベジ コレクタにより管理されている. プログラムの動作中は, ヒープの大きさは 単調非減少であり, 実メモリの量をこえて大きくなった場合には, OS による スワップエリアへの読み書きがほとんどの計算時間を占めることになる. @item 実メモリが少ない場合には, 起動時の @code{-adj} オプションにより, GC 主体の設定を行っておく必要がある. \E \BEG @item Command @code{heap()} returns an integer which is the byte size of current @b{Asir} heap area. Heap is a memory area where various data for expressions and user programs of @b{Asir} and is managed by the garbage collector. While @b{Asir} is running, size of the heap is monotonously non-decreasing against the time elapsed. If it happens to exceed the real memory size, most (real world) time is consumed for swapping between real memory and disk memory. @item For a platform with little real memory, it is recommended to set up @b{Asir} configuration tuned for GC functions by @code{-adj} option at the activation of @b{Asir}. (@xref{Command line options}.) \E @end itemize @example % asir -adj 16 [0] load("fctrdata")$ 0 [97] cputime(1)$ 0msec [98] heap(); 524288 0msec [99] fctr(Wang[8])$ 3.190sec + gc : 3.420sec [100] heap(); 1118208 0msec [101] quit; % asir [0] load("fctrdata")$ 0 [97] cputime(1)$ 0msec [98] heap(); 827392 0msec [99] fctr(Wang[8])$ 3.000sec + gc : 1.180sec [100] heap(); 1626112 0msec [101] quit; @end example @table @t \JP @item 参照 \EG @item References \JP @fref{コマンドラインオプション}. \EG @fref{Command line options}. @end table \JP @node version,,, その他 \EG @node version,,, Miscellaneouses @subsection @code{version} @findex version @table @t @item version() \JP :: @b{Asir} のバージョンを返す. \EG :: Version identification number of @b{Asir}. @end table @table @var @item return \JP 自然数 \EG integer @end table @itemize @bullet \BJP @item @b{Asir} のバージョンを自然数で返す. \E \BEG @item Command @code{version()} returns the version identification number, an integer of @b{Asir} in use. \E @end itemize @example [0] version(); 991214 @end example \JP @node shell,,, その他 \EG @node shell,,, Miscellaneouses @subsection @code{shell} @findex shell @table @t @item shell(@var{command}) \JP :: @var{command} をシェルコマンドとして実行する. \EG :: Execute shell commands described by a string @var{command}. @end table @table @var @item return \JP 自然数 \EG integer @item command \JP 文字列 \EG string @end table @itemize @bullet \BJP @item @var{command} を C の @code{system()} 函数によりシェルコマンドとして実行する. シェルの終了ステータスを返す. \E \BEG Execute shell commands described by a string @var{command} by a C function @code{system()}. This returns the exit status of shell as its return value. \E @end itemize @example [0] shell("ls"); alg da katsura ralg suit algt defs.h kimura ratint test alpi edet kimura3 robot texput.log asir.o fee mfee sasa wang asir_symtab gr mksym shira wang_data base gr.h mp snf1 wt bgk help msubst solve chou hom p sp const ifplot proot strum cyclic is r sugar 0 [1] @end example \JP @node map,,, その他 \EG @node map,,, Miscellaneouses @subsection @code{map} @findex map @table @t @item map(@var{function},@var{arg0},@var{arg1},...) \JP :: リスト, 配列の各要素に函数を適用する. \EG :: Applies a function to each member of a list or an array. @end table @table @var @item return \JP @var{arg0} と同じ型のオブジェクト \EG an object of the same type as @var{arg0}. @item function \JP 函数名 \EG the name of a function @item arg0 \JP リスト, ベクトル, 行列 \EG list, vector or matrix @item arg1 ... \JP 任意 (残りの引数) \EG arbitrary (the rest of arguments) @end table @itemize @bullet \BJP @item @var{arg0} の各要素を最初の引数, @var{arg1} 以下の残りの引数として 函数 @var{function} を呼び出し, @var{arg0} の対応する要素の位置に 函数呼び出しの結果が入った同じ型のオブジェクトを生成して返す. @item @var{function} は, ダブルクォートのない函数名を用いる. @item @var{function} にプログラム変数は使えない. @item @var{arg0} がリスト, ベクトル, 行列以外の場合, 単に @var{arg0}, @var{arg1}, ... を引数として @var{function} を呼び出しその 結果を返す. @item @code{map} の引数 @var{function} で与えられる函数は, 内部的にも函数と して実装されていなければならない. そうでなければ parse error になる. 例えば @code{map} 自身や @code{car}, @code{cdr} などは内部的には函数で はなく, Asir の文法におけるキーワードとして実装されている. したがって @code{map} の引数に @code{map} をとることはできない. \E \BEG @item Returns an object of the same type as @var{arg0}. Each member of the returned object is the return value of a function call where the first argument is the member of @var{arg0} corresponding to the member in the returned object and the rest of the argument are @var{arg1}, @dots{}. @item @var{function} is a function name itself without @samp{"}. @item A program variable cannot be used as @var{function}. @item If @var{arg0} is neither list nor array this function simply returns the value of @var{function}(@var{arg0},@var{arg1},@dots{}). \E @end itemize @example [82] def afo(X) @{ return X^3; @} [83] map(afo,[1,2,3]); [1,8,27] @end example \JP @node flist,,, その他 \EG @node flist,,, Miscellaneouses @subsection @code{flist} @findex flist @table @t @item flist([mname]) \JP :: 現在定義されている函数名を文字列リストとして返す. \EG :: Returns the list of function names currently defined. @item mname \JP モジュール名 \EG a module name @end table @table @var @item return \JP 文字列のリスト \EG list of character strings @end table @itemize @bullet \BJP @item 現在定義されている組み込み函数, ユーザ定義函数の函数名を文字列リスト として返す. モジュール名が指定された場合, そのモジュールで定義されている 関数名のみを返す. @item システム函数の後にユーザ定義函数が続く. \E \BEG @item Returns the list of names of built-in functions and user defined functions currently defined. The return value is a list of character strings. If a module name is specified, only the names of functions defined in the module are returned. @item The names of built-in functions are followed by those of user defined functions. \E @end itemize @example [77] flist(); [defpoly,newalg,mainalg,algtorat,rattoalg,getalg,alg,algv,...] @end example \JP @node delete_history,,, その他 \EG @node delete_history,,, Miscellaneouses @subsection @code{delete_history} @findex delete_history @table @t @item delete_history([@var{index}]) \JP :: ヒストリを消去する. \EG :: Deletes the history. @end table @table @var @item return 0 @item index \JP 消去したいヒストリの番号 \EG Index of history to be deleted. @end table @itemize @bullet \BJP @item 引数がないとき, これまで計算したヒストリを全て消去する. @item 引数があるとき, その番号の結果のみ消去する. @item ここでヒストリとは, 番号つきのプロンプトに対しての入力を評価して得られた式 で, この式は @code{@@@var{number}} により取り出すことができる. このことは, ガーベッジコレクションの際にもこの式が生き残ることを意味する. @item 大きな式がヒストリとして残った場合, 以降のメモリ管理に支障を来す場合が多い ため, @code{bsave()} などでファイルにセーブして, @code{delete_history()} によりヒストリを消去しておくのが有効である. \E \BEG @item Deletes all the histories without an argument. @item Deletes the history with index @var{index} if specified. @item A history is an expression which has been obtained by evaluating an input given for a prompt with an index. It can be taken out by @code{@@@var{index}}, which means that the expression survives garbage collections. @item A large history may do harm in the subsequent memory management and deleting the history by @code{delete_history()}, after saving it in a file by @code{bsave()}, is often effective. \E @end itemize @example [0] (x+y+z)^100$ [1] @@0; ... [2] delete_history(0); [3] @@0; 0 @end example \JP @node get_rootdir,,, その他 \EG @node get_rootdir,,, Miscellaneouses @subsection @code{get_rootdir} @findex get_rootdir @table @t @item get_rootdir() \JP :: Asir のルートディレクトリ名を取り出す \EG :: Gets the name of @b{Asir} root directory. @end table @table @var @item return \JP 文字列 \EG string @end table @itemize @bullet \BJP @item UNIX 版の場合, 環境変数 @code{ASIR_LIBDIR} が定義されている場合にはその値, されていない場合 には @samp{/usr/local/lib/asir} を返す. @item Windows 版の場合, @samp{asirgui.exe} のあるディレクトリ (@samp{bin} という名前のはずである) の親ディレクトリが返される. @item この関数が返すディレクトリ名を基準とした相対パス名を指定することにより, インストール された場所によらないファイル読み込みプログラムを書くことができる. \E \BEG @item On UNIX it returns the value of an environment variable @code{ASIR_LIBDIR} or @samp{/usr/local/lib/asir} if @code{ASIR_LIBDIR} is not set. @item On Windows the name of @b{Asir} root directory is returned. @item By using relative path names from the value of this function, one can write programs which contain file operations independent of the install directory. \E @end itemize \JP @node getopt,,, その他 \EG @node getopt,,, Miscellaneouses @subsection @code{getopt} @findex getopt @table @t @item getopt([@var{key}]) \JP :: オプションの値を返す. \EG :: Returns the value of an option. @end table @table @var @item return \JP オブジェクト \EG object @end table @itemize @bullet \BJP @item ユーザ定義関数は, 固定個数引数でしか宣言できない. ユーザ定義関数で 可変個引数を実現する方法の一つとして, オプションによる引数の指定 がある (@pxref{オプション指定}). 指定されたオプションを関数内で 受け取るためにこの関数を用いる. @item 無引数で呼び出された場合, @code{getopt()} は @code{[[key1,value1],[key2,value2],...]} なるリストを返す. ここで, @code{key} は関数呼び出し時に指定されたオプション, @code{value} はその値である. @item 関数呼び出しの際に @var{key} がオプションとして指定されている 場合には, その値を返す. もし指定がない場合には, VOID 型オブジェクト (型識別子 -1) を返す. @code{getopt()} が返した値の型を @code{type()} で調べることで, そのオプションが指定されたかどうか調べることができる. @item 関数呼び出しにおけるオプションの指定は, 正規の引数ならびの後ろに, @example xxx(A,B,C,D|x=X,y=Y,z=Z) @end example という風に, @samp{|} に続く, @var{key=value} の @samp{,} で区切られた 並びを置くことで行う. \E \BEG @item When a user defined function is called, the number of arguments must be equal to that in the declaration of the function. A function with indefinite number of arguments can be realized by using @var{options} (@pxref{option}). The value of a specified option is retrieved by @code{getopt}. @item If @code{getopt()} is called with no argument, then it returns a list @code{[[key1,value1],} @code{[key2,value2],@dots{}]}. In the list, each @code{key} is an option which was specified when the function executing @code{getopt} was invoked, and @code{value} is the value of the option. @item If an option @var{key} is specified upon a function call, @code{getopt} return the value of the option. If such an option is not specified, the it returns an object of VOID type whose object identifier is -1. By examining the type of the returned value with @code{type()}, one knows whether the option is set or not. @item Options are specified as follows: @example xxx(A,B,C,D|x=X,y=Y,z=Z) @end example That is, the options are specified by a sequence of @var{key=value} seperated by @samp{,}, after @samp{|}. \E @end itemize @table @t \JP @item 参照 \EG @item References \JP @fref{オプション指定}, @fref{type}. \EG @fref{option}, @fref{type}. @end table \JP @node getenv,,, その他 \EG @node getenv,,, Miscellaneouses @subsection @code{getenv} @findex getenv @table @t @item getenv(@var{name}) \JP :: 環境変数の値を返す. \EG :: Returns the value of an environment variable. @end table @table @var @item return @itemx name \JP 文字列 \EG string @end table @itemize @bullet @item \JP 環境変数 @var{name} の値を返す. \EG Returns the value of an environment variable @var{name}. @end itemize @example [0] getenv("HOME"); /home/pcrf/noro @end example