@comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/num.texi,v 1.15 2020/09/01 09:25:32 noro Exp $ \BJP @node 数の演算,,, 組み込み函数 @section 数の演算 \E \BEG @node Numbers,,, Built-in Function @section Numbers \E @menu * idiv irem:: * fac:: * igcd igcdcntl:: * ilcm:: * isqrt:: * inv:: * prime lprime:: * random:: * mt_save mt_load:: * nm dn:: * conj real imag:: * eval deval:: * pari:: * setbprec setprec:: * setmod:: * lrandom:: * ntoint32 int32ton:: * setround:: * inttorat:: @end menu \JP @node idiv irem,,, 数の演算 \EG @node idiv irem,,, Numbers @subsection @code{idiv}, @code{irem} @findex idiv @findex irem @table @t @item idiv(@var{i1},@var{i2}) \JP :: 整数除算による商. \EG :: Integer quotient of @var{i1} divided by @var{i2}. @item irem(@var{i1},@var{i2}) \JP :: 整数除算による剰余. \EG :: Integer remainder of @var{i1} divided by @var{i2}. @end table @table @var @item return \JP 整数 \EG integer @item i1 i2 \JP 整数 \EG integer @end table @itemize @bullet \BJP @item @var{i1} の @var{i2} による整数除算による商, 剰余を求める. @item @var{i2} は 0 であってはならない. @item 被除数が負の場合, 絶対値に対する値にマイナスをつけた値を返す. @item @var{i1} @code{%} @var{i2} は, 結果が正に正規化されることを除けば @code{irem()} の代わりに用いることができる. @item 多項式の場合は @code{sdiv}, @code{srem} を用いる. \E \BEG @item Integer quotient and remainder of @var{i1} divided by @var{i2}. @item @var{i2} must not be 0. @item If the dividend is negative, the results are obtained by changing the sign of the results for absolute values of the dividend. @item One can use @var{i1} @code{%} @var{i2} for replacement of @code{irem()} which only differs in the point that the result is always normalized to non-negative values. @item Use @code{sdiv()}, @code{srem()} for polynomial quotient. \E @end itemize @example [0] idiv(100,7); 14 [0] idiv(-100,7); -14 [1] irem(100,7); 2 [1] irem(-100,7); -2 @end example @table @t \JP @item 参照 \EG @item References @fref{sdiv sdivm srem sremm sqr sqrm}, @fref{%}. @end table \JP @node fac,,, 数の演算 \EG @node fac,,, Numbers @subsection @code{fac} @findex fac @table @t @item fac(@var{i}) \JP :: @var{i} の階乗. \EG :: The factorial of @var{i}. @end table @table @var @item return \JP 整数 \EG integer @item i \JP 整数 \EG integer @end table @itemize @bullet \BJP @item @var{i} の階乗を計算する. @item @var{i} が負の場合は 0 を返す. \E \BEG @item The factorial of @var{i}. @item Returns 0 if the argument @var{i} is negative. \E @end itemize @example [0] fac(50); 30414093201713378043612608166064768844377641568960512000000000000 @end example \JP @node igcd igcdcntl,,, 数の演算 \EG @node igcd igcdcntl,,, Numbers @subsection @code{igcd},@code{igcdcntl} @findex igcd @findex igcdcntl @table @t @item igcd(@var{i1},@var{i2}) \JP :: 整数の GCD (最大公約数) \EG :: The integer greatest common divisor of @var{i1} and @var{i2}. @item igcdcntl([@var{i}]) \JP :: 整数 GCDのアルゴリズム選択 \EG :: Selects an algorithm for integer GCD. @end table @table @var @item return \JP 整数 \EG integer @item i1 i2 i \JP 整数 \EG integer @end table @itemize @bullet \BJP @item @code{igcd} は @var{i1} と @var{i2} の GCD を求める. @item 引数が整数でない場合は, エラーまたは無意味な結果を返す. @item 多項式の場合は, @code{gcd}, @code{gcdz} を用いる. @item 整数 GCD にはさまざまな方法があり, @code{igcdcntl} で設定できる. @table @code @item 0 Euclid 互除法 (default) @item 1 binary GCD @item 2 bmod GCD @item 3 accelerated integer GCD @end table @code{2}, @code{3} は @code{[Weber]} による. おおむね @code{3} が高速だが, 例外もある. \E \BEG @item Function @code{igcd()} returns the integer greatest common divisor of the given two integers. @item An error will result if the argument is not an integer; the result is not valid even if one is returned. @item Use @code{gcd()}, @code{gcdz()} for polynomial GCD. @item Various method of integer GCD computation are implemented and they can be selected by @code{igcdcntl}. @table @code @item 0 Euclid algorithm (default) @item 1 binary GCD @item 2 bmod GCD @item 3 accelerated integer GCD @end table @code{2}, @code{3} are due to @code{[Weber]}. In most cases @code{3} is the fastest, but there are exceptions. \E @end itemize @example [0] A=lrandom(10^4)$ [1] B=lrandom(10^4)$ [2] C=lrandom(10^4)$ [3] D=A*C$ [4] E=A*B$ [5] cputime(1)$ [6] igcd(D,E)$ 0.6sec + gc : 1.93sec(2.531sec) [7] igcdcntl(1)$ [8] igcd(D,E)$ 0.27sec(0.2635sec) [9] igcdcntl(2)$ [10] igcd(D,E)$ 0.19sec(0.1928sec) [11] igcdcntl(3)$ [12] igcd(D,E)$ 0.08sec(0.08023sec) @end example @table @t \JP @item 参照 \EG @item References @fref{gcd gcdz}. @end table \JP @node ilcm,,, 数の演算 \EG @node ilcm,,, Numbers @subsection @code{ilcm} @findex ilcm @table @t @item ilcm(@var{i1},@var{i2}) \JP :: 最小公倍数を求める. \EG :: The integer least common multiple of @var{i1} and @var{i2}. @end table @table @var @item return \JP 整数 \EG integer @item i1 i2 \JP 整数 \EG integer @end table @itemize @bullet \BJP @item 整数 @var{i1}, @var{i2} の最小公倍数を求める. @item 一方が 0 の場合 0 を返す. \E \BEG @item This function computes the integer least common multiple of @var{i1}, @var{i2}. @item If one of argument is equal to 0, the return 0. \E @end itemize @table @t \JP @item 参照 \EG @item References @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} @findex inv @table @t @item inv(@var{i},@var{m}) \JP :: @var{m} を法とする @var{i} の逆数 \EG :: the inverse (reciprocal) of @var{i} modulo @var{m}. @end table @table @var @item return \JP 整数 \EG integer @item i m \JP 整数 \EG integer @end table @itemize @bullet \BJP @item @var{ia} @equiv{} 1 mod (@var{m}) なる整数 @var{a} を求める. @item @var{i} と @var{m} は互いに素でなければならないが, @code{inv()} は そのチェックは行わない. \E \BEG @item This function computes an integer such that @var{ia} @equiv{} 1 mod (@var{m}). @item The integer @var{i} and @var{m} must be mutually prime. However, @code{inv()} does not check it. \E @end itemize @example [71] igcd(1234,4321); 1 [72] inv(1234,4321); 3239 [73] irem(3239*1234,4321); 1 @end example @table @t \JP @item 参照 \EG @item References @fref{igcd igcdcntl}. @end table \JP @node prime lprime,,, 数の演算 \EG @node prime lprime,,, Numbers @subsection @code{prime}, @code{lprime} @findex prime @findex lprime @table @t @item prime(@var{index}) @item lprime(@var{index}) \JP :: 素数を返す \EG :: Returns a prime number. @end table @table @var @item return \JP 整数 \EG integer @item index \JP 整数 \EG integer @end table @itemize @bullet \BJP @item @code{prime()}, @code{lprime()} いずれもシステムが内部に持つ 素数表の要素を返す. @code{index} は 0 以上の整数で, 素数表 のインデックスに用いられる. @code{prime()} は 16381 まで の素数を小さい順に 1900 個, @code{lprime()} は, 10 進 8 桁で最大の 素数から大きい順に 999 個返す. それ以外のインデックスに対しては 0 を返す. @item より一般的な素数生成函数としては, @code{pari(nextprime,@var{number})} がある. \E \BEG @item The two functions, @code{prime()} and @code{lprime()}, returns an element stored in the system table of prime numbers. Here, @code{index} is a non-negative integer and be used as an index for the prime tables. The function @code{prime()} can return one of 1900 primes up to 16381 indexed so that the smaller one has smaller index. The function @code{lprime()} can return one of 999 primes which are 8 digit sized and indexed so that the larger one has the smaller index. The two function always returns 0 for other indices. @item For more general function for prime generation, there is a @code{PARI} function @code{pari(nextprime,@var{number})}. \E @end itemize @example [95] prime(0); 2 [96] prime(1228); 9973 [97] lprime(0); 99999989 [98] lprime(999); 0 @end example @table @t \JP @item 参照 \EG @item References @fref{pari}. @end table \JP @node random,,, 数の演算 \EG @node random,,, Numbers @subsection @code{random} @findex random @table @t @item random([@var{seed}]) \JP :: 乱数を生成する. @end table @table @var @item seed @itemx return \JP 自然数 \EG non-negative integer @end table @itemize @bullet \BJP @item 最大 2^32-1 の非負整数の乱数を生成する. @item 0 でない引数がある時, その値を seed として設定してから, 乱数を生成する. @item default の seed は固定のため, 種を設定しなければ, 生成される乱数の 系列は起動毎に一定である. @item 松本眞-西村拓士による Mersenne Twister (http://www.math.keio.ac.jp/matsumoto/mt.html) アルゴリズムの, 彼ら自身による実装を用いている. @item 周期は 2^19937-1 と非常に長い. @item @code{mt_save} により state をファイルに save できる. これを @code{mt_load} で読み込むことにより, 異る Asir セッション間で一つの乱数の系列を辿ることが できる. \E \BEG @item Generates a random number which is a non-negative integer less than 2^32. @item If a non zero argument is specified, then after setting it as a random seed, a random number is generated. @item As the default seed is fixed, the sequence of the random numbers is always the same if a seed is not set. @item The algorithm is Mersenne Twister (http://www.math.keio.ac.jp/matsumoto/mt.html) by M. Matsumoto and T. Nishimura. The implementation is done also by themselves. @item The period of the random number sequence is 2^19937-1. @item One can save the state of the random number generator with @code{mt_save}. By loading the state file with @code{mt_load}, one can trace a single random number sequence arcoss multiple sessions. \E @end itemize @table @t \JP @item 参照 \EG @item References @fref{lrandom}, @fref{mt_save mt_load}. @end table \JP @node lrandom,,, 数の演算 \EG @node lrandom,,, Numbers @subsection @code{lrandom} @findex lrandom @table @t @item lrandom(@var{bit}) \JP :: 多倍長乱数を生成する. \EG :: Generates a long random number. @end table @table @var @item bit @item return \JP 自然数 \EG integer @end table @itemize @bullet \BJP @item 高々 @var{bit} の非負整数の乱数を生成する. @item @code{random} を複数回呼び出して結合し, 指定の bit 長にマスクしている. \E \BEG @item Generates a non-negative integer of at most @var{bit} bits. @item The result is a concatination of outputs of @code{random}. \E @end itemize @table @t \JP @item 参照 \EG @item References @fref{random}, @fref{mt_save mt_load}. @end table \JP @node mt_save mt_load,,, 数の演算 \EG @node mt_save mt_load,,, Numbers @subsection @code{mt_save}, @code{mt_load} @findex mt_save @findex mt_load @table @t @item mt_save(@var{fname}) \JP :: 乱数生成器の現在の状態をファイルにセーブする. \EG :: Saves the state of the random number generator. @item mt_load(@var{fname}) \JP :: ファイルにセーブされた乱数生成器の状態をロードする. \EG :: Loads a saved state of the random number generator. @end table @table @var @item return \JP 0 または 1 \EG 0 or 1 @item fname \JP 文字列 \EG string @end table @itemize @bullet \BJP @item ある状態をセーブし, その状態をロードすることで, 一つの疑似乱数系列を, 新規の Asir セッションで続けてたどることが できる. \E \BEG @item One can save the state of the random number generator with @code{mt_save}. By loading the state file with @code{mt_load}, one can trace a single random number sequence arcoss multiple @b{Asir} sessions. \E @end itemize @example [340] random(); 3510405877 [341] mt_save("/tmp/mt_state"); 1 [342] random(); 4290933890 [343] quit; % asir This is Asir, Version 991108. Copyright (C) FUJITSU LABORATORIES LIMITED. 3 March 1994. All rights reserved. [340] mt_load("/tmp/mt_state"); 1 [341] random(); 4290933890 @end example @table @t \JP @item 参照 \EG @item References @fref{random}, @fref{lrandom}. @end table \JP @node nm dn,,, 数の演算 \EG @node nm dn,,, Numbers @subsection @code{nm}, @code{dn} @findex nm @findex dn @table @t @item nm(@var{rat}) \JP :: @var{rat} の分子. \EG :: Numerator of @var{rat}. @item dn(@var{rat}) \JP :: @var{rat} の分母. \EG :: Denominator of @var{rat}. @end table @table @var @item return \JP 整数または多項式 \EG integer or polynomial @item rat \JP 有理数または有理式 \EG rational number or rational expression @end table @itemize @bullet \BJP @item 与えられた有理数また有理式の分子及び分母を返す. @item 有理数の場合, 分母は常に正で, 符号は分子が持つ. @item 有理式の場合, 単に分母, 分子を取り出すだけである. 有理式に対しては, 約分は自動的には行われない. @code{red()} を明示的に呼び出す必要がある. \E \BEG @item Numerator and denominator of a given rational expression. @item For a rational number, they return its numerator and denominator, respectively. For a rational expression whose numerator and denominator may contain rational numbers, they do not separate those rational coefficients to numerators and denominators. @item For a rational number, the denominator is always kept positive, and the sign is contained in the numerator. @item @b{Risa/Asir} does not cancel the common divisors unless otherwise explicitly specified by the user. Therefore, @code{nm()} and @code{dn()} return the numerator and the denominator as it is, respectively. \E @end itemize @example [2] [nm(-43/8),dn(-43/8)]; [-43,8] [3] dn((x*z)/(x*y)); y*x [3] dn(red((x*z)/(x*y))); y @end example @table @t \JP @item 参照 \EG @item References @fref{red}. @end table \JP @node conj real imag,,, 数の演算 \EG @node conj real imag,,, Numbers @subsection @code{conj}, @code{real}, @code{imag} @findex conj @table @t @item real(@var{comp}) \JP :: @var{comp} の実数部分. \EG :: Real part of @var{comp}. @item imag(@var{comp}) \JP :: @var{comp} の虚数部分. \EG :: Imaginary part of @var{comp}. @item conj(@var{comp}) \JP :: @var{comp} の共役複素数. \EG :: Complex conjugate of @var{comp}. @end table @table @var @item return comp \JP 複素数 \EG complex number @end table @itemize @bullet \BJP @item 複素数に対し, 実部, 虚部, 共役を求める. @item これらは, 多項式に対しても働く. \E \BEG @item Basic operations for complex numbers. @item These functions works also for polynomials with complex coefficients. \E @end itemize @example [111] A=(2+@@i)^3; (2+11*@@i) [112] [real(A),imag(A),conj(A)]; [2,11,(2-11*@@i)] @end example \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 @table @var @item return \JP 数あるいは式 \EG number or expression @item obj \JP 一般の式 \EG general expression @item prec \JP 整数 \EG integer @end table @itemize @bullet \BJP @item @var{obj} に含まれる函数の値を可能な限り評価する. @item @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{setbprec setprec}.) @item @table @t @item 扱える函数は, 次の通り. @code{sin}, @code{cos}, @code{tan}, @code{asin}, @code{acos}, @code{atan}, @code{sinh}, @code{cosh}, @code{tanh}, @code{asinh}, @code{acosh}, @code{atanh}, @code{exp}, @code{log}, @code{pow(a,b) (a^b)} @end table @item 以下の記号を数として評価できる. ただし @code{@@i} を扱えるのは @code{eval}, @code{deval} のみである. @table @t @item @@i 虚数単位 @item @@pi 円周率 @item @@e 自然対数の底 @end table \E \BEG @item Evaluates the value of the functions contained in @var{obj} as far as possible. @item @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{setbprec setprec}.) @item Currently available numerical functions are listed below. @table @t @code{sin}, @code{cos}, @code{tan}, @code{asin}, @code{acos}, @code{atan}, @code{sinh}, @code{cosh}, @code{tanh}, @code{asinh}, @code{acosh}, @code{atanh}, @code{exp}, @code{log}, @code{pow(a,b) (a^b)} @end table @item 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 @item @@pi the number pi, the ratio of circumference to diameter @item @@e Napier's number (@t{exp}(1)) @end table \E @end itemize @example [118] eval(exp(@@pi*@@i)); -1.0000000000000000000000000000 [119] eval(2^(1/2)); 1.414213562373095048763788073031 [120] eval(sin(@@pi/3)); 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{setbprec setprec}. @end table \JP @node pari,,, 数の演算 \EG @node pari,,, Numbers @subsection @code{pari} @findex pari @cindex PARI @table @t @item pari(@var{func},@var{arg},@var{prec}) \JP :: @b{PARI} の函数 @var{func} を呼び出す. \EG :: Call @b{PARI} function @var{func}. @end table @table @var @item return \JP @var{func} 毎に異なる. \EG Depends on @var{func}. @item func \JP @b{PARI} の函数名 \EG Function name of @b{PARI}. @item arg \JP @var{func} の引数 \EG Arguments of @var{func}. @item prec \JP 整数 \EG integer @end table @itemize @bullet \BJP @item @b{PARI} の函数を呼び出す. @item @b{PARI} @code{[Batut et al.]} は Bordeaux 大学で開発されフ リーソフトウェアとして公開されている. @b{PARI} は数式処理的な機能を有 してはいるが, 主なターゲットは整数論に関連した数 (@b{bignum}, @b{bigfloat}) の演算で, 四則演算に限らず@b{bigfloat} によるさまざまな 函数値の評価を高速に行うことができる. @b{PARI} は他のプログラムから サブルーチンライブラリとして用いることができ, また, @samp{gp} という @b{PARI}ライブラリのインタフェースにより UNIX のアプリケーションとして 利用することもできる. @item 最後の引数 @var{prec} で計算精度を指定できる. @var{prec} を省略した場合 @code{setprec()} で指定した精度となる. @item 現時点で実行できる @b{PARI} の主な函数は次の通りである. いずれも 1 引数で @b{Asir} が対応できる型の引数をとる函数である. 実行できる函数の全リストは asir-contrib の ox_pari マニュアルを参照. なお各々の機能については @b{PARI} のマニュアルを参照のこと. \E \BEG @item This command connects @b{Asir} to @b{PARI} system so that several functions of @b{PARI} can be conveniently used from @b{Risa/Asir}. @item @b{PARI} @code{[Batut et al.]} is developed at Bordeaux University, and distributed as a free software. Though it has a certain facility to computer algebra, its major target is the operation of numbers (@b{bignum}, @b{bigfloat}) related to the number theory. It facilitates various function evaluations as well as arithmetic operations at a remarkable 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. @item The last argument (optional) @var{int} specifies the precision in digits for bigfloat operation. If the precision is not explicitly specified, operation will be performed with the precision set by @code{setprec()}. @item Some of currently available functions of @b{PARI} system are as follows. Note these are only a part of functions in @b{PARI} system. A complete list of functions which can be called from asir is in the ox_pari manual of the asir-contrib. For details of individual functions, refer to the @b{PARI} manual. (Some of them can be seen in the following example.) \E @code{abs}, @code{adj}, @code{arg}, @code{bigomega}, @code{binary}, @code{ceil}, @code{centerlift}, @code{cf}, @code{classno}, @code{classno2}, @code{conj}, @code{content}, @code{denom}, @code{det}, @code{det2}, @code{detr}, @code{dilog}, @code{disc}, @code{discf}, @code{divisors}, @code{eigen}, @code{eintg1}, @code{erfc}, @code{eta}, @code{floor}, @code{frac}, @code{galois}, @code{galoisconj}, @code{gamh}, @code{gamma}, @code{hclassno}, @code{hermite}, @code{hess}, @code{imag}, @code{image}, @code{image2}, @code{indexrank}, @code{indsort}, @code{initalg}, @code{isfund}, @code{isprime}, @code{ispsp}, @code{isqrt}, @code{issqfree}, @code{issquare}, @code{jacobi}, @code{jell}, @code{ker}, @code{keri}, @code{kerint}, @code{kerintg1}, @code{kerint2}, @code{kerr}, @code{length}, @code{lexsort}, @code{lift}, @code{lindep}, @code{lll}, @code{lllg1}, @code{lllgen}, @code{lllgram}, @code{lllgramg1}, @code{lllgramgen}, @code{lllgramint}, @code{lllgramkerim}, @iftex @break @end iftex @code{lllgramkerimgen}, @code{lllint}, @code{lllkerim}, @code{lllkerimgen}, @code{lllrat}, @code{lngamma}, @code{logagm}, @code{mat}, @code{matrixqz2}, @code{matrixqz3}, @code{matsize}, @code{modreverse}, @code{mu}, @code{nextprime}, @code{norm}, @code{norml2}, @code{numdiv}, @code{numer}, @code{omega}, @code{order}, @code{ordred}, @code{phi}, @code{pnqn}, @code{polred}, @code{polred2}, @code{primroot}, @code{psi}, @code{quadgen}, @code{quadpoly}, @code{real}, @code{recip}, @code{redcomp}, @code{redreal}, @code{regula}, @code{reorder}, @code{reverse}, @code{rhoreal}, @code{roots}, @code{rootslong}, @code{round}, @code{sigma}, @code{signat}, @code{simplify}, @code{smalldiscf}, @code{smallfact}, @code{smallpolred}, @code{smallpolred2}, @code{smith}, @code{smith2}, @code{sort}, @code{sqr}, @code{sqred}, @code{sqrt}, @code{supplement}, @code{trace}, @code{trans}, @code{trunc}, @code{type}, @code{unit}, @code{vec}, @code{wf}, @code{wf2}, @code{zeta} \BJP @item @b{Asir} で用いているのは @b{PARI} のほんの一部の機能である. \E \BEG @item @b{Asir} currently uses only a very small subset of @b{PARI}. \E @end itemize @example \JP /* 行列の固有ベクトルを求める. */ \EG /* Eigen vectors of a numerical matrix */ [0] pari(eigen,newmat(2,2,[[1,1],[1,2]])); [ -1.61803398874989484819771921990 0.61803398874989484826 ] [ 1 1 ] \JP /* 1 変数多項式の根を求める. */ \EG /* Roots of a polynomial */ [1] pari(roots,t^2-2); [ -1.41421356237309504876 1.41421356237309504876 ] @end example @table @t \JP @item 参照 \EG @item References @fref{setbprec setprec}. @end table \JP @node setbprec setprec,,, 数の演算 \EG @node setbprec setprec,,, Numbers @subsection @code{setbprec}, @code{setprec} @findex setbprec @findex setprec @table @t @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 @item return \JP 整数 \EG integer @item n \JP 整数 \EG integer @end table @itemize @bullet \BJP @item 引数がある場合, @b{bigfloat} の桁数を @var{n} 桁に設定する. 引数のあるなしにかかわらず, 以前に設定されていた値を返す. @item @b{bigfloat} の計算は @b{MPFR} ライブラリによって行われる. @item @b{bigfloat} での計算に対し有効である. @b{bigfloat} の flag を on にする方法は, @code{ctrl} を参照. @item 設定できる桁数に上限はないが, 指定した桁数に設定されるとは 限らない. 大きめの値を設定するのが安全である. \E \BEG @item 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{MPFR} library. @item This is effective for computations in @b{bigfloat}. Refer to @code{ctrl()} for turning on the `@b{bigfloat} flag.' @item There is no upper limit for precision digits. It sets the precision to some digits around the specified precision. Therefore, it is safe to specify a larger value. \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 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} @findex setmod @table @t @item setmod([@var{p}]) \JP :: 有限体を GF(@var{p}) に設定する. \EG :: Sets the ground field to GF(@var{p}). @end table @table @var @item return \JP 整数 \EG integer @item n \JP 2^27 未満の素数 \EG prime less than 2^27 @end table @itemize @bullet \BJP @item 有限体を GF(@var{p}) に設定する. 設定値を返す. @item 有限体の元の型を持つ数は, それ自身はどの有限体に属するかの情報を持たず, 現在設定されている素数 @var{p} により GF(@var{p}) 上での演算が適用される. @item 位数の大きな有限体に関しては @pxref{有限体に関する演算}. \E \BEG @item Sets the ground field to GF(@var{p}) and returns the value @var{p}. @item A member of a finite field does not have any information about the field and the arithmetic operations over GF(@var{p}) are applied with @var{p} set at the time. @item As for large finite fields, @pxref{Finite fields}. \E @end itemize @example [0] A=dp_mod(dp_ptod(2*x,[x]),3,[]); (2)*<<1>> [1] A+A; addmi : invalid modulus return to toplevel [1] setmod(3); 3 [2] A+A; (1)*<<1>> @end example @table @t \JP @item 参照 \EG @item References \JP @fref{dp_mod dp_rat}, @fref{数の型}. \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{ceil floor rint dceil dfloor drint}, @fref{isqrt}. @end table