Karim BELABAS on Wed, 16 Apr 2003 14:27:16 +0200 (MEST)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Using PARI as a library


On Fri, 11 Apr 2003, Alberto Simões/EPL wrote:
> So, we were looking for a library which could do this for us. I
> downloaded Pari/GP, and it seems a brilliant application... but
> as I read (well, looked to it) the documentation, it seems not so
> easy like that to use Pari library.
>
> Can anybody point if it can be feasible, or should we adopt GP and
> only do a GUI frontend? (well... I would like to maintain my own
> language and parser...)

Using the PARI library for a full-blown CAS will require a lot of work.
Basically, it contains no symbolic manipulation routines, except some minimal
polynomial algebra and linear algebra, which is very inefficient with
symbolic entries or large dimensions. ( You could have a look at GiNaC
<http://www.ginac.de/>, but it looks like a lot of work too .)

The simplest approach will be to use GP. TeXmacs [ <http://www.texmacs.org>.
It's presented as a wysiwyg emacs + LaTeX combo, but it's also a good CAS
frontend. ] has a naive but quite robust approach. As a result it can operate
as a frontend to dozens of computer algebra systems, some of them distributed
as closed source binaries.


Specifically (parent = TeXmacs below):

* parent starts GP process in the background, as 'gp --texmacs' to enable
some extended input parsing, and special output conventions. Communication
operated via named pipes: parent writes commands on gp standard input, and
reads its standard output and error streams.

* all gp output (stdout or stderr) is surrounded by DATA_BEGIN / DATA_END
pairs, so that parent knows when gp is done, and that the output can be
processed.

The first token following DATA_BEGIN tells parent the format of the following
text, up to DATA_END. Formats are defined by TeXmacs; currently, gp makes use
of only three TeXmacs formats:

-- 'command': a Guile/Scheme expression. Used on startup to tell TeXmacs about
the extended interface capabilities of that particular CAS. In the case of GP,
that an interface to command completion is available, and upon actual
completion to return the list of matching routines.

-- 'verbatim': to be printed as is, without further processing (error messages,
diagnostics, etc).

-- 'latex': LaTeX code  (results)

* Anything written on gp stdin that doesn't start with DATA_BEGIN is
processed as usual, but a

   <DATA_BEGIN><command> ... <DATA_END>

sequence is understood as a Scheme command. GP does not include a
Guile/Scheme interpreter like TeXmacs does, but can process very restricted
kinds of commands. In fact, currently only <TAB> command completion requests.

None of this is documented, but I could expand it if there is interest.

The only problem in the current TeXmacs interface to GP is that GP doesn't
try to be clever with LaTeX output, and neither does TeXmacs. So that huge
data structure take a long time to be printed, basically to no avail. It is a
trivial fix on GP's side of the pipe: chose verbatim instead of LaTeX when
output is large.

There's some amount of redundant parsing and conversions between strings and
PARI GEN objects, that could be avoided by linking directly to the library
[ a preliminary version of the TeXmacs interface did this, using shared
libraries ], but the performances were basically the same and the coding
overhead much, much larger.

Cheers,

    Karim.
-- 
Karim Belabas                     Tel: (+33) (0)1 69 15 57 48
Dép. de Mathématiques, Bât. 425   Fax: (+33) (0)1 69 15 60 19
Université Paris-Sud              http://www.math.u-psud.fr/~belabas/
F-91405 Orsay (France)            http://www.parigp-home.de/  [PARI/GP]