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