[BACK]Return to num.texi CVS log [TXT][DIR] Up to [local] / OpenXM / src / asir-doc / parts / builtin

File: [local] / OpenXM / src / asir-doc / parts / builtin / num.texi (download)

Revision 1.15, Tue Sep 1 09:25:32 2020 UTC (3 years, 9 months ago) by noro
Branch: MAIN
CVS Tags: HEAD
Changes since 1.14: +2 -2 lines

Fixed bugs in the asir document.

@comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/num.texi,v 1.15 2020/09/01 09:25:32 noro Exp $
\BJP
@node $B?t$N1i;;(B,,, $BAH$_9~$_H!?t(B
@section $B?t$N1i;;(B
\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,,, $B?t$N1i;;(B
\EG @node idiv irem,,, Numbers
@subsection @code{idiv}, @code{irem}
@findex idiv
@findex irem

@table @t
@item idiv(@var{i1},@var{i2})
\JP :: $B@0?t=|;;$K$h$k>&(B. 
\EG :: Integer quotient of @var{i1} divided by @var{i2}.
@item irem(@var{i1},@var{i2})
\JP :: $B@0?t=|;;$K$h$k>jM>(B. 
\EG :: Integer remainder of @var{i1} divided by @var{i2}.
@end table

@table @var
@item return
\JP $B@0?t(B
\EG integer
@item i1 i2
\JP $B@0?t(B
\EG integer
@end table

@itemize @bullet
\BJP
@item
@var{i1} $B$N(B @var{i2} $B$K$h$k@0?t=|;;$K$h$k>&(B, $B>jM>$r5a$a$k(B. 
@item
@var{i2} $B$O(B 0 $B$G$"$C$F$O$J$i$J$$(B. 
@item
$BHo=|?t$,Ii$N>l9g(B, $B@dBPCM$KBP$9$kCM$K%^%$%J%9$r$D$1$?CM$rJV$9(B. 
@item
@var{i1} @code{%} @var{i2} $B$O(B, $B7k2L$,@5$K@55,2=$5$l$k$3$H$r=|$1$P(B
@code{irem()} $B$NBe$o$j$KMQ$$$k$3$H$,$G$-$k(B. 
@item
$BB?9`<0$N>l9g$O(B @code{sdiv}, @code{srem} $B$rMQ$$$k(B. 
\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 $B;2>H(B
\EG @item References
@fref{sdiv sdivm srem sremm sqr sqrm}, @fref{%}.
@end table

\JP @node fac,,, $B?t$N1i;;(B
\EG @node fac,,, Numbers
@subsection @code{fac}
@findex fac

@table @t
@item fac(@var{i})
\JP :: @var{i} $B$N3,>h(B. 
\EG :: The factorial of @var{i}.
@end table

@table @var
@item return
\JP $B@0?t(B
\EG integer
@item i
\JP $B@0?t(B
\EG integer
@end table

@itemize @bullet
\BJP
@item
@var{i} $B$N3,>h$r7W;;$9$k(B. 
@item
@var{i} $B$,Ii$N>l9g$O(B 0 $B$rJV$9(B. 
\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,,, $B?t$N1i;;(B
\EG @node igcd igcdcntl,,, Numbers
@subsection @code{igcd},@code{igcdcntl}
@findex igcd
@findex igcdcntl

@table @t
@item igcd(@var{i1},@var{i2})
\JP :: $B@0?t$N(B GCD ($B:GBg8xLs?t(B)
\EG :: The integer greatest common divisor of @var{i1} and @var{i2}.
@item igcdcntl([@var{i}])
\JP :: $B@0?t(B GCD$B$N%"%k%4%j%:%`A*Br(B
\EG :: Selects an algorithm for integer GCD.
@end table

@table @var
@item return
\JP $B@0?t(B
\EG integer
@item i1 i2 i
\JP $B@0?t(B
\EG integer
@end table

@itemize @bullet
\BJP
@item
@code{igcd} $B$O(B @var{i1} $B$H(B @var{i2} $B$N(B GCD $B$r5a$a$k(B. 
@item
$B0z?t$,@0?t$G$J$$>l9g$O(B, $B%(%i!<$^$?$OL50UL#$J7k2L$rJV$9(B. 
@item
$BB?9`<0$N>l9g$O(B, @code{gcd}, @code{gcdz} $B$rMQ$$$k(B. 
@item
$B@0?t(B GCD $B$K$O$5$^$6$^$JJ}K!$,$"$j(B, @code{igcdcntl} $B$G@_Dj$G$-$k(B. 

@table @code
@item 0
Euclid $B8_=|K!(B (default)
@item 1
binary GCD
@item 2
bmod GCD
@item 3
accelerated integer GCD
@end table
@code{2}, @code{3} $B$O(B @code{[Weber]} $B$K$h$k(B. 

$B$*$*$`$M(B @code{3} $B$,9bB.$@$,(B, $BNc30$b$"$k(B. 
\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 $B;2>H(B
\EG @item References
@fref{gcd gcdz}.
@end table

\JP @node ilcm,,, $B?t$N1i;;(B
\EG @node ilcm,,, Numbers
@subsection @code{ilcm}
@findex ilcm

@table @t
@item ilcm(@var{i1},@var{i2})
\JP :: $B:G>.8xG\?t$r5a$a$k(B. 
\EG :: The integer least common multiple of @var{i1} and @var{i2}.
@end table

@table @var
@item return
\JP $B@0?t(B
\EG integer
@item i1 i2
\JP $B@0?t(B
\EG integer
@end table

@itemize @bullet
\BJP
@item
$B@0?t(B @var{i1}, @var{i2} $B$N:G>.8xG\?t$r5a$a$k(B. 
@item
$B0lJ}$,(B 0 $B$N>l9g(B 0 $B$rJV$9(B. 
\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 $B;2>H(B
\EG @item References
@fref{igcd igcdcntl}, @fref{mt_save mt_load}.
@end table

\JP @node isqrt,,, $B?t$N1i;;(B
\EG @node isqrt,,, Numbers
@subsection @code{isqrt}
@findex isqrt

@table @t
@item isqrt(@var{n})
\JP :: $BJ?J}:,$r1[$($J$$:GBg$N@0?t$r5a$a$k(B. 
\EG :: The integer square root of @var{n}.
@end table

@table @var
@item return
\JP $BHsIi@0?t(B
\EG non-negative integer
@item n
\JP $BHsIi@0?t(B
\EG non-negative integer
@end table

\JP @node inv,,, $B?t$N1i;;(B
\EG @node inv,,, Numbers
@subsection @code{inv}
@findex inv

@table @t
@item inv(@var{i},@var{m})
\JP :: @var{m} $B$rK!$H$9$k(B @var{i} $B$N5U?t(B
\EG :: the inverse (reciprocal) of @var{i} modulo @var{m}.
@end table

@table @var
@item return
\JP $B@0?t(B
\EG integer
@item i m
\JP $B@0?t(B
\EG integer
@end table

@itemize @bullet
\BJP
@item
@var{ia} @equiv{} 1 mod (@var{m}) $B$J$k@0?t(B @var{a} $B$r5a$a$k(B. 
@item
@var{i} $B$H(B @var{m} $B$O8_$$$KAG$G$J$1$l$P$J$i$J$$$,(B, @code{inv()} $B$O(B
$B$=$N%A%'%C%/$O9T$o$J$$(B. 
\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 $B;2>H(B
\EG @item References
@fref{igcd igcdcntl}.
@end table

\JP @node prime lprime,,, $B?t$N1i;;(B
\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 :: $BAG?t$rJV$9(B
\EG :: Returns a prime number.
@end table

@table @var
@item return
\JP $B@0?t(B
\EG integer
@item index
\JP $B@0?t(B
\EG integer
@end table

@itemize @bullet
\BJP
@item
@code{prime()}, @code{lprime()} $B$$$:$l$b%7%9%F%`$,FbIt$K;}$D(B
$BAG?tI=$NMWAG$rJV$9(B. @code{index} $B$O(B 0 $B0J>e$N@0?t$G(B, $BAG?tI=(B
$B$N%$%s%G%C%/%9$KMQ$$$i$l$k(B. @code{prime()} $B$O(B 16381 $B$^$G(B
$B$NAG?t$r>.$5$$=g$K(B 1900 $B8D(B, @code{lprime()} $B$O(B, 10 $B?J(B 8 $B7e$G:GBg$N(B
$BAG?t$+$iBg$-$$=g$K(B 999 $B8DJV$9(B. $B$=$l0J30$N%$%s%G%C%/%9$KBP$7$F$O(B
0 $B$rJV$9(B. 
@item
$B$h$j0lHLE*$JAG?t@8@.H!?t$H$7$F$O(B,
@code{pari(nextprime,@var{number})}
$B$,$"$k(B. 
\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 $B;2>H(B
\EG @item References
@fref{pari}.
@end table

\JP @node random,,, $B?t$N1i;;(B
\EG @node random,,, Numbers
@subsection @code{random}
@findex random

@table @t
@item random([@var{seed}])
\JP :: $BMp?t$r@8@.$9$k(B. 
@end table

@table @var
@item seed
@itemx return
\JP $B<+A3?t(B
\EG non-negative integer
@end table

@itemize @bullet
\BJP
@item
$B:GBg(B 2^32-1 $B$NHsIi@0?t$NMp?t$r@8@.$9$k(B. 
@item
0 $B$G$J$$0z?t$,$"$k;~(B, $B$=$NCM$r(B seed $B$H$7$F@_Dj$7$F$+$i(B, $BMp?t$r@8@.$9$k(B. 
@item
default $B$N(B seed $B$O8GDj$N$?$a(B, $B<o$r@_Dj$7$J$1$l$P(B, $B@8@.$5$l$kMp?t$N(B
$B7ONs$O5/F0Kh$K0lDj$G$"$k(B. 
@item
$B>>K\bC(B-$B@>B<Bs;N$K$h$k(B Mersenne Twister (http://www.math.keio.ac.jp/matsumoto/mt.html) $B%"%k%4%j%:%`$N(B, $BH`$i<+?H$K$h$k<BAu$rMQ$$$F$$$k(B. 
@item
$B<~4|$O(B 2^19937-1 $B$HHs>o$KD9$$(B. 
@item
@code{mt_save} $B$K$h$j(B state $B$r%U%!%$%k$K(B save $B$G$-$k(B. $B$3$l$r(B @code{mt_load}
$B$GFI$_9~$`$3$H$K$h$j(B, $B0[$k(B Asir $B%;%C%7%g%s4V$G0l$D$NMp?t$N7ONs$rC)$k$3$H$,(B
$B$G$-$k(B. 
\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 $B;2>H(B
\EG @item References
@fref{lrandom}, @fref{mt_save mt_load}.
@end table

\JP @node lrandom,,, $B?t$N1i;;(B
\EG @node lrandom,,, Numbers
@subsection @code{lrandom}
@findex lrandom

@table @t
@item lrandom(@var{bit})
\JP :: $BB?G\D9Mp?t$r@8@.$9$k(B. 
\EG :: Generates a long random number.
@end table

@table @var
@item bit
@item return
\JP $B<+A3?t(B
\EG integer
@end table

@itemize @bullet
\BJP
@item
$B9b!9(B @var{bit} $B$NHsIi@0?t$NMp?t$r@8@.$9$k(B. 
@item
@code{random} $B$rJ#?t2s8F$S=P$7$F7k9g$7(B, $B;XDj$N(B bit $BD9$K%^%9%/$7$F$$$k(B. 
\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 $B;2>H(B
\EG @item References
@fref{random}, @fref{mt_save mt_load}.
@end table

\JP @node mt_save mt_load,,, $B?t$N1i;;(B
\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 :: $BMp?t@8@.4o$N8=:_$N>uBV$r%U%!%$%k$K%;!<%V$9$k(B. 
\EG :: Saves the state of the random number generator.
@item mt_load(@var{fname})
\JP :: $B%U%!%$%k$K%;!<%V$5$l$?Mp?t@8@.4o$N>uBV$r%m!<%I$9$k(B. 
\EG :: Loads a saved state of the random number generator.
@end table

@table @var
@item return
\JP 0 $B$^$?$O(B 1
\EG 0 or 1
@item fname
\JP $BJ8;zNs(B
\EG string
@end table

@itemize @bullet
\BJP
@item
$B$"$k>uBV$r%;!<%V$7(B, $B$=$N>uBV$r%m!<%I$9$k$3$H$G(B, 
$B0l$D$N5?;wMp?t7ONs$r(B, $B?75,$N(B Asir $B%;%C%7%g%s$GB3$1$F$?$I$k$3$H$,(B
$B$G$-$k(B. 
\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 $B;2>H(B
\EG @item References
@fref{random}, @fref{lrandom}.
@end table

\JP @node nm dn,,, $B?t$N1i;;(B
\EG @node nm dn,,, Numbers
@subsection @code{nm}, @code{dn}
@findex nm
@findex dn

@table @t
@item nm(@var{rat})
\JP :: @var{rat} $B$NJ,;R(B. 
\EG :: Numerator of @var{rat}.
@item dn(@var{rat})
\JP :: @var{rat} $B$NJ,Jl(B. 
\EG :: Denominator of @var{rat}.
@end table

@table @var
@item return
\JP $B@0?t$^$?$OB?9`<0(B
\EG integer or polynomial
@item rat
\JP $BM-M}?t$^$?$OM-M}<0(B
\EG rational number or rational expression
@end table

@itemize @bullet
\BJP
@item
$BM?$($i$l$?M-M}?t$^$?M-M}<0$NJ,;R5Z$SJ,Jl$rJV$9(B. 
@item
$BM-M}?t$N>l9g(B, $BJ,Jl$O>o$K@5$G(B, $BId9f$OJ,;R$,;}$D(B. 
@item
$BM-M}<0$N>l9g(B, $BC1$KJ,Jl(B, $BJ,;R$r<h$j=P$9$@$1$G$"$k(B. 
$BM-M}<0$KBP$7$F$O(B, $BLsJ,$O<+F0E*$K$O9T$o$l$J$$(B. @code{red()}
$B$rL@<(E*$K8F$S=P$9I,MW$,$"$k(B. 
\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 $B;2>H(B
\EG @item References
@fref{red}.
@end table

\JP @node conj real imag,,, $B?t$N1i;;(B
\EG @node conj real imag,,, Numbers
@subsection @code{conj}, @code{real}, @code{imag}
@findex conj

@table @t
@item real(@var{comp})
\JP :: @var{comp} $B$N<B?tItJ,(B. 
\EG :: Real part of @var{comp}.
@item imag(@var{comp})
\JP :: @var{comp} $B$N5u?tItJ,(B. 
\EG :: Imaginary part of @var{comp}.
@item conj(@var{comp})
\JP :: @var{comp} $B$N6&LrJ#AG?t(B. 
\EG :: Complex conjugate of @var{comp}.
@end table

@table @var
@item return comp
\JP $BJ#AG?t(B
\EG complex number
@end table

@itemize @bullet
\BJP
@item
$BJ#AG?t$KBP$7(B, $B<BIt(B, $B5uIt(B, $B6&Lr$r5a$a$k(B. 
@item
$B$3$l$i$O(B, $BB?9`<0$KBP$7$F$bF/$/(B. 
\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 ,,, $B?t$N1i;;(B
\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} $B$NCM$NI>2A(B. 
\EG :: Evaluate @var{obj} numerically.
@end table

@table @var
@item return
\JP $B?t$"$k$$$O<0(B
\EG number or expression
@item obj
\JP $B0lHL$N<0(B
\EG general expression
@item prec
\JP $B@0?t(B
\EG integer
@end table

@itemize @bullet
\BJP
@item
@var{obj} $B$K4^$^$l$kH!?t$NCM$r2DG=$J8B$jI>2A$9$k(B. 
@item
@code{deval} $B$OG\@:EYIbF0>.?t$r7k2L$H$7$F(B 
@code{eval} $B$N>l9g(B, $BM-M}?t$O$=$N$^$^;D$k(B. 
@item
@code{eval} $B$K$*$$$F$O(B, $B7W;;$O(B @b{MPFR} $B%i%$%V%i%j$,9T$&(B. 
@code{deval} $B$K$*$$$F$O(B, $B7W;;$O(B C $B?t3X%i%$%V%i%j$N4X?t$rMQ$$$F9T$&(B. 
@item
@code{deval} $B$OJ#AG?t$O07$($J$$(B. 
@item
@code{eval} $B$K$*$$$F$O(B, 
@var{prec} $B$r;XDj$7$?>l9g(B, $B7W;;$O(B, 10 $B?J(B @var{prec} $B7eDxEY$G9T$o$l$k(B. 
@var{prec} $B$N;XDj$,$J$$>l9g(B, $B8=:_@_Dj$5$l$F$$$k@:EY$G9T$o$l$k(B. 
(@xref{setbprec setprec}.)
@item
@table @t
@item $B07$($kH!?t$O(B, $B<!$NDL$j(B. 
@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
$B0J2<$N5-9f$r?t$H$7$FI>2A$G$-$k(B. $B$?$@$7(B @code{@@i} $B$r07$($k$N$O(B
@code{eval}, @code{deval} $B$N$_$G$"$k(B.
@table @t
@item @@i
$B5u?tC10L(B
@item @@pi
$B1_<~N((B
@item @@e
$B<+A3BP?t$NDl(B
@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 $B;2>H(B
\EG @item References
@fref{ctrl}, @fref{setbprec setprec}.
@end table

\JP @node pari,,, $B?t$N1i;;(B
\EG @node pari,,, Numbers
@subsection @code{pari}
@findex pari
@cindex PARI

@table @t
@item pari(@var{func},@var{arg},@var{prec}) 
\JP :: @b{PARI} $B$NH!?t(B @var{func} $B$r8F$S=P$9(B. 
\EG :: Call @b{PARI} function @var{func}.
@end table

@table @var
@item return
\JP @var{func} $BKh$K0[$J$k(B. 
\EG Depends on @var{func}.
@item func
\JP @b{PARI} $B$NH!?tL>(B
\EG Function name of @b{PARI}.
@item arg
\JP @var{func} $B$N0z?t(B
\EG Arguments of @var{func}.
@item prec
\JP $B@0?t(B
\EG integer
@end table

@itemize @bullet
\BJP
@item
@b{PARI} $B$NH!?t$r8F$S=P$9(B. 

@item
@b{PARI} @code{[Batut et al.]} $B$O(B Bordeaux $BBg3X$G3+H/$5$l%U(B
$B%j!<%=%U%H%&%'%"$H$7$F8x3+$5$l$F$$$k(B. @b{PARI} $B$O?t<0=hM}E*$J5!G=$rM-(B
$B$7$F$O$$$k$,(B, $B<g$J%?!<%2%C%H$O@0?tO@$K4XO"$7$??t(B (@b{bignum},
@b{bigfloat}) $B$N1i;;$G(B, $B;MB'1i;;$K8B$i$:(B@b{bigfloat} $B$K$h$k$5$^$6$^$J(B
$BH!?tCM$NI>2A$r9bB.$K9T$&$3$H$,$G$-$k(B. @b{PARI} $B$OB>$N%W%m%0%i%`$+$i(B
$B%5%V%k!<%A%s%i%$%V%i%j$H$7$FMQ$$$k$3$H$,$G$-(B, $B$^$?(B, @samp{gp} $B$H$$$&(B 
@b{PARI}$B%i%$%V%i%j$N%$%s%?%U%'!<%9$K$h$j(B UNIX $B$N%"%W%j%1!<%7%g%s$H$7$F(B
$BMxMQ$9$k$3$H$b$G$-$k(B. 
@item
$B:G8e$N0z?t(B @var{prec} $B$G7W;;@:EY$r;XDj$G$-$k(B.
@var{prec} $B$r>JN,$7$?>l9g(B @code{setprec()} $B$G;XDj$7$?@:EY$H$J$k(B. 
@item
$B8=;~E@$G<B9T$G$-$k(B @b{PARI} $B$N<g$JH!?t$O<!$NDL$j$G$"$k(B. $B$$$:$l$b(B
1 $B0z?t$G(B @b{Asir} $B$,BP1~$G$-$k7?$N0z?t$r$H$kH!?t$G$"$k(B. 
$B<B9T$G$-$kH!?t$NA4%j%9%H$O(B asir-contrib $B$N(B ox_pari $B%^%K%e%"%k$r;2>H(B.
$B$J$*3F!9$N5!G=$K$D$$$F$O(B @b{PARI} $B$N%^%K%e%"%k$r;2>H$N$3$H(B.
\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$GMQ$$$F$$$k$N$O(B @b{PARI} $B$N$[$s$N0lIt$N5!G=$G$"$k(B.
\E
\BEG
@item
@b{Asir} currently uses only a very small subset of @b{PARI}.
\E
@end itemize

@example
\JP /* $B9TNs$N8GM-%Y%/%H%k$r5a$a$k(B. */
\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 $BJQ?tB?9`<0$N:,$r5a$a$k(B. */
\EG /* Roots of a polynomial */
[1] pari(roots,t^2-2);
[ -1.41421356237309504876 1.41421356237309504876 ]
@end example

@table @t
\JP @item $B;2>H(B
\EG @item References
@fref{setbprec setprec}.
@end table

\JP @node setbprec setprec,,, $B?t$N1i;;(B
\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$O(B @b{bigfloat} $B$N@:EY$r$=$l$>$l(B 2 $B?J(B, 10$B?J(B @var{n} $B7e$K@_Dj$9$k(B.
\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 $B@0?t(B
\EG integer
@item n
\JP $B@0?t(B
\EG integer
@end table

@itemize @bullet
\BJP
@item
$B0z?t$,$"$k>l9g(B, @b{bigfloat} $B$N7e?t$r(B @var{n} $B7e$K@_Dj$9$k(B. 
$B0z?t$N$"$k$J$7$K$+$+$o$i$:(B, $B0JA0$K@_Dj$5$l$F$$$?CM$rJV$9(B. 
@item
@b{bigfloat} $B$N7W;;$O(B @b{MPFR} $B%i%$%V%i%j$K$h$C$F9T$o$l$k(B. 
@item
@b{bigfloat} $B$G$N7W;;$KBP$7M-8z$G$"$k(B. 
@b{bigfloat} $B$N(B flag $B$r(B on $B$K$9$kJ}K!$O(B, @code{ctrl} $B$r;2>H(B. 
@item
$B@_Dj$G$-$k7e?t$K>e8B$O$J$$$,(B, $B;XDj$7$?7e?t$K@_Dj$5$l$k$H$O(B
$B8B$i$J$$(B. $BBg$-$a$NCM$r@_Dj$9$k$N$,0BA4$G$"$k(B. 
\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 $B;2>H(B
@fref{ctrl}, @fref{eval deval}.
@end table

\JP @node setround,,, $B?t$N1i;;(B
\EG @node setround,,, Numbers
@subsection @code{setround}
@findex setround

@table @t
@item setround([@var{mode}])
\JP :: @b{bigfloat} $B$N4]$a%b!<%I$r(B @var{mode} $B$K@_Dj$9$k(B.
\EG :: Sets the rounding mode @var{mode}.
@end table

@table @var
@item return
\JP $B@0?t(B
\EG integer
@item mode
\JP $B@0?t(B
\EG integer
@end table

@itemize @bullet
\BJP
@item
$B0z?t$,$"$k>l9g(B, @b{bigfloat} $B$N4]$a%b!<%I$r(B @var{mode} $B$K@_Dj$9$k(B. 
$B0z?t$N$"$k$J$7$K$+$+$o$i$:(B, $B0JA0$K@_Dj$5$l$F$$$?CM$rJV$9(B. 
$B4]$a%b!<%I$N0UL#$O<!$N$H$*$j(B.
@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$G$N7W;;$KBP$7M-8z$G$"$k(B. 
@b{bigfloat} $B$N(B flag $B$r(B on $B$K$9$kJ}K!$O(B, @code{ctrl} $B$r;2>H(B. 
\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 $B;2>H(B
@fref{ctrl}, @fref{eval deval}.
@end table


\JP @node setmod,,, $B?t$N1i;;(B
\EG @node setmod,,, Numbers
@subsection @code{setmod}
@findex setmod

@table @t
@item setmod([@var{p}])
\JP :: $BM-8BBN$r(B GF(@var{p}) $B$K@_Dj$9$k(B. 
\EG :: Sets the ground field to GF(@var{p}).
@end table

@table @var
@item return
\JP $B@0?t(B
\EG integer
@item n
\JP 2^27 $BL$K~$NAG?t(B
\EG prime less than 2^27
@end table

@itemize @bullet
\BJP
@item
$BM-8BBN$r(B GF(@var{p}) $B$K@_Dj$9$k(B. $B@_DjCM$rJV$9(B. 
@item
$BM-8BBN$N85$N7?$r;}$D?t$O(B, $B$=$l<+?H$O$I$NM-8BBN$KB0$9$k$+$N>pJs$r;}$?$:(B, 
$B8=:_@_Dj$5$l$F$$$kAG?t(B @var{p} $B$K$h$j(B GF(@var{p}) $B>e$G$N1i;;$,E,MQ$5$l$k(B. 
@item
$B0L?t$NBg$-$JM-8BBN$K4X$7$F$O(B @pxref{$BM-8BBN$K4X$9$k1i;;(B}.
\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 $B;2>H(B
\EG @item References
\JP @fref{dp_mod dp_rat}, @fref{$B?t$N7?(B}.
\EG @fref{dp_mod dp_rat}, @fref{Types of numbers}.
@end table

\JP @node ntoint32 int32ton,,, $B?t$N1i;;(B
\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 :: $BHsIi@0?t$HId9f$J$7(B 32bit $B@0?t$N4V$N7?JQ49(B. 
\EG :: Type-conversion between a non-negative integer and an unsigned 32bit integer.
@end table

@table @var
@item return
\JP $BId9f$J$7(B 32bit $B@0?t$^$?$OHsIi@0?t(B
\EG unsigned 32bit integer or non-negative integer
@item n
\JP 2^32 $BL$K~$NHsIi@0?t(B
\EG non-negative interger less than 2^32
@item int32
\JP $BId9f$J$7(B 32bit $B@0?t(B
\EG unsigned 32bit integer
@end table

@itemize @bullet
\BJP
@item $BHsIi@0?t(B ($B<1JL;R(B 1) $B$NId9f$J$7(B 32bit $B@0?t(B ($B<1JL;R(B 10) $B$X$NJQ49(B, 
$B$^$?$O$=$N5UJQ49$r9T$&(B. 
@item 32bit $B@0?t$O(B @b{OpenXM} $B$N4pK\9=@.MWAG$G$"$j(B, $B@0?t$r$=$N7?$GAw?.(B
$B$9$kI,MW$,$"$k>l9g$KMQ$$$k(B. 
\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 $B;2>H(B
\EG @item References
\JP @fref{$BJ,;67W;;(B}, @fref{$B?t$N7?(B}.
\EG @fref{Distributed computation}, @fref{Types of numbers}.
@end table

\JP @node inttorat,,, $B?t$N1i;;(B
\EG @node inttorat,,, Numbers
@subsection @code{inttorat}
@findex inttorat

@table @t
@item inttorat(@var{a},@var{m},@var{b})
\JP :: $B@0?t(B-$BM-M}?tJQ49$r9T$&(B.
\EG :: Perform the rational reconstruction.
@end table

@table @var
@item return
\JP $B%j%9%H$^$?$O(B 0
\EG list or 0
@item a
@itemx m
@itemx b
\JP $B@0?t(B
\EG integer
@end table

@itemize @bullet
\BJP
@item
$B@0?t(B @var{a} $B$KBP$7(B, @var{xa=y} mod @var{m} $B$rK~$?$9@5@0?t(B @var{x}, $B@0?t(B @var{y}
(@var{x}, @var{|y|} < @var{b}, @var{GCD(x,y)=1}) $B$r5a$a$k(B.
@item
$B$3$N$h$&$J(B @var{x}, @var{y} $B$,B8:_$9$k$J$i(B @var{[y,x]} $B$rJV$7(B, $BB8:_$7$J$$>l9g$K$O(B 0 $B$rJV$9(B.
@item
@var{b} $B$r(B @var{floor(sqrt(m/2))} $B$H<h$l$P(B, @var{x}, @var{y} $B$OB8:_$9$l$P0l0U$G$"$k(B.
@var{floor(sqrt(m/2))} $B$O(B @code{isqrt(floor(m/2))} $B$G7W;;$G$-$k(B.
@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 $B;2>H(B
\EG @item References
@fref{ceil floor rint dceil dfloor drint}, @fref{isqrt}.
@end table