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
21       numerical/scientific/number-theoretic calculations.  It allows use of
22       most PARI functions as Perl functions, and (almost) seamless merging of
23       PARI and Perl data. In what follows we suppose prior knowledge of what
24       PARI is (see ftp://megrez.math.u-bordeaux.fr/pub/pari
25       <ftp://megrez.math.u-bordeaux.fr/pub/pari>, or Math::libPARI).
26

EXPORTed functions

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

Available functions

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

PARI objects

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

PARI monomials and Perl barewords

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

Overloading and automatic conversion

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

PREREQUISITES

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

Perl vs. PARI: different syntax

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

High-resolution graphics

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

libPARI documentation

680       libPARI documentation is included, see Math::libPARI.  It is converted
681       from Chapter 3 of PARI/GP documentation by the gphelp script of
682       GP/PARI.
683

ENVIRONMENT

685       No environment variables are used.
686

BUGS

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

INITIALIZATION

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

AUTHOR

777       Ilya Zakharevich, ilyaz@cpan.org
778
779
780
781perl v5.12.1                      2009-12-12                           Pari(3)
Impressum