=================================================================== RCS file: /home/cvs/OpenXM/src/asir-doc/parts/builtin/num.texi,v retrieving revision 1.2 retrieving revision 1.13 diff -u -p -r1.2 -r1.13 --- OpenXM/src/asir-doc/parts/builtin/num.texi 1999/12/21 02:47:34 1.2 +++ OpenXM/src/asir-doc/parts/builtin/num.texi 2019/03/29 01:57:46 1.13 @@ -1,4 +1,4 @@ -@comment $OpenXM$ +@comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/num.texi,v 1.12 2016/08/29 04:56:58 noro Exp $ \BJP @node 数の演算,,, 組み込み函数 @section 数の演算 @@ -13,17 +13,21 @@ * fac:: * igcd igcdcntl:: * ilcm:: +* isqrt:: * inv:: * prime lprime:: * random:: * mt_save mt_load:: * nm dn:: * conj real imag:: -* eval:: +* eval deval:: * pari:: -* setprec:: +* setbprec setprec:: * setmod:: * lrandom:: +* ntoint32 int32ton:: +* setround:: +* inttorat:: @end menu \JP @node idiv irem,,, 数の演算 @@ -45,7 +49,7 @@ @item return \JP 整数 \EG integer -@item i1,i2 +@item i1 i2 \JP 整数 \EG integer @end table @@ -158,7 +162,7 @@ Returns 0 if the argument @var{i} is negative. @item return \JP 整数 \EG integer -@item i1,i2,i +@item i1 i2 i \JP 整数 \EG integer @end table @@ -259,7 +263,7 @@ In most cases @code{3} is the fastest, but there are e @item return \JP 整数 \EG integer -@item i1,i2 +@item i1 i2 \JP 整数 \EG integer @end table @@ -286,6 +290,26 @@ If one of argument is equal to 0, the return 0. @fref{igcd igcdcntl}, @fref{mt_save mt_load}. @end table +\JP @node isqrt,,, 数の演算 +\EG @node isqrt,,, Numbers +@subsection @code{isqrt} +@findex isqrt + +@table @t +@item isqrt(@var{n}) +\JP :: 平方根を越えない最大の整数を求める. +\EG :: The integer square root of @var{n}. +@end table + +@table @var +@item return +\JP 非負整数 +\EG non-negative integer +@item n +\JP 非負整数 +\EG non-negative integer +@end table + \JP @node inv,,, 数の演算 \EG @node inv,,, Numbers @subsection @code{inv} @@ -301,7 +325,7 @@ If one of argument is equal to 0, the return 0. @item return \JP 整数 \EG integer -@item i,m +@item i m \JP 整数 \EG integer @end table @@ -418,7 +442,7 @@ function @findex random @table @t -@item radom([@var{seed}]) +@item random([@var{seed}]) \JP :: 乱数を生成する. @end table @@ -481,7 +505,7 @@ one can trace a single random number sequence arcoss m @findex lrandom @table @t -@item lradom(@var{bit}) +@item lrandom(@var{bit}) \JP :: 多倍長乱数を生成する. \EG :: Generates a long random number. @end table @@ -692,14 +716,16 @@ These functions works also for polynomials with comple [2,11,(2-11*@@i)] @end example -\JP @node eval,,, 数の演算 -\EG @node eval,,, Numbers -@subsection @code{eval} +\JP @node eval deval ,,, 数の演算 +\EG @node eval deval,,, Numbers +@subsection @code{eval}, @code{deval} @findex eval +@findex deval @cindex PARI @table @t @item eval(@var{obj}[,@var{prec}]) +@item deval(@var{obj}) \JP :: @var{obj} の値の評価. \EG :: Evaluate @var{obj} numerically. @end table @@ -721,11 +747,18 @@ These functions works also for polynomials with comple @item @var{obj} に含まれる函数の値を可能な限り評価する. @item -計算は @b{PARI} (@xref{pari}) が行う. +@code{deval} は倍精度浮動小数を結果として +@code{eval} の場合, 有理数はそのまま残る. @item +@code{eval} においては, 計算は @b{MPFR} ライブラリが行う. +@code{deval} においては, 計算は C 数学ライブラリの関数を用いて行う. +@item +@code{deval} は複素数は扱えない. +@item +@code{eval} においては, @var{prec} を指定した場合, 計算は, 10 進 @var{prec} 桁程度で行われる. @var{prec} の指定がない場合, 現在設定されている精度で行われる. -(@xref{setprec}) +(@xref{setbprec setprec}.) @item @table @t @item 扱える函数は, 次の通り. @@ -740,7 +773,8 @@ These functions works also for polynomials with comple @code{exp}, @code{log}, @code{pow(a,b) (a^b)} @end table @item -以下の記号を数として評価できる. +以下の記号を数として評価できる. ただし @code{@@i} を扱えるのは +@code{eval}, @code{deval} のみである. @table @t @item @@i 虚数単位 @@ -755,15 +789,21 @@ These functions works also for polynomials with comple Evaluates the value of the functions contained in @var{obj} as far as possible. @item -The computation is done by @b{PARI} (@xref{pari}). +@code{deval} returns +double float. Rational numbers remain unchanged in results from @code{eval}. @item +In @code{eval} the computation is done +by @b{MPFR} library. In @code{deval} the computation is +done by the C math library. +@item +@code{deval} cannot handle complex numbers. +@item When @var{prec} is specified, computation will be performed with a precision of about @var{prec}-digits. If @var{prec} is not specified, computation is performed with the -precision set currently. (@xref{setprec}) +precision set currently. (@xref{setbprec setprec}.) @item Currently available numerical functions are listed below. -Note they are only a small part of whole @b{PARI} functions. @table @t @code{sin}, @code{cos}, @code{tan}, @@ -776,7 +816,8 @@ Note they are only a small part of whole @b{PARI} func @code{exp}, @code{log}, @code{pow(a,b) (a^b)} @end table @item -Symbols for special values are as the followings. +Symbols for special values are as the followings. Note that +@code{@@i} cannot be handled by @code{deval}. @table @t @item @@i unit of imaginary number @@ -798,12 +839,16 @@ Napier's number (@t{exp}(1)) 0.86602540378443864674620506632 [121] eval(sin(@@pi/3)-3^(1/2)/2,50); -2.78791084448179148471 E-58 +[122] eval(1/2); +1/2 +[123] deval(sin(1)^2+cos(1)^2); +1 @end example @table @t \JP @item 参照 \EG @item References -@fref{ctrl}, @fref{setprec}, @fref{pari}. +@fref{ctrl}, @fref{setbprec setprec}. @end table \JP @node pari,,, 数の演算 @@ -846,9 +891,7 @@ Napier's number (@t{exp}(1)) 函数値の評価を高速に行うことができる. @b{PARI} は他のプログラムから サブルーチンライブラリとして用いることができ, また, @samp{gp} という @b{PARI}ライブラリのインタフェースにより UNIX のアプリケーションとして -利用することもできる. 現在のバージョンは @b{2.0.17beta} でいくつかの ftp -site (たとえば @code{ftp://megrez.ceremab.u-bordeaux.fr/pub/pari}) -から anonymous ftp できる. +利用することもできる. @item 最後の引数 @var{prec} で計算精度を指定できる. @var{prec} を省略した場合 @code{setprec()} で指定した精度となる. @@ -870,8 +913,6 @@ function evaluations as well as arithmetic operations speed. It can also be used from other external programs as a library. It provides a language interface named @samp{gp} to its library, which enables a user to use @b{PARI} as a calculator which runs on UNIX. -The current version is @b{2.0.17beta}. It can be obtained by several ftp -sites. (For example, @code{ftp://megrez.ceremab.u-bordeaux.fr/pub/pari}.) @item The last argument (optional) @var{int} specifies the precision in digits for bigfloat operation. @@ -960,7 +1001,6 @@ For details of individual functions, refer to the @b{P @code{lngamma}, @code{logagm}, @code{mat}, -@code{matinvr}, @code{matrixqz2}, @code{matrixqz3}, @code{matsize}, @@ -1019,14 +1059,11 @@ For details of individual functions, refer to the @b{P \BJP @item -@b{Asir} で用いているのは @b{PARI} のほんの一部の機能であるが, 今後 -より多くの機能が利用できるよう改良する予定である. +@b{Asir} で用いているのは @b{PARI} のほんの一部の機能である. \E \BEG @item @b{Asir} currently uses only a very small subset of @b{PARI}. -We will improve @b{Asir} so that it can provide more functions of -@b{PARI}. \E @end itemize @@ -1045,19 +1082,20 @@ We will improve @b{Asir} so that it can provide more f @table @t \JP @item 参照 \EG @item References -@fref{setprec}. +@fref{setbprec setprec}. @end table -\JP @node setprec,,, 数の演算 -\EG @node setprec,,, Numbers -@subsection @code{setprec} +\JP @node setbprec setprec,,, 数の演算 +\EG @node setbprec setprec,,, Numbers +@subsection @code{setbprec}, @code{setprec} +@findex setbprec @findex setprec -@cindex PARI @table @t -@item setprec([@var{n}]) -\JP :: @b{bigfloat} の桁数を @var{n} 桁に設定する. -\EG :: Sets the precision for @b{bigfloat} operations to @var{n} digits. +@item setbprec([@var{n}]) +@itemx setprec([@var{n}]) +\JP :: @b{setbprec}, @b{setprec} は @b{bigfloat} の精度をそれぞれ 2 進, 10進 @var{n} 桁に設定する. +\EG :: @b{setbprec}, @b{setprec} set the precision for @b{bigfloat} operations to @var{n} bits, @var{n} digits respectively. @end table @table @var @@ -1075,7 +1113,7 @@ We will improve @b{Asir} so that it can provide more f 引数がある場合, @b{bigfloat} の桁数を @var{n} 桁に設定する. 引数のあるなしにかかわらず, 以前に設定されていた値を返す. @item -@b{bigfloat} の計算は @b{PARI} (@xref{pari}) によって行われる. +@b{bigfloat} の計算は @b{MPFR} ライブラリによって行われる. @item @b{bigfloat} での計算に対し有効である. @b{bigfloat} の flag を on にする方法は, @code{ctrl} を参照. @@ -1085,13 +1123,13 @@ We will improve @b{Asir} so that it can provide more f \E \BEG @item -When an argument is given, it -sets the precision for @b{bigfloat} operations to @var{n} digits. -The return value is always the previous precision in digits regardless of +When an argument @var{n} is given, these functions +set the precision for @b{bigfloat} operations to @var{n} bits or @var{n} digits. +The return value is always the previous precision regardless of the existence of an argument. @item -@b{Bigfloat} operations are done by @b{PARI}. (@xref{pari}) +@b{Bigfloat} operations are done by @b{MPFR} library. @item This is effective for computations in @b{bigfloat}. Refer to @code{ctrl()} for turning on the `@b{bigfloat} flag.' @@ -1104,18 +1142,101 @@ Therefore, it is safe to specify a larger value. @example [1] setprec(); -9 +15 [2] setprec(100); -9 +15 [3] setprec(100); -96 +99 +[4] setbprec(); +332 @end example @table @t \JP @item 参照 -@fref{ctrl}, @fref{eval}, @fref{pari}. +@fref{ctrl}, @fref{eval deval}. @end table +\JP @node setround,,, 数の演算 +\EG @node setround,,, Numbers +@subsection @code{setround} +@findex setround + +@table @t +@item setround([@var{mode}]) +\JP :: @b{bigfloat} の丸めモードを @var{mode} に設定する. +\EG :: Sets the rounding mode @var{mode}. +@end table + +@table @var +@item return +\JP 整数 +\EG integer +@item mode +\JP 整数 +\EG integer +@end table + +@itemize @bullet +\BJP +@item +引数がある場合, @b{bigfloat} の丸めモードを @var{mode} に設定する. +引数のあるなしにかかわらず, 以前に設定されていた値を返す. +丸めモードの意味は次のとおり. +@table @code +@item 0 +Round to nearest +@item 1 +Round toward 0 +@item 2 +Round toward +infinity +@item 3 +Round toward -infinity +@end table +@item +@b{bigfloat} での計算に対し有効である. +@b{bigfloat} の flag を on にする方法は, @code{ctrl} を参照. +\E +\BEG +@item +When an argument @var{mode} is given, these functions +set the rounding mode for @b{bigfloat} operations to @var{mode}. +The return value is always the previous rounding mode regardless of +the existence of an argument. +The meanings of rounding modes are as follows +@table @code +@item 0 +Round to nearest +@item 1 +Round toward 0 +@item 2 +Round toward +infinity +@item 3 +Round toward -infinity +@end table + +@item +This is effective for computations in @b{bigfloat}. +Refer to @code{ctrl()} for turning on the `@b{bigfloat} flag.' +\E +@end itemize + +@example +[1] setprec(); +15 +[2] setprec(100); +15 +[3] setprec(100); +99 +[4] setbprec(); +332 +@end example + +@table @t +\JP @item 参照 +@fref{ctrl}, @fref{eval deval}. +@end table + + \JP @node setmod,,, 数の演算 \EG @node setmod,,, Numbers @subsection @code{setmod} @@ -1177,3 +1298,113 @@ return to toplevel \EG @fref{dp_mod dp_rat}, @fref{Types of numbers}. @end table +\JP @node ntoint32 int32ton,,, 数の演算 +\EG @node ntoint32 int32ton,,, Numbers +@subsection @code{ntoint32}, @code{int32ton} +@findex ntoint32 +@findex int32ton + +@table @t +@item ntoint32(@var{n}) +@itemx int32ton(@var{int32}) +\JP :: 非負整数と符号なし 32bit 整数の間の型変換. +\EG :: Type-conversion between a non-negative integer and an unsigned 32bit integer. +@end table + +@table @var +@item return +\JP 符号なし 32bit 整数または非負整数 +\EG unsigned 32bit integer or non-negative integer +@item n +\JP 2^32 未満の非負整数 +\EG non-negative interger less than 2^32 +@item int32 +\JP 符号なし 32bit 整数 +\EG unsigned 32bit integer +@end table + +@itemize @bullet +\BJP +@item 非負整数 (識別子 1) の符号なし 32bit 整数 (識別子 10) への変換, +またはその逆変換を行う. +@item 32bit 整数は @b{OpenXM} の基本構成要素であり, 整数をその型で送信 +する必要がある場合に用いる. +\E +\BEG +@item These functions do conversions between non-negative +integers (the type id 1) and unsigned 32bit integers (the type id 10). +@item An unsigned 32bit integer is a fundamental construct of @b{OpenXM} +and one often has to send an integer to a server as an unsigned 32bit +integer. These functions are used in such a case. +\E +@end itemize + +@table @t +\JP @item 参照 +\EG @item References +\JP @fref{分散計算}, @fref{数の型}. +\EG @fref{Distributed computation}, @fref{Types of numbers}. +@end table + +\JP @node inttorat,,, 数の演算 +\EG @node inttorat,,, Numbers +@subsection @code{inttorat} +@findex inttorat + +@table @t +@item inttorat(@var{a},@var{m},@var{b}) +\JP :: 整数-有理数変換を行う. +\EG :: Perform the rational reconstruction. +@end table + +@table @var +@item return +\JP リストまたは 0 +\EG list or 0 +@item a +@itemx m +@itemx b +\JP 整数 +\EG integer +@end table + +@itemize @bullet +\BJP +@item +整数 @var{a} に対し, @var{xa=y} mod @var{m} を満たす正整数 @var{x}, 整数 @var{y} +(@var{x}, @var{|y|} < @var{b}, @var{GCD(x,y)=1}) を求める. +@item +このような @var{x}, @var{y} が存在するなら @var{[y,x]} を返し, 存在しない場合には 0 を返す. +@item +@var{b} を @var{floor(sqrt(m/2))} と取れば, @var{x}, @var{y} は存在すれば一意である. +@var{floor(sqrt(m/2))} は @code{isqrt(floor(m/2))} で計算できる. +@end itemize +\E +\BEG +@item +For an integer @var{a}, find a positive integer @var{x} and an intger @var{y} satisfying +@var{xa=y} mod @var{m}, @var{x}, @var{|y|} < @var{b} and @var{GCD(x,y)=1}. +@item +If such @var{x}, @var{y} exist then a list @var{[y,x]} is returned. Otherwise 0 is returned. +@item +If @var{b} is set to @var{floor(sqrt(M/2))}, then @var{x} and @var{y} are unique if they +exist. @var{floor(sqrt(M/2))} can be computed by @code{floor} and @code{isqrt}. +@end itemize +\E + +@example +[2121] M=lprime(0)*lprime(1); +9996359931312779 +[2122] B=isqrt(floor(M/2)); +70697807 +[2123] A=234234829304; +234234829304 +[2124] inttorat(A,M,B); +[-20335178,86975031] +@end example + +@table @t +\JP @item 参照 +\EG @item References +@fref{floor}, @fref{isqrt}. +@end table