1<?xml version="1.0" encoding="UTF-8"?>
2
3<section id="pari"><title>Computer Algebra System PARI</title>
4
5<para>This package offers an &ffi-pac;-based interface to &pari-link;.</para>
6<para>The package <quote role="package">PARI</quote>
7 is &case-sensitive-k;.</para>
8
9<simpara>When this module is present, &features-my; contains the
10 symbol <constant>:PARI</constant>.</simpara>
11
12<para>PARI objects are printed and read using a special
13 <literal role="data">#Z""</literal> syntax.</para>
14
15<para>Most functions accept lisp objects as well as PARI objects and
16return PARI objects, which can be converted to lisp using the
17<function>pari:pari-to-lisp</function> function.</para>
18
19<para>See <filename role="clisp-cvs">modules/pari/test.tst</filename>
20 for sample usage.</para>
21
22<simplesect id="pari-desc"><title>Available functionality</title>
23<para>The module interfaces to most of the functions available in GP,
24by parsing the file <filename>${prefix}/share/pari/pari.desc</filename>,
25see <filename role="clisp-cvs">modules/pari/desc2lisp.lisp</filename>.</para>
26<para>Lisp functions are normally named the same as the GP functions
27they correspond to or the PARI functions they call, e.g.: <itemizedlist>
28<listitem><simpara><function>para:quadpoly</function> corresponds to the
29eponymous GP function and calls the <function>quadpoly0</function>
30PARI function</simpara></listitem>
31<listitem><simpara><function>para:issmall</function> calls the PARI
32function <function>issmall</function> which has no GP
33analogue</simpara></listitem>
34<listitem><simpara><function>para:random_</function> (note the
35<literal>_</literal> suffix to avoid clash with the &ansi-cl; &random;)
36corresponds to the GP function <function>random</function> and calls the
37<function>genrand</function> PARI function.</simpara></listitem></itemizedlist>
38</para></simplesect>
39
40<simplesect id="pari-ext"><title>Extending the module</title>
41<para>Not all PARI functions have a corresponding Lisp function, but one can
42remedy that with just a few lines: <programlisting language="lisp">
43(&default-foreign-library; "libpari.so") ; or pari.dll on &win32;
44(pari:pari-call-out (matrix-rank ffi:long) "rank" (x))<lineannotation>long rank(GEN x);</lineannotation>
45(pari:pari-call-out fibonacci "fibo" ((n ffi:long)))<lineannotation>GEN fibo(long n);</lineannotation>
46(pari:pari-call-out-prec pari-arctan "gatan" (x))<lineannotation>GEN gatan(GEN x, long prec);</lineannotation>
47(pari:pari-call-out (equal? boolean) "gequal" (x y))<lineannotation>GEN gequal(GEN x, GEN y);</lineannotation>
48</programlisting>
49(Actually, these four functions are already interfaced to by the module.)
50Please feel free to submit additions for
51 <filename role="clisp-cvs">modules/pari/pari.lisp</filename>
52 and <filename role="clisp-cvs">modules/pari/test.tst</filename>.</para>
53</simplesect>
54
55<simplesect id="pari-prec"><title>Real precision</title>
56<para>The real precision defaults to <varname>pari:pari-real-precision</varname>
57which specifies the default precision in decimal digits:
58<programlisting language="lisp">
59pari:pari-real-precision
60<computeroutput>19</computeroutput>
61(&length; (&prin1-to-string; (pari:pari-to-lisp (pari:Pi))))
62<computeroutput>23</computeroutput>
63</programlisting>
64One can also pass the precision parameter explicitly:
65<programlisting language="lisp">
66(&length; (&prin1-to-string; (pari:pari-to-lisp (pari:Pi :prec 38))))
67<computeroutput>41</computeroutput>
68</programlisting>
69Note that the <emphasis>actual</emphasis> precision is determined by the
70size of the mantissa which can be incremented only in steps of
71<code>(&bitsizeof; 'ffi:ulong)</code> (64 bits or 32 bits).</para>
72</simplesect>
73</section>
74