On Nov 21, 2007 10:03 AM, Bill Allombert
<[EMAIL PROTECTED]> wrote:
> On Wed, Nov 21, 2007 at 09:14:51AM -0800, William Stein wrote:
> > On Nov 20, 2007 12:44 PM, Anton Mellit <[EMAIL PROTECTED]> wrote:
> > > Sorry, I overlooked the question and only saw it now.
> > > >
> > > > What are you using to link Python and Pari's C?
> > > >
> > > In pari there is a special database (in the 'desc' directory of the
> > > source distribution) of all functions that are exposed to the
> > > interpreter. So I use a perl script that for each function in the list
> > > generates a python function using certain conventions for transforming
>
> Actually if you install pari, the database ins installed as well in
> $datadir/pari.desc (usually /usr/local/share/pari/pari.desc) and we provides
> a perl modules to parse it in $datadir/PARI/822.pm
> (but it is just RFC822-style format)
> So you do not need the pari source tree to run your script
> (though you are welcome to use src/desc/pari.desc and
> src/desc/PARI/822.pm if that suits you better).
>
>
> > > parameters. In pari there are several types of parameters and you need
> > > to handle them appropriately. The easiest cases are when parameter is
> > > a GEN or a long, so you don't need any special handling.
> > >
> > > I explain on the example of intnum. Pari's intnum is called as
> > > follows:
> > > intnum(t=0,1, t^2).
> > > So the actual C function takes 4 parameters. The first one is a
> > > 'variable', which has the type "entree". Then come two limits of
> > > integration, and finally a string which will be parsed later. So the
> > > function intnum sets the value of this entree and evaluates the string
> > > to get the value of the integrand at a certain point.
> > > In python the function is called like this:
> > > intnum(0,1,lambda t: t^2)
> > > My realization of intnum creates an empty entree, and as the string to
> > > evaluate it sends special string that contains a reference to this
> > > entree and a reference to the python function (which was given by
> > > lambda t: t^2). Also there is a way in PARI to override the parser
> > > which will parse a string. If you send a sequence of strings which
> > > starts with a certain character then my parser is called. So my parser
> > > simply extracts the references to the entree and to the function,
> > > reads the value from the entree and calls the functions with this
> > > value as the argument.
> >
> > Does this actually work, i.e., numerical integration
> > from the python interpreter via PARI?  And is it just as fast as
> > doing it from gp?   I remember quite awhile ago that I could
> > never get intnum to work reliably in C library mode, though
> > it worked from via the gp command line.
>
> I strongly suggest you use the libpari variant instead:
> GEN intnum(void *E, GEN (*eval)(GEN, void*), GEN a, GEN b, GEN tab, long prec)
> where you pass a C function instead as a string.
> This is especially important since in the PARI CVS version, the
> interface to the GP variant has completly changed. (there is no entree
> nor strings anymore).
> libpari variant are available for all similar routines (just drop the 0
> from intnum0, etc.)

Thanks for explaining this.

>
> > > So as soon you know what to do with each parameter type you simply
> > > 'import' all pari's function using a script.
> > >
> >
> > Thanks for the explanation.  Definitely your wrapping of PARI is much much
> > much different than what we do in Sage.   Ours is not automated, and indeed
> > we change some of the semantics (e.g., indexing is 0-based instead of 
> > 1-based)
> > and some function even behave differently, e.g., our factor routine always
> > gives answers provably correctly unlike PARI's.
>
> PARI CVS version factor routine actually can check primality now.
> (default(factor_proven,1))

Excellent!  But it might be a long time until that is in Sage, though
of course I really really
hope you guys will release a new stable version of PARI with that
functionality.  (Hint hint)


>
> > Another interesting aspect
> > of our approach is that if you do, e.g.,
> >
> >    >>> pari(2**997 - 1).factor()
> >
> > you can hit control-c to escape out of it at any point.  Also, with our 
> > wrapper
> > if pari runs out of memory doing a step of a calculation it will
> > automatically double
> > the stack and redo the calculation.  It also copies all results of 
> > calculations
> > out of the pari stack into the Python heap, so that Python's memory 
> > management
> > is used to deal with (reference counted) garbage collection.
> >
> > Currently when an error occurs in PARI the PARI C library calls sigint and 
> > Sage
>
> Actually it does not: The SAGE version is patched so that it calls abort
> which report a SIGABRT (instead of exit()).

Sorry, I certainly meant "SIGABRT" rather than SIGINT.  Otherwise it's as I say.

 -- William

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-forum
URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to