1Pari(3)               User Contributed Perl Documentation              Pari(3)
2
3
4

NAME

6       "Math::Pari" - Perl interface to PARI.
7

SYNOPSIS

9         use Math::Pari;
10         $a = PARI 2;
11         print $a**10000;
12
13       or
14
15         use Math::Pari qw(Mod);
16         $a = Mod(3,5);
17         print $a**10000;
18

DESCRIPTION

20       This package is a Perl interface to famous library PARI for numeri‐
21       cal/scientific/number-theoretic calculations.  It allows use of most
22       PARI functions as Perl functions, and (almost) seamless merging of PARI
23       and Perl data. In what follows we suppose prior knowledge of what PARI
24       is (see <ftp://megrez.math.u-bordeaux.fr/pub/pari>, or Math::libPARI).
25

EXPORTed functions

27       DEFAULT
28           By default the package exports functions PARI(), PARIcol(), PARI‐
29           var(), PARImat() and PARImat_tr() which convert their argument(s)
30           to a PARI object. (In fact PARI() is just an alias for "new
31           Math::Pari").  The function PARI() accepts following data as its
32           arguments
33
34           One integer      Is converted to a PARI integer.
35
36           One float        Is converted to a PARI float.
37
38           One string       Is executed as a PARI expresion (so should not
39                            contain whitespace).
40
41           PARI object      Is passed unchanged.
42
43           Reference to a Perl array
44                            Each element is converted using the same rules,
45                            PARI vector-row with these elements is returned.
46
47           Several of above The same as with a reference to array.
48
49       Conflicts of rules in PARI()
50           In deciding what rule of the above to apply the preference is given
51           to the uppermost choice of those available now.  If none matches,
52           then the string rule is used.  So PARI(1) returns integer,
53           "PARI(1.)"  returns float, "PARI("1")" evaluates 1 as a PARI
54           expression (well, the result is the same as PARI(1), only slower).
55
56           Note that for Perl these data are synonimous, since Perl freely
57           converts between integers, float and strings.  However, to PARI()
58           only what the argument is now is important.  If $v is 1 in the Perl
59           world, "PARI($v)" may convert it to an integer, float, or to the
60           result of evaluating the PARI program 1 (all depending on how $v
61           was created and accessed in Perl).
62
63           This is a fundamental limitation of creating an interface between
64           two systems, both with polymorphic objects, but with subtly differ‐
65           ent semantic of the flavors of these objects.  In reality, however,
66           this is rarely a problem.
67
68       PARIcol(), PARImat() and PARImat_tr()
69           PARIcol() behaves in the same way as PARI() unless given several
70           arguments. In the latter case it returns a vector-column instead of
71           a vector-row.
72
73           PARImat() constructs a matrix out of the given arguments. It will
74           work if PARI() will construct a vector of vectors given the same
75           arguments.  The internal vectors become columns of the matrix.
76           PARImat_tr() behaves similarly, but the internal vectors become
77           rows of the matrix.
78
79           Since PARI matrices are similar to vector-rows of vector-columns,
80           PARImat() is quickier, but PARImat_tr() better corresponds to the
81           PARI input and output forms of matrices:
82
83             print PARImat    [[1,2], [3,4]];      # prints [1,3;2,4]
84             print PARImat_tr [[1,2], [3,4]];      # prints [1,2;3,4]
85
86       "use" with arguments
87           If arguments are specified in the "use Math::Pari" directive, the
88           PARI functions appearing as arguments are exported in the caller
89           context. In this case the function PARI() and friends is not
90           exported, so if you need them, you should include them into export
91           list explicitely, or include ":DEFAULT" tag:
92
93             use Math::Pari qw(factorint PARI);
94             use Math::Pari qw(:DEFAULT factorint);
95
96           or simply do it in two steps
97
98             use Math::Pari;
99             use Math::Pari 'factorint';
100
101           The other tags recognized are ":PARI", ":all", "prec=NUMBER", num‐
102           ber tags (e.g., ":4"), overloaded constants tags (":int", ":float",
103           ":hex") and section names tags.  The number tags export functions
104           from the PARI library from the given class (except for ":PARI",
105           which exports all of the classes).  Tag ":all" exports all of the
106           exportable symbols and ":PARI".
107
108           Giving "?" command to "gp" (PARI calculator) lists the following
109           classes:
110
111             1: Standard monadic or dyadic OPERATORS
112             2: CONVERSIONS and similar elementary functions
113             3: TRANSCENDENTAL functions
114             4: NUMBER THEORETICAL functions
115             5: Functions related to ELLIPTIC CURVES
116             6: Functions related to general NUMBER FIELDS
117             7: POLYNOMIALS and power series
118             8: Vectors, matrices, LINEAR ALGEBRA and sets
119             9: SUMS, products, integrals and similar functions
120             10: GRAPHIC functions
121             11: PROGRAMMING under GP
122
123           One can use section names instead of number tags.  Recognized names
124           are
125
126             :standard :conversions :transcendental :number :elliptic
127             :fields :polynomials :vectors :sums :graphic :programming
128
129           One can get the list of all of the functions accessible by
130           "Math::Pari", or the accessible functions from the given section
131           using listPari() function.
132
133           Starting from version 5.005 of Perl, three constant-overload tags
134           are supported: ":int", ":float", ":hex".  If used, all the inte‐
135           ger/float/hex-or-octal-or-binary literals in Perl will be automati‐
136           cally converted to became PARI objects.  For example,
137
138             use Math::Pari ':int';
139             print 2**1000;
140
141           is equivalent to
142
143             print PARI(2)**PARI(1000);
144
145           (The support for this Perl feature is buggy before the Perl version
146           5.005_57 - unless Perl uses mymalloc options; you can check for
147           this with "perl -V:usemymalloc".)  Note also that (at least with
148           some versions of Perl) one should enable ':float' for conversion of
149           long integer literals (Perl may consider them as floats, since they
150           won't fit into Perl integers); note that it is PARI which deter‐
151           mines which PARI subtype is assigned to each such literal:
152
153             use Math::Pari ':float', 'type_name';
154             print type_name 22222222222222222222222;
155
156           prints "t_INT".
157

Available functions

159       Directly accessible from Perl
160
161       This package supports all the functions from the PARI library with a
162       signature which can be recognized by Math::Pari.  This means that when
163       you update the PARI library, the newly added functions will we avail‐
164       able without any change to this package; only a recompile is needed.
165       In fact no recompile will be needed if you link libPARI dynamically
166       (you need to modify the Makefile manually to do this).
167
168       You can "reach" unsupported functions via going directly to PARI parser
169       using the string flavor of PARI() function, as in
170
171         3 + PARI('O(x^17)');
172
173       For some "unreachable" functions there is a special wrapper functions,
174       such as "O(variable,power)").
175
176       The following functions are specific to GP calculator, thus are not
177       available to Math::Pari in any way:
178
179         default error extern input print print1 printp printp1
180         printtex quit read system whatnow write write1 writetex
181
182       whatnow() function is useless, since Math::Pari does not support the
183       "compatibility" mode (with older PARI library).  The functionality of
184       print(), write() and variants is available via automatic string trans‐
185       lation, and pari_print() function and its variants (see "Printout func‐
186       tions").
187
188       default() is the only important function with functionality not sup‐
189       ported by the current interface.  Note however, that three most impor‐
190       tant default() actions are supported by allocatemem(), setprimelimit(),
191       setprecision() and setseriesprecision() functions.  (When called with‐
192       out arguments, these functions return the current values.)
193
194       allocatemem($bytes) should not be called from inside Math::Pari func‐
195       tions (such as forprimes()).
196
197       Arguments
198
199       Arguments to PARI functions are automatically converted to "long" or a
200       PARI object depending on the signature of the actual library function.
201       The arguments are forced into the given type, so even if "gp" rejects
202       your code similar to
203
204         func(2.5);                    # func() takes a long in C
205
206       arguing that a particular argument should be of "type T_INT" (i.e., a
207       Pari integer), the corresponding code will work in "Math::Pari", since
208       2.5 is silently converted to "long", per the function signature.
209
210       Return values
211
212       PARI functions return a PARI object or a Perl's integer depending on
213       what the actual library function returns.
214
215       Additional functions
216
217       Some PARI functions are available in "gp" (i.e., in "PARI" calculator)
218       via infix notation only. In "Math::Pari" these functions are available
219       in functional notations too.  Some other convenience functions are also
220       made available.
221
222       Infix, prefix and postfix operations
223            are available under names
224
225              gneg, gadd, gsub, gmul, gdiv, gdivent, gmod, gpui,
226              gle, gge, glt, ggt, geq, gne, gegal, gor, gand,
227              gcmp, gcmp0, gcmp1, gcmp_1.
228
229            "gdivent" means euclidean quotient, "gpui" is power, "gegal"
230            checks whether two objects are equal, "gcmp" is applicable to two
231            real numbers only, "gcmp0", "gcmp1", "gcmp_1" compare with 0, 1
232            and -1 correspondingly (see PARI user manual for details, or
233            Math::libPARI).  Note that all these functions are more readily
234            available via operator overloading, so instead of
235
236              gadd(gneg($x), $y)
237
238            one can write
239
240              -$x+$y
241
242            (as far as overloading may be triggered, see overload, so we
243            assume that at least one of $x or $y is a PARI object).
244
245       Conversion functions
246              pari2iv, pari2nv, pari2num, pari2pv, pari2bool
247
248            convert a PARI object to an integer, float, integer/float (what‐
249            ever is better), string, and a boolean value correspondingly. Most
250            the time you do not need these functions due to automatic conver‐
251            sions.
252
253       Printout functions
254              pari_print, pari_pprint, pari_texprint
255
256            perform the same conversions to strings as their PARI counter‐
257            parts, but do not print the result.  The difference of
258            pari_print() with pari2pv() is the number of significant digits
259            they output, and whitespace in the output.  pari2pv(), which is
260            intended for "computer-readable strings", outputs as many digits
261            as is supported by the current precision of the number; while
262            pari_print(), which targets human-readable strings, takes into
263            account the currently specified output precision too.
264
265       Constant functions
266            Some mathematical constants appear as function without arguments
267            in PARI.  These functions are available in Math::Pari too.  If you
268            export them as in
269
270              use Math::Pari qw(:DEFAULT Pi I Euler);
271
272            they can be used as barewords in your program:
273
274              $x = Pi ** Euler;
275
276       Low-level functions
277            For convenience of low-level PARI programmers some low-level func‐
278            tions are made available as well (all except type_name() and
279            changevalue() are not exportable):
280
281              typ($x)
282              lg($x)
283              lgef($x)
284              lgefint($x)
285              longword($x, $n)
286              type_name($x)
287              changevalue($name,$newvalue)
288
289            Here longword($x,$n) returns $n-th word in the memory representa‐
290            tion of $x (including non-code words).  type_name() differs from
291            the PARI function type(): type() returns a PARI object, while
292            type_name() returns a Perl string.  (PARI objects of string type
293            behave very non-intuitive w.r.t. string comparison functions;
294            remember that they are compared using lex() to the results of
295            evaluation of other argument of comparison!)
296
297            The function listPari($number) outputs a list of names of PARI
298            functions in the section $number.  Use listPari(-1) to get the
299            list across all of the sections.
300
301       Uncompatible functions
302              O
303
304            Since implementing "O(7**6)" would be very tedious, we provide a
305            two-argument form "O(7,6)" instead (meaning the same as "O(7^6)"
306            in PARI).  Note that with polynomials there is no problem like
307            this one, both "O($x,6)" and "O($x**6)" work.
308
309              ifact(n)
310
311            integer factorial functions, available from "gp" as "n!".
312
313       Looping functions
314
315       PARI has a big collection of functions which loops over some set.  Such
316       a function takes two special arguments: loop variable, and the code to
317       execute in the loop.
318
319       The code can be either a string (which contains PARI code to execute -
320       thus should not contain whitespace), or a Perl code reference.  The
321       loop variable can be a string giving the name of PARI variable (as in
322
323         fordiv(28, 'j', 'a=a+j+j^2');
324
325       or
326
327         $j= 'j';
328         fordiv(28, $j, 'a=a+j+j^2');
329
330       ), a PARI monomial (as in
331
332         $j = PARI 'j';
333         fordiv(28, $j, sub { $a += $j + $j**2 });
334
335       ), or a "delayed Math::Pari variable" (as in
336
337         $j = PARIvar 'j';
338         fordiv(28, $j, 'a=a+j+j^2');
339
340       ).  If none of these applies, as in
341
342         my $j;        # Have this in a separate statement
343         fordiv(28, $j, sub { $a += $j + $j**2 });
344
345       then during the execution of the "sub", Math::Pari would autogenerate a
346       PARI variable, and would put its value in $j; this value of $j is tem‐
347       porary only, the old contents of $j is restored when fordiv() returns.
348
349       Note that since you have no control over this name, you will not be
350       able to use this variable from your PARI code; e.g.,
351
352         $j = 7.8;
353         fordiv(28, $j, 'a=a+j+j^2');
354
355       will not make "j" mirror $j (unless you explicitely set up "j" to be a
356       no-argument PARI function mirroring $j, see "Accessing Perl functions
357       from PARI code").
358
359       Caveats.  There are 2 flavors of the "code" arguments (string/"sub"),
360       and 4 types of the "variable" arguments (string/monomial/"PARI‐
361       var"/other).  However, not all 8 combinations make sense.  As we
362       already explained, an "other" variable cannot work with a "string"
363       code.
364
365       Useless musing alert! Do not read the rest of this section! Do not use
366       "string" variables with "sub" code, and do not ask why!
367
368       Additionally, the following code will not do what you expect
369
370         $x = 0;
371         $j = PARI 'j';
372         fordiv(28, 'j', sub { $x += $j } );   # Use $j as a loop variable!
373
374       since the PARI function "fordiv" localizes the PARI variable "j" inside
375       the loop, but $j will still reference the old value; the old value is a
376       monomial, not the index of the loop (which is an integer each time
377       "sub" is called).  The simplest workaround is not to use the above syn‐
378       tax (i.e., not mixing literal loop variable with Perl loop code, just
379       using $j as the second argument to "fordiv" is enough):
380
381         $x = 0;
382         $j = PARI 'j';
383         fordiv(28, $j, sub { $x += $j } );
384
385       Alternately, one can make a delayed variable $j which will always ref‐
386       erence the same thing "j" references in PARI now by using "PARIvar"
387       constructor
388
389         $x = 0;
390         $j = PARIvar 'j';
391         fordiv(28, 'j', sub { $x += $j } );
392
393       (This problem is similar to
394
395         $ref = \$_;                   # $$ref is going to be old value even after
396                                       # localizing $_ in Perl's grep/map
397
398       not accessing localized values of $_ in the plain Perl.)
399
400       Another possible quirk is that
401
402         fordiv(28, my $j, sub { $a += $j + $j**2 });
403
404       will not work too - by a different reason.  "my" declarations change
405       the meaning of $j only after the end of the current statement; thus $j
406       inside "sub" will access a different variable $j (typically a non-lexi‐
407       cal, global variable $j) than one you declared on this line.
408
409       Accessing Perl functions from PARI code
410
411       Use the same name inside PARI code:
412
413         sub counter { $i += shift; }
414         $i = 145;
415         PARI 'k=5' ;
416         fordiv(28, 'j', 'k=k+counter(j)');
417         print PARI('k'), "\n";
418
419       prints
420
421          984
422
423       Due to a difference in the semantic of variable-number-of-parameters-
424       functions between PARI and Perl, if the Perl subroutine takes a vari‐
425       able number of arguments (via "@" in the prototype or a missing proto‐
426       type), up to 6 arguments are supported when this function is called
427       from PARI.  If called from PARI with fewer arguments, the rest of argu‐
428       ments will be set to be integers "PARI 0".
429
430       Note also that no direct import of Perl variables is available yet (but
431       you can write a function wrapper for this):
432
433         sub getv () {$v}
434
435       There is an unsupported (and undocumented ;-) function for explicitely
436       importing Perl functions into PARI, possibly with a different name, and
437       possibly with explicitely specifying number of arguments.
438

PARI objects

440       Functions from PARI library may take as arguments and/or return values
441       the objects of C type "GEN". In Perl these data are encapsulated into
442       special kind of Perl variables: PARI objects. You can check for a vari‐
443       able $obj to be a PARI object using
444
445         ref $obj and $obj->isa('Math::Pari');
446
447       Most the time you do not need this due to automatic conversions and
448       overloading.
449

PARI monomials and Perl barewords

451       If very lazy, one can code in Perl the same way one does it in PARI.
452       Variables in PARI are denoted by barewords, as in "x", and in the
453       default configuration (no warnings, no strict) Perl allows the same -
454       up to some extent.  Do not do this, since there are many surprising
455       problems.
456
457       Some bareletters denote Perl operators, like "q", "x", "y", "s". This
458       can lead to errors in Perl parsing your expression. E.g.,
459
460         print sin(tan(t))-tan(sin(t))-asin(atan(t))+atan(asin(t));
461
462       may parse OK after "use Math::Pari qw(sin tan asin atan)".  Why?
463
464       After importing, the word "sin" will denote the PARI function sin(),
465       not Perl operator sin().  The difference is subtle: the PARI function
466       implicitly forces its arguments to be converted PARI objects; it gets
467       't' as the argument, which is a string, thus is converted to what "t"
468       denotes in PARI - a monomial.  While the Perl operator sin() grants
469       overloading (i.e., it will call PARI function sin() if the argument is
470       a PARI object), it does not force its argument; given 't' as argument,
471       it converts it to what sin() understands, a float (producing 0.), so
472       will give 0. as the answer.
473
474       However
475
476         print sin(tan(y))-tan(sin(y))-asin(atan(y))+atan(asin(y));
477
478       would not compile. You should avoid lower-case barewords used as PARI
479       variables, e.g., do
480
481         $y = PARI 'y';
482         print sin(tan($y))-tan(sin($y))-asin(atan($y))+atan(asin($y));
483
484       to get
485
486         -1/18*y^9+26/4725*y^11-41/1296*y^13+328721/16372125*y^15+O(y^16)
487
488       (BTW, it is a very good exercise to get the leading term by hand).
489
490       Well, the same advice again: do not use barewords anywhere in your pro‐
491       gram!
492

Overloading and automatic conversion

494       Whenever an arithmetic operation includes at least one PARI object, the
495       other arguments are converted to a PARI object and the corresponding
496       PARI library functions is used to implement the operation.  Currently
497       the following arithmetic operations are overloaded:
498
499         unary -
500         + - * / % ** abs cos sin exp log sqrt
501         << >>
502         <= == => <  >  != <=>
503         le eq ge lt gt ne cmp
504         ⎪ & ^ ~
505
506       Numeric comparison operations are converted to "gcmp" and friends,
507       string comparisons compare in lexicographical order using "lex".
508
509       Additionally, whenever a PARI object appears in a situation that
510       requires integer, numeric, boolean or string data, it is converted to
511       the corresponding type. Boolean conversion is subject to usual PARI
512       pitfalls related to imprecise zeros (see documentation of "gcmp0" in
513       PARI reference).
514
515       For details on overloading, see overload.
516
517       Note that a check for equality is subject to same pitfalls as in PARI
518       due to imprecise values.  PARI may also refuse to compare data of dif‐
519       ferent types for equality if it thinks this may lead to counterintu‐
520       itive results.
521
522       Note also that in PARI the numeric ordering is not defined for some
523       types of PARI objects.  For string comparison operations we use PARI-
524       lexicographical ordering.
525

PREREQUISITES

527       Perl
528
529       In the versions of perl earlier than 5.003 overloading used a different
530       interface, so you may need to convert "use overload" line to %OVERLOAD,
531       or, better, upgrade.
532
533       PARI
534
535       Starting from version 2.0, this module comes without a PARI library
536       included.
537
538       For the source of PARI library see <ftp://megrez.math.u-bor‐
539       deaux.fr/pub/pari>.
540

Perl vs. PARI: different syntax

542       Note that the PARI notations should be used in the string arguments to
543       PARI() function, while the Perl notations should be used otherwise.
544
545       "^" Power is denoted by "**" in Perl.
546
547       "\" and "\/"
548           There are no such operators in Perl, use the word forms "gdi‐
549           vent(x,y)" and "gdivround(x,y)" instead.
550
551       "~" There is no postfix "~" Perl operator.  Use mattranspose() instead.
552
553       "'" There is no postfix "'" Perl operator.  Use deriv() instead.
554
555       "!" There is no postfix "!" Perl operator.  Use factorial()/ifact()
556           instead (returning a real or an integer correspondingly).
557
558       big integers
559           Perl converts big literal integers to doubles if they could not be
560           put into C integers (the particular flavor can be found in the out‐
561           put of "perl -V" in newer version of Perl, look for
562           "ivtype"/"ivsize").  If you want to input such an integer, use
563
564             while ($x < PARI('12345678901234567890')) ...
565
566           instead of
567
568             while ($x < 12345678901234567890) ...
569
570           Why?  Because conversion to double leads to precision loss (typi‐
571           cally above 1e15, see perlnumber), and you will get something like
572           12345678901234567168 otherwise.
573
574           Starting from version 5.005 of Perl, if the tag ":int" is used on
575           the 'use Math::Pari' line, all of the integer literals in Perl will
576           be automatically converted to became PARI objects.  E.g.,
577
578             use Math::Pari ':int';
579             print 2**1000;
580
581           is equivalent to
582
583             print PARI(2)**PARI(1000);
584
585           Similarly, large integer literals do not lose precision.
586
587           This directive is lexically scoped.  There is a similar tag ":hex"
588           which affects hexadecimal, octal and binary constants.  One may
589           also need to use tag ":float" for auto-conversion of large integer
590           literals which Perl considers as floating point literals (see
591           ""use" with arguments" for details).
592
593       doubles
594           Doubles in Perl are typically of precision approximately 15 digits
595           (see perlnumber).  When you use them as arguments to PARI func‐
596           tions, they are converted to PARI real variables, and due to inter‐
597           mediate 15-digits-to-binary conversion of Perl variables the result
598           may be different than with the PARI many-digits-to-binary conver‐
599           sion.  E.g., "PARI(0.01)" and "PARI('0.01')" differ at 19-th place,
600           as
601
602             setprecision(38);
603             print pari_print(0.01),   "\n",
604                   pari_print('0.01'), "\n";
605
606           shows.
607
608           Note that setprecision() changes the output format of pari_print()
609           and friends, as well as the default internal precision.  The
610           generic PARI===>string conversion does not take into account the
611           output format, thus
612
613             setprecision(38);
614             print PARI(0.01),       "\n",
615                   PARI('0.01'),     "\n",
616                   pari_print(0.01), "\n";
617
618           will print all the lines with different number of digits after the
619           point: the first one with 22, since the double 0.01 was converted
620           to a low-precision PARI object, the second one with 41, since
621           internal form for precision 38 requires that many digits for repre‐
622           sentation, and the last one with 39 to have 38 significant digits.
623
624           Starting from version 5.005 of Perl, if the tag ":float" is used on
625           the "use Math::Pari" line, all the float literals in Perl will be
626           automatically converted to became PARI objects.  E.g.,
627
628             use Math::Pari ':float';
629             print atan(1.);
630
631           is equivalent to
632
633             print atan(PARI('1.'));
634
635           Similarly, large float literals do not lose precision.
636
637           This directive is lexically scoped.
638
639       array base
640           Arrays are 1-based in PARI, are 0-based in Perl.  So while array
641           access is possible in Perl, you need to use different indices:
642
643             $nf = PARI 'nf';      # assume that PARI variable nf contains a number field
644             $a = PARI('nf[7]');
645             $b = $nf->[6];
646
647           Now $a and $b contain the same value.
648
649       matrices
650           Note that "PARImat([[...],...,[...])" constructor creates a matrix
651           with specified columns, while in PARI the command "[1,2,3;4,5,6]"
652           creates a matrix with specified rows.  Use a convenience function
653           PARImat_tr() which will transpose a matrix created by PARImat() to
654           use the same order of elements as in PARI.
655
656       builtin perl functions
657           Some PARI functions, like "length" and "eval", are Perl
658           (semi-)reserved words.  To reach these functions, one should either
659           import them:
660
661             use Math::Pari qw(length eval);
662
663           or call them with prefix (like &length) or the full name (like
664           "Math::Pari::length").
665

High-resolution graphics

667       If you have Term::Gnuplot Perl module installed, you may use high-reso‐
668       lution graphic primitives of PARI.  Before the usage you need to estab‐
669       lish a link between Math::Pari and Term::Gnuplot by calling link_gnu‐
670       plot().  You can change the output filehandle by calling set_plot_fh(),
671       and output terminal by calling plotterm(), as in
672
673           use Math::Pari qw(:graphic asin);
674
675           open FH, '>out.tex' or die;
676           link_gnuplot();             # automatically loads Term::Gnuplot
677           set_plot_fh(\*FH);
678           plotterm('emtex');
679           ploth($x, .5, .999, sub {asin $x});
680           close FH or die;
681

libPARI documentation

683       libPARI documentation is included, see Math::libPARI.  It is converted
684       from Chapter 3 of PARI/GP documentation by the gphelp script of
685       GP/PARI.
686

ENVIRONMENT

688       No environment variables are used.
689

BUGS

691       ·    A few of PARI functions are available indirectly only.
692
693       ·    Using overloading constants with the Perl versions below 5.005_57
694            could lead to segfaults (at least without "-D usemymalloc"), as
695            in:
696
697              use Math::Pari ':int';
698              for ( $i = 0; $i < 10 ; $i++ ) { print "$i\n" }
699
700       ·    It may be possible that conversion of a Perl value which has both
701            the integer slot and the floating slot set may create a PARI inte‐
702            ger, even if the actual value is not an integer.
703
704       ·    problems with refcounting of array elements and Mod().
705
706            Workaround: make the modulus live longer than the result of Mod().
707            Until Perl version 5.6.1, one should exercise a special care so
708            that the modulus goes out of scope on a different statement than
709            the result:
710
711              { my $modulus = 125;
712                { my $res = Mod(34, $modulus);
713                  print $res;
714                }
715                $fake = 1;          # A (fake) statement here is required
716              }
717
718            Here $res is destructed before the "$fake = 1" statement, $modulus
719            is destructed before the first statement after the provided block.
720            However, if you remove the "$fake = 1" statement, both these vari‐
721            ables are destructed on the first statement after the provided
722            block (and in a wrong order!).
723
724            In 5.6.1 declaring $modulus before $res is all that is needed to
725            circumvent the same problem:
726
727              { my $modulus = 125;
728                my $res = Mod(34, $modulus);
729                print $res;
730              }                     # destruction will happen in a correct order.
731
732            Access to array elements may result in similar problems.  Hard to
733            fix since in PARI the data is not refcounted.
734
735       ·    Legacy implementations of dynalinking require the code of DLL to
736            be compiled to be "position independent" code (PIC).  This slows
737            down the execution, while allowing sharing the loaded copy of the
738            DLL between different processes.  [On contemeporary architectures
739            the same effect is allowed without the position-independent hack.]
740
741            Currently, PARI assembler files are not position-independent.
742            When compiled for the dynamic linking on legacy systems, this cre‐
743            ates a DLL which cannot be shared between processes.  Some legacy
744            systems are reported to recognize this situation, and load the DLL
745            as a non-shared module.  However, there may be systems (are
746            there?) on which this can cause some "problems".
747
748            Summary: if the dynaloading on your system requires some kind of
749            "-fPIC" flag, using "assembler" compiles (anything but
750            "machine=none") *may* force you to do a static build (i.e., cre‐
751            ation of a custom Perl executable with
752
753             perl Makefile.PL static
754             make perl
755             make test_static
756
757            ).
758

INITIALIZATION

760       When Math::Pari is loaded, it examines variables $Math::Pari::initmem
761       and $Math::Pari::initprimes.  They specify up to which number the ini‐
762       tial list of primes should be precalculated, and how large should be
763       the arena for PARI calculations (in bytes).  (These values have safe
764       defaults.)
765
766       Since setting these values before loading requires either a "BEGIN"
767       block, or postponing the loading ("use" vs. "require"), it may be more
768       convenient to set them via Math::PariInit:
769
770         use Math::PariInit qw( primes=12000000 stack=1e8 );
771
772       "use Math::PariInit" also accepts arbitrary Math::Pari import direc‐
773       tives, see Math::PariInit.
774
775       These values may be changed at runtime too, via allocatemem() and set‐
776       primelimit(), with performance penalties for recalculation/realloca‐
777       tion.
778

AUTHOR

780       Ilya Zakharevich, ilyaz@cpan.org
781
782
783
784perl v5.8.8                       2007-04-18                           Pari(3)
Impressum