Different stuff

October 28, 2007

Pari – Python

Filed under: Uncategorized — Anton @ 5:17 pm
Tags: , , , ,

I finished some working version of the pari-python module. I tried to make it is close as possible to the standard PARI shell, at the same time using the standard python syntax. Here I put some screenshots. I didn’t make a proper package distribution for python (the code still looks ugly and I still don’t know how to make proper distributions), but if someone is interested to test it send me an email. This is in early alpha stage. A lot of things are not working. I imported almost all functions of gp by an automated perl script but I don’t know which of them actually work and which not.


There are two special difficulties you may notice about python. The first one is the power operation. In python it is ‘**’, whereas ‘^’ is reserved for the bitwise xor. I made some little changes to the python source so that ‘^’ and ‘^=’ now work as power, and ‘^^’ and ‘^^=’ work as xor if you still want to use it. This is done by modifying about 30 lines of source code in several files: Include/token.h, Modules/parsermodule.c, Parser/tokenizer.c, Python/ast.c, Grammar/Grammar.

The second difficulty is that expressions like ’1/2′ produce 0 in python. For this my module installes my own handler for the operation ‘divide’ for integers and longs. That’s it. In other respects it is a normal python module.

Please, any comments are welcome. Here are the screenshots. This is an example session:pari-python1.jpg

This is an example of using the ‘help(pari)’ command:

pari-python2.jpg

About these ads

4 Comments »

  1. [...] The only thing that I not-so-like in PARI is its programming abilities. I think it is better to use some carefully designed standard scripting language for programming. That’s why I am working on integration of PARI with Python. This is still work in progress (look at some screenshots here). [...]

    Pingback by Tricks using PARI « Vivatsgasse 7 — November 10, 2007 @ 12:40 pm | Reply

  2. I once spent some effort to write a pari-python wrapper. Actually, there is an old floating around on the web

    http://www.fermigier.com/fermigier/PariPython/readme.html

    However, I gave it up once I learned about sage — http://sagemath.org — Sage is an effort to provide a fully featured cas with python as the principle language. I highly recommend it (Full disclosure: I help develop sage).

    Comment by Joel B. Mohler — December 14, 2007 @ 3:37 pm | Reply

  3. I have seen the project you mentioned. It is very incomplete. I already have a support of all PARI functions and I can work with my module without using the standard pari shell. I have just posted some links and an example on the blog.

    Comment by Anton — December 14, 2007 @ 5:35 pm | Reply

  4. About sage – to me it seems as ‘too heavy’ project. And I could not set it up on my computer (Windows).

    Comment by Anton — December 14, 2007 @ 5:37 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: