Annotation of OpenXM/src/asir-doc/parts/builtin/num.texi, Revision 1.2
1.2 ! noro 1: @comment $OpenXM$
! 2: \BJP
1.1 noro 3: @node $B?t$N1i;;(B,,, $BAH$_9~$_H!?t(B
4: @section $B?t$N1i;;(B
1.2 ! noro 5: \E
! 6: \BEG
! 7: @node Numbers,,, Built-in Function
! 8: @section Numbers
! 9: \E
1.1 noro 10:
11: @menu
12: * idiv irem::
13: * fac::
14: * igcd igcdcntl::
15: * ilcm::
16: * inv::
17: * prime lprime::
18: * random::
19: * mt_save mt_load::
20: * nm dn::
21: * conj real imag::
22: * eval::
23: * pari::
24: * setprec::
25: * setmod::
26: * lrandom::
27: @end menu
28:
1.2 ! noro 29: \JP @node idiv irem,,, $B?t$N1i;;(B
! 30: \EG @node idiv irem,,, Numbers
1.1 noro 31: @subsection @code{idiv}, @code{irem}
32: @findex idiv
33: @findex irem
34:
35: @table @t
36: @item idiv(@var{i1},@var{i2})
1.2 ! noro 37: \JP :: $B@0?t=|;;$K$h$k>&(B.
! 38: \EG :: Integer quotient of @var{i1} divided by @var{i2}.
1.1 noro 39: @item irem(@var{i1},@var{i2})
1.2 ! noro 40: \JP :: $B@0?t=|;;$K$h$k>jM>(B.
! 41: \EG :: Integer remainder of @var{i1} divided by @var{i2}.
1.1 noro 42: @end table
43:
44: @table @var
45: @item return
1.2 ! noro 46: \JP $B@0?t(B
! 47: \EG integer
1.1 noro 48: @item i1,i2
1.2 ! noro 49: \JP $B@0?t(B
! 50: \EG integer
1.1 noro 51: @end table
52:
53: @itemize @bullet
1.2 ! noro 54: \BJP
1.1 noro 55: @item
56: @var{i1} $B$N(B @var{i2} $B$K$h$k@0?t=|;;$K$h$k>&(B, $B>jM>$r5a$a$k(B.
57: @item
58: @var{i2} $B$O(B 0 $B$G$"$C$F$O$J$i$J$$(B.
59: @item
60: $BHo=|?t$,Ii$N>l9g(B, $B@dBPCM$KBP$9$kCM$K%^%$%J%9$r$D$1$?CM$rJV$9(B.
61: @item
62: @var{i1} @code{%} @var{i2} $B$O(B, $B7k2L$,@5$K@55,2=$5$l$k$3$H$r=|$1$P(B
63: @code{irem()} $B$NBe$o$j$KMQ$$$k$3$H$,$G$-$k(B.
64: @item
65: $BB?9`<0$N>l9g$O(B @code{sdiv}, @code{srem} $B$rMQ$$$k(B.
1.2 ! noro 66: \E
! 67: \BEG
! 68: @item
! 69: Integer quotient and remainder of @var{i1} divided by @var{i2}.
! 70: @item
! 71: @var{i2} must not be 0.
! 72: @item
! 73: If the dividend is negative, the results are obtained by changing the
! 74: sign of the results for absolute values of the dividend.
! 75: @item
! 76: One can use
! 77: @var{i1} @code{%} @var{i2}
! 78: for replacement of @code{irem()} which only differs in the point that
! 79: the result is always normalized to non-negative values.
! 80: @item
! 81: Use @code{sdiv()}, @code{srem()} for polynomial quotient.
! 82: \E
1.1 noro 83: @end itemize
84:
85: @example
86: [0] idiv(100,7);
87: 14
88: [0] idiv(-100,7);
89: -14
90: [1] irem(100,7);
91: 2
92: [1] irem(-100,7);
93: -2
94: @end example
95:
96: @table @t
1.2 ! noro 97: \JP @item $B;2>H(B
! 98: \EG @item References
1.1 noro 99: @fref{sdiv sdivm srem sremm sqr sqrm}, @fref{%}.
100: @end table
101:
1.2 ! noro 102: \JP @node fac,,, $B?t$N1i;;(B
! 103: \EG @node fac,,, Numbers
1.1 noro 104: @subsection @code{fac}
105: @findex fac
106:
107: @table @t
108: @item fac(@var{i})
1.2 ! noro 109: \JP :: @var{i} $B$N3,>h(B.
! 110: \EG :: The factorial of @var{i}.
1.1 noro 111: @end table
112:
113: @table @var
114: @item return
1.2 ! noro 115: \JP $B@0?t(B
! 116: \EG integer
1.1 noro 117: @item i
1.2 ! noro 118: \JP $B@0?t(B
! 119: \EG integer
1.1 noro 120: @end table
121:
122: @itemize @bullet
1.2 ! noro 123: \BJP
1.1 noro 124: @item
125: @var{i} $B$N3,>h$r7W;;$9$k(B.
126: @item
127: @var{i} $B$,Ii$N>l9g$O(B 0 $B$rJV$9(B.
1.2 ! noro 128: \E
! 129: \BEG
! 130: @item
! 131: The factorial of @var{i}.
! 132: @item
! 133: Returns 0 if the argument @var{i} is negative.
! 134: \E
1.1 noro 135: @end itemize
136:
137: @example
138: [0] fac(50);
139: 30414093201713378043612608166064768844377641568960512000000000000
140: @end example
141:
1.2 ! noro 142: \JP @node igcd igcdcntl,,, $B?t$N1i;;(B
! 143: \EG @node igcd igcdcntl,,, Numbers
1.1 noro 144: @subsection @code{igcd},@code{igcdcntl}
145: @findex igcd
146: @findex igcdcntl
147:
148: @table @t
149: @item igcd(@var{i1},@var{i2})
1.2 ! noro 150: \JP :: $B@0?t$N(B GCD ($B:GBg8xLs?t(B)
! 151: \EG :: The integer greatest common divisor of @var{i1} and @var{i2}.
1.1 noro 152: @item igcdcntl([@var{i}])
1.2 ! noro 153: \JP :: $B@0?t(B GCD$B$N%"%k%4%j%:%`A*Br(B
! 154: \EG :: Selects an algorithm for integer GCD.
1.1 noro 155: @end table
156:
157: @table @var
158: @item return
1.2 ! noro 159: \JP $B@0?t(B
! 160: \EG integer
1.1 noro 161: @item i1,i2,i
1.2 ! noro 162: \JP $B@0?t(B
! 163: \EG integer
1.1 noro 164: @end table
165:
166: @itemize @bullet
1.2 ! noro 167: \BJP
1.1 noro 168: @item
169: @code{igcd} $B$O(B @var{i1} $B$H(B @var{i2} $B$N(B GCD $B$r5a$a$k(B.
170: @item
171: $B0z?t$,@0?t$G$J$$>l9g$O(B, $B%(%i!<$^$?$OL50UL#$J7k2L$rJV$9(B.
172: @item
173: $BB?9`<0$N>l9g$O(B, @code{gcd}, @code{gcdz} $B$rMQ$$$k(B.
174: @item
175: $B@0?t(B GCD $B$K$O$5$^$6$^$JJ}K!$,$"$j(B, @code{igcdcntl} $B$G@_Dj$G$-$k(B.
176:
177: @table @code
178: @item 0
179: Euclid $B8_=|K!(B (default)
180: @item 1
181: binary GCD
182: @item 2
183: bmod GCD
184: @item 3
185: accelerated integer GCD
186: @end table
1.2 ! noro 187: @code{2}, @code{3} $B$O(B @code{[Weber]} $B$K$h$k(B.
1.1 noro 188:
1.2 ! noro 189: $B$*$*$`$M(B @code{3} $B$,9bB.$@$,(B, $BNc30$b$"$k(B.
! 190: \E
! 191: \BEG
! 192: @item
! 193: Function @code{igcd()} returns the integer greatest common divisor of
! 194: the given two integers.
! 195: @item
! 196: An error will result if the argument is not an integer; the result is
! 197: not valid even if one is returned.
! 198: @item
! 199: Use @code{gcd()}, @code{gcdz()} for polynomial GCD.
! 200:
! 201: @item
! 202: Various method of integer GCD computation are implemented
! 203: and they can be selected by @code{igcdcntl}.
! 204:
! 205: @table @code
! 206: @item 0
! 207: Euclid algorithm (default)
! 208: @item 1
! 209: binary GCD
! 210: @item 2
! 211: bmod GCD
! 212: @item 3
! 213: accelerated integer GCD
! 214: @end table
! 215: @code{2}, @code{3} are due to @code{[Weber]}.
! 216:
! 217: In most cases @code{3} is the fastest, but there are exceptions.
! 218: \E
1.1 noro 219: @end itemize
220:
221: @example
222: [0] A=lrandom(10^4)$
223: [1] B=lrandom(10^4)$
224: [2] C=lrandom(10^4)$
225: [3] D=A*C$
226: [4] E=A*B$
227: [5] cputime(1)$
228: [6] igcd(D,E)$
229: 0.6sec + gc : 1.93sec(2.531sec)
230: [7] igcdcntl(1)$
231: [8] igcd(D,E)$
232: 0.27sec(0.2635sec)
233: [9] igcdcntl(2)$
234: [10] igcd(D,E)$
235: 0.19sec(0.1928sec)
236: [11] igcdcntl(3)$
237: [12] igcd(D,E)$
238: 0.08sec(0.08023sec)
239: @end example
240:
241: @table @t
1.2 ! noro 242: \JP @item $B;2>H(B
! 243: \EG @item References
1.1 noro 244: @fref{gcd gcdz}.
245: @end table
246:
1.2 ! noro 247: \JP @node ilcm,,, $B?t$N1i;;(B
! 248: \EG @node ilcm,,, Numbers
1.1 noro 249: @subsection @code{ilcm}
250: @findex ilcm
251:
252: @table @t
253: @item ilcm(@var{i1},@var{i2})
1.2 ! noro 254: \JP :: $B:G>.8xG\?t$r5a$a$k(B.
! 255: \EG :: The integer least common multiple of @var{i1} and @var{i2}.
1.1 noro 256: @end table
257:
258: @table @var
259: @item return
1.2 ! noro 260: \JP $B@0?t(B
! 261: \EG integer
1.1 noro 262: @item i1,i2
1.2 ! noro 263: \JP $B@0?t(B
! 264: \EG integer
1.1 noro 265: @end table
266:
267: @itemize @bullet
1.2 ! noro 268: \BJP
1.1 noro 269: @item
270: $B@0?t(B @var{i1}, @var{i2} $B$N:G>.8xG\?t$r5a$a$k(B.
271: @item
272: $B0lJ}$,(B 0 $B$N>l9g(B 0 $B$rJV$9(B.
1.2 ! noro 273: \E
! 274: \BEG
1.1 noro 275: @item
1.2 ! noro 276: This function computes the integer least common multiple of
! 277: @var{i1}, @var{i2}.
! 278: @item
! 279: If one of argument is equal to 0, the return 0.
! 280: \E
1.1 noro 281: @end itemize
282:
283: @table @t
1.2 ! noro 284: \JP @item $B;2>H(B
! 285: \EG @item References
1.1 noro 286: @fref{igcd igcdcntl}, @fref{mt_save mt_load}.
287: @end table
1.2 ! noro 288:
! 289: \JP @node inv,,, $B?t$N1i;;(B
! 290: \EG @node inv,,, Numbers
1.1 noro 291: @subsection @code{inv}
292: @findex inv
293:
294: @table @t
295: @item inv(@var{i},@var{m})
1.2 ! noro 296: \JP :: @var{m} $B$rK!$H$9$k(B @var{i} $B$N5U?t(B
! 297: \EG :: the inverse (reciprocal) of @var{i} modulo @var{m}.
1.1 noro 298: @end table
299:
300: @table @var
301: @item return
1.2 ! noro 302: \JP $B@0?t(B
! 303: \EG integer
1.1 noro 304: @item i,m
1.2 ! noro 305: \JP $B@0?t(B
! 306: \EG integer
1.1 noro 307: @end table
308:
309: @itemize @bullet
1.2 ! noro 310: \BJP
1.1 noro 311: @item
312: @var{ia} @equiv{} 1 mod (@var{m}) $B$J$k@0?t(B @var{a} $B$r5a$a$k(B.
313: @item
314: @var{i} $B$H(B @var{m} $B$O8_$$$KAG$G$J$1$l$P$J$i$J$$$,(B, @code{inv()} $B$O(B
315: $B$=$N%A%'%C%/$O9T$o$J$$(B.
1.2 ! noro 316: \E
! 317: \BEG
! 318: @item
! 319: This function computes an integer such that
! 320: @var{ia} @equiv{} 1 mod (@var{m}).
! 321: @item
! 322: The integer @var{i} and @var{m} must be mutually prime.
! 323: However, @code{inv()} does not check it.
! 324: \E
1.1 noro 325: @end itemize
326:
327: @example
328: [71] igcd(1234,4321);
329: 1
330: [72] inv(1234,4321);
331: 3239
332: [73] irem(3239*1234,4321);
333: 1
334: @end example
335:
336: @table @t
1.2 ! noro 337: \JP @item $B;2>H(B
! 338: \EG @item References
1.1 noro 339: @fref{igcd igcdcntl}.
340: @end table
341:
1.2 ! noro 342: \JP @node prime lprime,,, $B?t$N1i;;(B
! 343: \EG @node prime lprime,,, Numbers
1.1 noro 344: @subsection @code{prime}, @code{lprime}
345: @findex prime
346: @findex lprime
347:
348: @table @t
349: @item prime(@var{index})
350: @item lprime(@var{index})
1.2 ! noro 351: \JP :: $BAG?t$rJV$9(B
! 352: \EG :: Returns a prime number.
1.1 noro 353: @end table
354:
355: @table @var
356: @item return
1.2 ! noro 357: \JP $B@0?t(B
! 358: \EG integer
1.1 noro 359: @item index
1.2 ! noro 360: \JP $B@0?t(B
! 361: \EG integer
1.1 noro 362: @end table
363:
364: @itemize @bullet
1.2 ! noro 365: \BJP
1.1 noro 366: @item
367: @code{prime()}, @code{lprime()} $B$$$:$l$b%7%9%F%`$,FbIt$K;}$D(B
368: $BAG?tI=$NMWAG$rJV$9(B. @code{index} $B$O(B 0 $B0J>e$N@0?t$G(B, $BAG?tI=(B
369: $B$N%$%s%G%C%/%9$KMQ$$$i$l$k(B. @code{prime()} $B$O(B 16381 $B$^$G(B
370: $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
371: $BAG?t$+$iBg$-$$=g$K(B 999 $B8DJV$9(B. $B$=$l0J30$N%$%s%G%C%/%9$KBP$7$F$O(B
372: 0 $B$rJV$9(B.
373: @item
1.2 ! noro 374: $B$h$j0lHLE*$JAG?t@8@.H!?t$H$7$F$O(B,
! 375: @code{pari(nextprime,@var{number})}
1.1 noro 376: $B$,$"$k(B.
1.2 ! noro 377: \E
! 378: \BEG
! 379: @item
! 380: The two functions, @code{prime()} and @code{lprime()}, returns
! 381: an element stored in the system table of prime numbers.
! 382: Here, @code{index} is a non-negative integer and be used as an index
! 383: for the prime tables.
! 384: The function @code{prime()} can return one of 1900 primes
! 385: up to 16381 indexed so that the smaller one has smaller
! 386: index. The function @code{lprime()} can return one of 999 primes which
! 387: are 8 digit sized and indexed so that the larger one has the smaller
! 388: index.
! 389: The two function always returns 0 for other indices.
! 390: @item
! 391: For more general function for prime generation, there is a @code{PARI}
! 392: function
! 393:
! 394: @code{pari(nextprime,@var{number})}.
! 395: \E
1.1 noro 396: @end itemize
397:
398: @example
399: [95] prime(0);
400: 2
401: [96] prime(1228);
402: 9973
403: [97] lprime(0);
404: 99999989
405: [98] lprime(999);
406: 0
407: @end example
408:
409: @table @t
1.2 ! noro 410: \JP @item $B;2>H(B
! 411: \EG @item References
1.1 noro 412: @fref{pari}.
413: @end table
414:
1.2 ! noro 415: \JP @node random,,, $B?t$N1i;;(B
! 416: \EG @node random,,, Numbers
1.1 noro 417: @subsection @code{random}
418: @findex random
419:
420: @table @t
421: @item radom([@var{seed}])
1.2 ! noro 422: \JP :: $BMp?t$r@8@.$9$k(B.
1.1 noro 423: @end table
424:
425: @table @var
426: @item seed
1.2 ! noro 427: @itemx return
! 428: \JP $B<+A3?t(B
! 429: \EG non-negative integer
1.1 noro 430: @end table
431:
432: @itemize @bullet
1.2 ! noro 433: \BJP
1.1 noro 434: @item
435: $B:GBg(B 2^32-1 $B$NHsIi@0?t$NMp?t$r@8@.$9$k(B.
436: @item
437: 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.
438: @item
439: 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
440: $B7ONs$O5/F0Kh$K0lDj$G$"$k(B.
441: @item
442: $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.
443: @item
444: $B<~4|$O(B 2^19937-1 $B$HHs>o$KD9$$(B.
445: @item
446: @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}
447: $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
448: $B$G$-$k(B.
1.2 ! noro 449: \E
! 450: \BEG
! 451: @item
! 452: Generates a random number which is a non-negative integer less than 2^32.
! 453: @item
! 454: If a non zero argument is specified, then after setting it as a random seed,
! 455: a random number is generated.
! 456: @item
! 457: As the default seed is fixed, the sequence of the random numbers is
! 458: always the same if a seed is not set.
! 459: @item
! 460: The algorithm is Mersenne Twister
! 461: (http://www.math.keio.ac.jp/matsumoto/mt.html) by M. Matsumoto and
! 462: T. Nishimura. The implementation is done also by themselves.
! 463: @item
! 464: The period of the random number sequence is 2^19937-1.
! 465: @item
! 466: One can save the state of the random number generator with @code{mt_save}.
! 467: By loading the state file with @code{mt_load},
! 468: one can trace a single random number sequence arcoss multiple sessions.
! 469: \E
1.1 noro 470: @end itemize
471:
472: @table @t
1.2 ! noro 473: \JP @item $B;2>H(B
! 474: \EG @item References
1.1 noro 475: @fref{lrandom}, @fref{mt_save mt_load}.
476: @end table
477:
1.2 ! noro 478: \JP @node lrandom,,, $B?t$N1i;;(B
! 479: \EG @node lrandom,,, Numbers
1.1 noro 480: @subsection @code{lrandom}
481: @findex lrandom
482:
483: @table @t
484: @item lradom(@var{bit})
1.2 ! noro 485: \JP :: $BB?G\D9Mp?t$r@8@.$9$k(B.
! 486: \EG :: Generates a long random number.
1.1 noro 487: @end table
488:
489: @table @var
490: @item bit
491: @item return
1.2 ! noro 492: \JP $B<+A3?t(B
! 493: \EG integer
1.1 noro 494: @end table
495:
496: @itemize @bullet
1.2 ! noro 497: \BJP
1.1 noro 498: @item
499: $B9b!9(B @var{bit} $B$NHsIi@0?t$NMp?t$r@8@.$9$k(B.
500: @item
501: @code{random} $B$rJ#?t2s8F$S=P$7$F7k9g$7(B, $B;XDj$N(B bit $BD9$K%^%9%/$7$F$$$k(B.
1.2 ! noro 502: \E
! 503: \BEG
! 504: @item
! 505: Generates a non-negative integer of at most @var{bit} bits.
! 506: @item
! 507: The result is a concatination of outputs of @code{random}.
! 508: \E
1.1 noro 509: @end itemize
510:
511: @table @t
1.2 ! noro 512: \JP @item $B;2>H(B
! 513: \EG @item References
1.1 noro 514: @fref{random}, @fref{mt_save mt_load}.
515: @end table
516:
1.2 ! noro 517: \JP @node mt_save mt_load,,, $B?t$N1i;;(B
! 518: \EG @node mt_save mt_load,,, Numbers
1.1 noro 519: @subsection @code{mt_save}, @code{mt_load}
520: @findex mt_save
521: @findex mt_load
522:
523: @table @t
524: @item mt_save(@var{fname})
1.2 ! noro 525: \JP :: $BMp?t@8@.4o$N8=:_$N>uBV$r%U%!%$%k$K%;!<%V$9$k(B.
! 526: \EG :: Saves the state of the random number generator.
1.1 noro 527: @item mt_load(@var{fname})
1.2 ! noro 528: \JP :: $B%U%!%$%k$K%;!<%V$5$l$?Mp?t@8@.4o$N>uBV$r%m!<%I$9$k(B.
! 529: \EG :: Loads a saved state of the random number generator.
1.1 noro 530: @end table
531:
532: @table @var
533: @item return
1.2 ! noro 534: \JP 0 $B$^$?$O(B 1
! 535: \EG 0 or 1
1.1 noro 536: @item fname
1.2 ! noro 537: \JP $BJ8;zNs(B
! 538: \EG string
1.1 noro 539: @end table
540:
541: @itemize @bullet
1.2 ! noro 542: \BJP
! 543: @item
! 544: $B$"$k>uBV$r%;!<%V$7(B, $B$=$N>uBV$r%m!<%I$9$k$3$H$G(B,
1.1 noro 545: $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
546: $B$G$-$k(B.
1.2 ! noro 547: \E
! 548: \BEG
! 549: @item
! 550: One can save the state of the random number generator with @code{mt_save}.
! 551: By loading the state file with @code{mt_load},
! 552: one can trace a single random number sequence arcoss multiple
! 553: @b{Asir} sessions.
! 554: \E
1.1 noro 555: @end itemize
556:
557: @example
558: [340] random();
559: 3510405877
560: [341] mt_save("/tmp/mt_state");
561: 1
562: [342] random();
563: 4290933890
564: [343] quit;
565: % asir
566: This is Asir, Version 991108.
567: Copyright (C) FUJITSU LABORATORIES LIMITED.
568: 3 March 1994. All rights reserved.
569: [340] mt_load("/tmp/mt_state");
570: 1
571: [341] random();
572: 4290933890
573: @end example
574:
575: @table @t
1.2 ! noro 576: \JP @item $B;2>H(B
! 577: \EG @item References
1.1 noro 578: @fref{random}, @fref{lrandom}.
579: @end table
580:
1.2 ! noro 581: \JP @node nm dn,,, $B?t$N1i;;(B
! 582: \EG @node nm dn,,, Numbers
1.1 noro 583: @subsection @code{nm}, @code{dn}
584: @findex nm
585: @findex dn
586:
587: @table @t
588: @item nm(@var{rat})
1.2 ! noro 589: \JP :: @var{rat} $B$NJ,;R(B.
! 590: \EG :: Numerator of @var{rat}.
1.1 noro 591: @item dn(@var{rat})
1.2 ! noro 592: \JP :: @var{rat} $B$NJ,Jl(B.
! 593: \EG :: Denominator of @var{rat}.
1.1 noro 594: @end table
595:
596: @table @var
597: @item return
1.2 ! noro 598: \JP $B@0?t$^$?$OB?9`<0(B
! 599: \EG integer or polynomial
1.1 noro 600: @item rat
1.2 ! noro 601: \JP $BM-M}?t$^$?$OM-M}<0(B
! 602: \EG rational number or rational expression
1.1 noro 603: @end table
604:
605: @itemize @bullet
1.2 ! noro 606: \BJP
1.1 noro 607: @item
608: $BM?$($i$l$?M-M}?t$^$?M-M}<0$NJ,;R5Z$SJ,Jl$rJV$9(B.
609: @item
610: $BM-M}?t$N>l9g(B, $BJ,Jl$O>o$K@5$G(B, $BId9f$OJ,;R$,;}$D(B.
611: @item
612: $BM-M}<0$N>l9g(B, $BC1$KJ,Jl(B, $BJ,;R$r<h$j=P$9$@$1$G$"$k(B.
613: $BM-M}<0$KBP$7$F$O(B, $BLsJ,$O<+F0E*$K$O9T$o$l$J$$(B. @code{red()}
614: $B$rL@<(E*$K8F$S=P$9I,MW$,$"$k(B.
1.2 ! noro 615: \E
! 616: \BEG
! 617: @item
! 618: Numerator and denominator of a given rational expression.
! 619: @item
! 620: For a rational number, they return its numerator and denominator,
! 621: respectively. For a rational expression whose numerator and denominator
! 622: may contain rational numbers, they do not separate those rational
! 623: coefficients to numerators and denominators.
! 624: @item
! 625: For a rational number, the denominator is always kept positive, and
! 626: the sign is contained in the numerator.
! 627: @item
! 628: @b{Risa/Asir} does not cancel the common divisors unless otherwise explicitly
! 629: specified by the user.
! 630: Therefore, @code{nm()} and @code{dn()} return the numerator and the
! 631: denominator as it is, respectively.
! 632: \E
1.1 noro 633: @end itemize
634:
635: @example
636: [2] [nm(-43/8),dn(-43/8)];
637: [-43,8]
638: [3] dn((x*z)/(x*y));
639: y*x
640: [3] dn(red((x*z)/(x*y)));
641: y
642: @end example
643:
644: @table @t
1.2 ! noro 645: \JP @item $B;2>H(B
! 646: \EG @item References
1.1 noro 647: @fref{red}.
648: @end table
649:
1.2 ! noro 650: \JP @node conj real imag,,, $B?t$N1i;;(B
! 651: \EG @node conj real imag,,, Numbers
1.1 noro 652: @subsection @code{conj}, @code{real}, @code{imag}
653: @findex conj
654:
655: @table @t
656: @item real(@var{comp})
1.2 ! noro 657: \JP :: @var{comp} $B$N<B?tItJ,(B.
! 658: \EG :: Real part of @var{comp}.
1.1 noro 659: @item imag(@var{comp})
1.2 ! noro 660: \JP :: @var{comp} $B$N5u?tItJ,(B.
! 661: \EG :: Imaginary part of @var{comp}.
1.1 noro 662: @item conj(@var{comp})
1.2 ! noro 663: \JP :: @var{comp} $B$N6&LrJ#AG?t(B.
! 664: \EG :: Complex conjugate of @var{comp}.
1.1 noro 665: @end table
666:
667: @table @var
668: @item return comp
1.2 ! noro 669: \JP $BJ#AG?t(B
! 670: \EG complex number
1.1 noro 671: @end table
672:
673: @itemize @bullet
1.2 ! noro 674: \BJP
1.1 noro 675: @item
676: $BJ#AG?t$KBP$7(B, $B<BIt(B, $B5uIt(B, $B6&Lr$r5a$a$k(B.
677: @item
678: $B$3$l$i$O(B, $BB?9`<0$KBP$7$F$bF/$/(B.
1.2 ! noro 679: \E
! 680: \BEG
! 681: @item
! 682: Basic operations for complex numbers.
! 683: @item
! 684: These functions works also for polynomials with complex coefficients.
! 685: \E
1.1 noro 686: @end itemize
687:
688: @example
689: [111] A=(2+@@i)^3;
690: (2+11*@@i)
691: [112] [real(A),imag(A),conj(A)];
692: [2,11,(2-11*@@i)]
693: @end example
694:
1.2 ! noro 695: \JP @node eval,,, $B?t$N1i;;(B
! 696: \EG @node eval,,, Numbers
1.1 noro 697: @subsection @code{eval}
698: @findex eval
699: @cindex PARI
700:
701: @table @t
702: @item eval(@var{obj}[,@var{prec}])
1.2 ! noro 703: \JP :: @var{obj} $B$NCM$NI>2A(B.
! 704: \EG :: Evaluate @var{obj} numerically.
1.1 noro 705: @end table
706:
707: @table @var
708: @item return
1.2 ! noro 709: \JP $B?t$"$k$$$O<0(B
! 710: \EG number or expression
1.1 noro 711: @item obj
1.2 ! noro 712: \JP $B0lHL$N<0(B
! 713: \EG general expression
1.1 noro 714: @item prec
1.2 ! noro 715: \JP $B@0?t(B
! 716: \EG integer
1.1 noro 717: @end table
718:
719: @itemize @bullet
1.2 ! noro 720: \BJP
1.1 noro 721: @item
722: @var{obj} $B$K4^$^$l$kH!?t$NCM$r2DG=$J8B$jI>2A$9$k(B.
723: @item
724: $B7W;;$O(B @b{PARI} (@xref{pari}) $B$,9T$&(B.
725: @item
726: @var{prec} $B$r;XDj$7$?>l9g(B, $B7W;;$O(B, 10 $B?J(B @var{prec} $B7eDxEY$G9T$o$l$k(B.
727: @var{prec} $B$N;XDj$,$J$$>l9g(B, $B8=:_@_Dj$5$l$F$$$k@:EY$G9T$o$l$k(B.
728: (@xref{setprec})
729: @item
730: @table @t
731: @item $B07$($kH!?t$O(B, $B<!$NDL$j(B.
732: @code{sin}, @code{cos}, @code{tan},
733:
734: @code{asin}, @code{acos}, @code{atan},
735:
736: @code{sinh}, @code{cosh}, @code{tanh},
737:
738: @code{asinh}, @code{acosh}, @code{atanh},
739:
740: @code{exp}, @code{log}, @code{pow(a,b) (a^b)}
741: @end table
742: @item
743: $B0J2<$N5-9f$r?t$H$7$FI>2A$G$-$k(B.
744: @table @t
745: @item @@i
746: $B5u?tC10L(B
747: @item @@pi
748: $B1_<~N((B
749: @item @@e
750: $B<+A3BP?t$NDl(B
751: @end table
1.2 ! noro 752: \E
! 753: \BEG
! 754: @item
! 755: Evaluates the value of the functions contained in @var{obj} as far as
! 756: possible.
! 757: @item
! 758: The computation is done by @b{PARI} (@xref{pari}).
! 759: @item
! 760: When @var{prec} is specified, computation will be performed with a
! 761: precision of about @var{prec}-digits.
! 762: If @var{prec} is not specified, computation is performed with the
! 763: precision set currently. (@xref{setprec})
! 764: @item
! 765: Currently available numerical functions are listed below.
! 766: Note they are only a small part of whole @b{PARI} functions.
! 767:
! 768: @table @t
! 769: @code{sin}, @code{cos}, @code{tan},
! 770:
! 771: @code{asin}, @code{acos}, @code{atan},
! 772:
! 773: @code{sinh}, @code{cosh}, @code{tanh},
! 774: @code{asinh}, @code{acosh}, @code{atanh},
! 775:
! 776: @code{exp}, @code{log}, @code{pow(a,b) (a^b)}
! 777: @end table
! 778: @item
! 779: Symbols for special values are as the followings.
! 780: @table @t
! 781: @item @@i
! 782: unit of imaginary number
! 783: @item @@pi
! 784: the number pi,
! 785: the ratio of circumference to diameter
! 786: @item @@e
! 787: Napier's number (@t{exp}(1))
! 788: @end table
! 789: \E
1.1 noro 790: @end itemize
791:
792: @example
793: [118] eval(exp(@@pi*@@i));
794: -1.0000000000000000000000000000
795: [119] eval(2^(1/2));
796: 1.414213562373095048763788073031
797: [120] eval(sin(@@pi/3));
798: 0.86602540378443864674620506632
799: [121] eval(sin(@@pi/3)-3^(1/2)/2,50);
800: -2.78791084448179148471 E-58
801: @end example
802:
803: @table @t
1.2 ! noro 804: \JP @item $B;2>H(B
! 805: \EG @item References
1.1 noro 806: @fref{ctrl}, @fref{setprec}, @fref{pari}.
807: @end table
808:
1.2 ! noro 809: \JP @node pari,,, $B?t$N1i;;(B
! 810: \EG @node pari,,, Numbers
1.1 noro 811: @subsection @code{pari}
812: @findex pari
813: @cindex PARI
814:
815: @table @t
816: @item pari(@var{func},@var{arg},@var{prec})
1.2 ! noro 817: \JP :: @b{PARI} $B$NH!?t(B @var{func} $B$r8F$S=P$9(B.
! 818: \EG :: Call @b{PARI} function @var{func}.
1.1 noro 819: @end table
820:
821: @table @var
822: @item return
1.2 ! noro 823: \JP @var{func} $BKh$K0[$J$k(B.
! 824: \EG Depends on @var{func}.
1.1 noro 825: @item func
1.2 ! noro 826: \JP @b{PARI} $B$NH!?tL>(B
! 827: \EG Function name of @b{PARI}.
1.1 noro 828: @item arg
1.2 ! noro 829: \JP @var{func} $B$N0z?t(B
! 830: \EG Arguments of @var{func}.
1.1 noro 831: @item prec
1.2 ! noro 832: \JP $B@0?t(B
! 833: \EG integer
1.1 noro 834: @end table
835:
836: @itemize @bullet
1.2 ! noro 837: \BJP
1.1 noro 838: @item
839: @b{PARI} $B$NH!?t$r8F$S=P$9(B.
840:
841: @item
842: @b{PARI} @code{[Batut et al.]} $B$O(B Bordeaux $BBg3X$G3+H/$5$l%U(B
843: $B%j!<%=%U%H%&%'%"$H$7$F8x3+$5$l$F$$$k(B. @b{PARI} $B$O?t<0=hM}E*$J5!G=$rM-(B
844: $B$7$F$O$$$k$,(B, $B<g$J%?!<%2%C%H$O@0?tO@$K4XO"$7$??t(B (@b{bignum},
845: @b{bigfloat}) $B$N1i;;$G(B, $B;MB'1i;;$K8B$i$:(B@b{bigfloat} $B$K$h$k$5$^$6$^$J(B
846: $BH!?tCM$NI>2A$r9bB.$K9T$&$3$H$,$G$-$k(B. @b{PARI} $B$OB>$N%W%m%0%i%`$+$i(B
847: $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
848: @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
1.2 ! noro 849: $BMxMQ$9$k$3$H$b$G$-$k(B. $B8=:_$N%P!<%8%g%s$O(B @b{2.0.17beta} $B$G$$$/$D$+$N(B ftp
! 850: site ($B$?$H$($P(B @code{ftp://megrez.ceremab.u-bordeaux.fr/pub/pari})
1.1 noro 851: $B$+$i(B anonymous ftp $B$G$-$k(B.
852: @item
853: $B:G8e$N0z?t(B @var{prec} $B$G7W;;@:EY$r;XDj$G$-$k(B.
854: @var{prec} $B$r>JN,$7$?>l9g(B @code{setprec()} $B$G;XDj$7$?@:EY$H$J$k(B.
855: @item
856: $B8=;~E@$G<B9T$G$-$k(B @b{PARI} $B$NH!?t$O<!$NDL$j$G$"$k(B. $B$$$:$l$b(B
857: 1 $B0z?t$G(B @b{Asir} $B$,BP1~$G$-$k7?$N0z?t$r$H$kH!?t$G$"$k(B.
858: $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.
1.2 ! noro 859: \E
! 860: \BEG
! 861: @item
! 862: This command connects @b{Asir} to @b{PARI} system so that several
! 863: functions of @b{PARI} can be conveniently used from @b{Risa/Asir}.
! 864: @item
! 865: @b{PARI} @code{[Batut et al.]} is developed at Bordeaux University, and
! 866: distributed as a free software. Though it has a certain facility to computer
! 867: algebra, its major target is the operation of numbers (@b{bignum},
! 868: @b{bigfloat}) related to the number theory. It facilitates various
! 869: function evaluations as well as arithmetic operations at a remarkable
! 870: speed. It can also be used from other external programs as a library.
! 871: It provides a language interface named @samp{gp} to its library, which
! 872: enables a user to use @b{PARI} as a calculator which runs on UNIX.
! 873: The current version is @b{2.0.17beta}. It can be obtained by several ftp
! 874: sites. (For example, @code{ftp://megrez.ceremab.u-bordeaux.fr/pub/pari}.)
! 875: @item
! 876: The last argument (optional) @var{int} specifies the precision in digits
! 877: for bigfloat operation.
! 878: If the precision is not explicitly specified, operation will be performed
! 879: with the precision set by @code{setprec()}.
! 880: @item
! 881: Currently available functions of @b{PARI} system are as follows.
! 882: Note these are only a part of functions in @b{PARI} system.
! 883: For details of individual functions, refer to the @b{PARI} manual.
! 884: (Some of them can be seen in the following example.)
! 885: \E
1.1 noro 886:
887: @code{abs},
888: @code{adj},
889: @code{arg},
890: @code{bigomega},
891: @code{binary},
892: @code{ceil},
893: @code{centerlift},
894: @code{cf},
895: @code{classno},
896: @code{classno2},
897: @code{conj},
898: @code{content},
899: @code{denom},
900: @code{det},
901: @code{det2},
902: @code{detr},
903: @code{dilog},
904: @code{disc},
905: @code{discf},
906: @code{divisors},
907: @code{eigen},
908: @code{eintg1},
909: @code{erfc},
910: @code{eta},
911: @code{floor},
912: @code{frac},
913: @code{galois},
914: @code{galoisconj},
915: @code{gamh},
916: @code{gamma},
917: @code{hclassno},
918: @code{hermite},
919: @code{hess},
920: @code{imag},
921: @code{image},
922: @code{image2},
923: @code{indexrank},
924: @code{indsort},
925: @code{initalg},
926: @code{isfund},
927: @code{isprime},
928: @code{ispsp},
929: @code{isqrt},
930: @code{issqfree},
931: @code{issquare},
932: @code{jacobi},
933: @code{jell},
934: @code{ker},
935: @code{keri},
936: @code{kerint},
937: @code{kerintg1},
938: @code{kerint2},
939: @code{kerr},
940: @code{length},
941: @code{lexsort},
942: @code{lift},
943: @code{lindep},
944: @code{lll},
945: @code{lllg1},
946: @code{lllgen},
947: @code{lllgram},
948: @code{lllgramg1},
949: @code{lllgramgen},
950: @code{lllgramint},
951: @code{lllgramkerim},
952: @iftex
953: @break
954: @end iftex
955: @code{lllgramkerimgen},
956: @code{lllint},
957: @code{lllkerim},
958: @code{lllkerimgen},
959: @code{lllrat},
960: @code{lngamma},
961: @code{logagm},
962: @code{mat},
963: @code{matinvr},
964: @code{matrixqz2},
965: @code{matrixqz3},
966: @code{matsize},
967: @code{modreverse},
968: @code{mu},
969: @code{nextprime},
970: @code{norm},
971: @code{norml2},
972: @code{numdiv},
973: @code{numer},
974: @code{omega},
975: @code{order},
976: @code{ordred},
977: @code{phi},
978: @code{pnqn},
979: @code{polred},
980: @code{polred2},
981: @code{primroot},
982: @code{psi},
983: @code{quadgen},
984: @code{quadpoly},
985: @code{real},
986: @code{recip},
987: @code{redcomp},
988: @code{redreal},
989: @code{regula},
990: @code{reorder},
991: @code{reverse},
992: @code{rhoreal},
993: @code{roots},
994: @code{rootslong},
995: @code{round},
996: @code{sigma},
997: @code{signat},
998: @code{simplify},
999: @code{smalldiscf},
1000: @code{smallfact},
1001: @code{smallpolred},
1002: @code{smallpolred2},
1003: @code{smith},
1004: @code{smith2},
1005: @code{sort},
1006: @code{sqr},
1007: @code{sqred},
1008: @code{sqrt},
1009: @code{supplement},
1010: @code{trace},
1011: @code{trans},
1012: @code{trunc},
1013: @code{type},
1014: @code{unit},
1015: @code{vec},
1016: @code{wf},
1017: @code{wf2},
1018: @code{zeta}
1019:
1.2 ! noro 1020: \BJP
1.1 noro 1021: @item
1022: @b{Asir} $B$GMQ$$$F$$$k$N$O(B @b{PARI} $B$N$[$s$N0lIt$N5!G=$G$"$k$,(B, $B:#8e(B
1023: $B$h$jB?$/$N5!G=$,MxMQ$G$-$k$h$&2~NI$9$kM=Dj$G$"$k(B.
1.2 ! noro 1024: \E
! 1025: \BEG
! 1026: @item
! 1027: @b{Asir} currently uses only a very small subset of @b{PARI}.
! 1028: We will improve @b{Asir} so that it can provide more functions of
! 1029: @b{PARI}.
! 1030: \E
1.1 noro 1031: @end itemize
1032:
1033: @example
1.2 ! noro 1034: \JP /* $B9TNs$N8GM-%Y%/%H%k$r5a$a$k(B. */
! 1035: \EG /* Eigen vectors of a numerical matrix */
1.1 noro 1036: [0] pari(eigen,newmat(2,2,[[1,1],[1,2]]));
1037: [ -1.61803398874989484819771921990 0.61803398874989484826 ]
1038: [ 1 1 ]
1.2 ! noro 1039: \JP /* 1 $BJQ?tB?9`<0$N:,$r5a$a$k(B. */
! 1040: \EG /* Roots of a polynomial */
1.1 noro 1041: [1] pari(roots,t^2-2);
1042: [ -1.41421356237309504876 1.41421356237309504876 ]
1043: @end example
1044:
1045: @table @t
1.2 ! noro 1046: \JP @item $B;2>H(B
! 1047: \EG @item References
1.1 noro 1048: @fref{setprec}.
1049: @end table
1050:
1.2 ! noro 1051: \JP @node setprec,,, $B?t$N1i;;(B
! 1052: \EG @node setprec,,, Numbers
1.1 noro 1053: @subsection @code{setprec}
1054: @findex setprec
1055: @cindex PARI
1056:
1057: @table @t
1058: @item setprec([@var{n}])
1.2 ! noro 1059: \JP :: @b{bigfloat} $B$N7e?t$r(B @var{n} $B7e$K@_Dj$9$k(B.
! 1060: \EG :: Sets the precision for @b{bigfloat} operations to @var{n} digits.
1.1 noro 1061: @end table
1062:
1063: @table @var
1064: @item return
1.2 ! noro 1065: \JP $B@0?t(B
! 1066: \EG integer
1.1 noro 1067: @item n
1.2 ! noro 1068: \JP $B@0?t(B
! 1069: \EG integer
1.1 noro 1070: @end table
1071:
1072: @itemize @bullet
1.2 ! noro 1073: \BJP
1.1 noro 1074: @item
1075: $B0z?t$,$"$k>l9g(B, @b{bigfloat} $B$N7e?t$r(B @var{n} $B7e$K@_Dj$9$k(B.
1076: $B0z?t$N$"$k$J$7$K$+$+$o$i$:(B, $B0JA0$K@_Dj$5$l$F$$$?CM$rJV$9(B.
1077: @item
1078: @b{bigfloat} $B$N7W;;$O(B @b{PARI} (@xref{pari}) $B$K$h$C$F9T$o$l$k(B.
1079: @item
1080: @b{bigfloat} $B$G$N7W;;$KBP$7M-8z$G$"$k(B.
1081: @b{bigfloat} $B$N(B flag $B$r(B on $B$K$9$kJ}K!$O(B, @code{ctrl} $B$r;2>H(B.
1082: @item
1083: $B@_Dj$G$-$k7e?t$K>e8B$O$J$$$,(B, $B;XDj$7$?7e?t$K@_Dj$5$l$k$H$O(B
1084: $B8B$i$J$$(B. $BBg$-$a$NCM$r@_Dj$9$k$N$,0BA4$G$"$k(B.
1.2 ! noro 1085: \E
! 1086: \BEG
! 1087: @item
! 1088: When an argument is given, it
! 1089: sets the precision for @b{bigfloat} operations to @var{n} digits.
! 1090: The return value is always the previous precision in digits regardless of
! 1091: the existence of an argument.
! 1092:
! 1093: @item
! 1094: @b{Bigfloat} operations are done by @b{PARI}. (@xref{pari})
! 1095: @item
! 1096: This is effective for computations in @b{bigfloat}.
! 1097: Refer to @code{ctrl()} for turning on the `@b{bigfloat} flag.'
! 1098: @item
! 1099: There is no upper limit for precision digits.
! 1100: It sets the precision to some digits around the specified precision.
! 1101: Therefore, it is safe to specify a larger value.
! 1102: \E
1.1 noro 1103: @end itemize
1104:
1105: @example
1106: [1] setprec();
1107: 9
1108: [2] setprec(100);
1109: 9
1110: [3] setprec(100);
1111: 96
1112: @end example
1113:
1114: @table @t
1.2 ! noro 1115: \JP @item $B;2>H(B
1.1 noro 1116: @fref{ctrl}, @fref{eval}, @fref{pari}.
1117: @end table
1118:
1.2 ! noro 1119: \JP @node setmod,,, $B?t$N1i;;(B
! 1120: \EG @node setmod,,, Numbers
1.1 noro 1121: @subsection @code{setmod}
1122: @findex setmod
1123:
1124: @table @t
1125: @item setmod([@var{p}])
1.2 ! noro 1126: \JP :: $BM-8BBN$r(B GF(@var{p}) $B$K@_Dj$9$k(B.
! 1127: \EG :: Sets the ground field to GF(@var{p}).
1.1 noro 1128: @end table
1129:
1130: @table @var
1131: @item return
1.2 ! noro 1132: \JP $B@0?t(B
! 1133: \EG integer
1.1 noro 1134: @item n
1.2 ! noro 1135: \JP 2^27 $BL$K~$NAG?t(B
! 1136: \EG prime less than 2^27
1.1 noro 1137: @end table
1138:
1139: @itemize @bullet
1.2 ! noro 1140: \BJP
1.1 noro 1141: @item
1142: $BM-8BBN$r(B GF(@var{p}) $B$K@_Dj$9$k(B. $B@_DjCM$rJV$9(B.
1143: @item
1144: $BM-8BBN$N85$N7?$r;}$D?t$O(B, $B$=$l<+?H$O$I$NM-8BBN$KB0$9$k$+$N>pJs$r;}$?$:(B,
1145: $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.
1.2 ! noro 1146: @item
! 1147: $B0L?t$NBg$-$JM-8BBN$K4X$7$F$O(B @pxref{$BM-8BBN$K4X$9$k1i;;(B}.
! 1148: \E
! 1149: \BEG
! 1150: @item
! 1151: Sets the ground field to GF(@var{p}) and returns the value @var{p}.
! 1152: @item
! 1153: A member of a finite field does not have any information
! 1154: about the field and the arithmetic operations over GF(@var{p}) are applied
! 1155: with @var{p} set at the time.
! 1156: @item
! 1157: As for large finite fields, @pxref{Finite fields}.
! 1158: \E
1.1 noro 1159: @end itemize
1160:
1161: @example
1162: [0] A=dp_mod(dp_ptod(2*x,[x]),3,[]);
1163: (2)*<<1>>
1164: [1] A+A;
1165: addmi : invalid modulus
1166: return to toplevel
1167: [1] setmod(3);
1168: 3
1169: [2] A+A;
1170: (1)*<<1>>
1171: @end example
1172:
1173: @table @t
1.2 ! noro 1174: \JP @item $B;2>H(B
! 1175: \EG @item References
! 1176: \JP @fref{dp_mod dp_rat}, @fref{$B?t$N7?(B}.
! 1177: \EG @fref{dp_mod dp_rat}, @fref{Types of numbers}.
1.1 noro 1178: @end table
1179:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>