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.
The module interfaces to most of the functions available in GP,
by parsing the file ${prefix}/share/pari/pari.desc
,
see modules/pari/desc2lisp.lisp
.
Lisp functions are normally named the same as the GP functions they correspond to or the PARI functions they call, e.g.:
para:quadpoly
corresponds to the
eponymous GP function and calls the quadpoly0
PARI functionpara:issmall
calls the PARI
function issmall
which has no GP
analoguepara:random_
(note the
_
suffix to avoid clash with the [ANSI CL standard] RANDOM
)
corresponds to the GP function random
and calls the
genrand
PARI function.
Not all PARI functions have a corresponding Lisp function, but one can 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 interfaced to by the module.)
Please feel free to submit additions for
modules/pari/pari.lisp
and modules/pari/test.tst
.
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:Pi)))) ⇒23
One can also pass the precision parameter explicitly:
(LENGTH
(PRIN1-TO-STRING
(pari:pari-to-lisp (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
(
(64 bits or 32 bits).FFI:BITSIZEOF
'ffi:ulong)
These notes document CLISP version 2.49.93+ | Last modified: 2018-02-19 |