33.11. Computer Algebra System PARI

This package offers an FFI-based interface to PARI.

The package PARI is :CASE-SENSITIVE.

When this module is present, *FEATURES* contains the symbol :PARI.

PARI objects are printed and read using a special #Z"" syntax.

Most functions accept lisp objects as well as PARI objects and return PARI objects, which can be converted to lisp using the pari:pari-to-lisp function.

See modules/pari/test.tst for sample usage.

Extending the module

Not all PARI functions have a corresponding lisp function yet, but one remedy that with just a few lines:

(FFI:DEFAULT-FOREIGN-LIBRARY "libpari.so") ; or pari.dll on Win32
(pari:pari-call-out (matrix-rank ffi:long) "rank" (x))long rank(GEN x);
(pari:pari-call-out fibonacci "fibo" ((n ffi:long)))GEN fibo(long n);
(pari:pari-call-out-prec pari-arctan "gatan" (x))GEN gatan(GEN x, long prec);
(pari:pari-call-out (equal? boolean) "gequal" (x y))GEN gequal(GEN x, GEN y);

(Actually, these four functions are already present in the module.) Please feel free to submit additions for modules/pari/pari.lisp and modules/pari/test.tst.

Real precision

The real precision defaults to pari:pari-real-precision which specifies the default precision in decimal digits:

pari:pari-real-precision
⇒ 19
(LENGTH (PRIN1-TO-STRING (pari:pari-to-lisp (pari:pari-pi))))
⇒ 23

One can also pass the precision parameter explicitly:

(LENGTH (PRIN1-TO-STRING (pari:pari-to-lisp (pari:pari-pi :prec 38))))
⇒ 41

Note that the actual precision is determined by the size of the mantissa which can be incremented only in steps of (FFI:BITSIZEOF 'ffi:ulong) (64 bits or 32 bits).


These notes document CLISP version 2.49Last modified: 2010-07-07