SourceForge.net Logo

PyGiNaC - Python Interface to GiNaC

Introduction

PyGiNaC is a Python package that provides an interface to the C++ library GiNaC, which is an open framework for symbolic computation within C++. PyGiNaC is implemented with the help of the Boost.Python library. At the moment, the package is more or less in an "alpha" state, i.e. the GiNaC classes are only partially exposed, parts of regression test suite are unconverted and no actual documentation exists. However, all of this is supposed to change in the future.

The current implementation of PyGiNaC has, up to our knowledge, two predecessors: a version written by Pearu Peterson some years ago, and another one by Ondrej Certik.

Despite of being not-so-complete, PyGiNaC can do some fancy stuff for you. For example, solving a linear system of equations in the Python intepreter can be as simple as

>>> x = symbol('x')
>>> y = symbol('y')
>>> lsolve([3*x + 5*y == 2, 5*x+y == -3], [x,y])
[<cginac.relational object at 0xb7de61bc>, <cginac.relational object at 0xb7de648c>]
>>> [str(x) for x in lsolve([3*x + 5*y == 2, 5*x+y == -3], [x,y])]
['x==-17/22', 'y==19/22']
>>> 

Power series of functions are also handled

>>> x = symbol('x')
>>> print sin(x).series(x==0, 8)
1*x+(-1/6)*x**3+1/120*x**5+(-1/5040)*x**7+Order(x**8)
>>> 

Or try a modified version of one of Ramanujan's identities (this example is ripped off from GiNaC's regression test suite)

>>> e1 = pow(1 + pow(3,numeric(1,5)) - pow(3,numeric(2,5)),3)
>>> e2 = expand(e1 - 10 + 5*pow(3,numeric(3,5)))
>>> print e2.expand()
0
>>> 
Above numeric(3,5) is a fraction 3/5.

Download

At the moment there are no released tarballs of PyGiNaC. Instead, it can be downloaded directly from the CVS repository at SourceForge. To do a CVS checkout, issue the following commands

cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/pyginac login
 
cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/pyginac co -P pyginac
Or, you can, of course, browse the CVS.

Compiling and running

To run PyGiNaC you need to have the following software installed:

  • python (preferably 2.3)
  • the boost libraries (1.31.0 or higher)
  • GiNaC (1.3.2 or higher)

    In addition to the above, to compile PyGiNaC the following are needed

  • scons
  • GNU g++ (3.2 or higher, preferably 3.3) Compiling PyGiNaC takes a lot of memory, although generally not as much is needed to run it.

    Once you have all the dependencies listed above installed, issue the command "scons". This will build the module in-place. An install target is not yet supported. Instead, the script "run" can be used to start an interactive Python session that will be able to use PyGiNaC by

    $ ./run python2.3
    
    or, to run a Python script
    $ ./run python2.3 some_script_file.py
    

    That's it. Have fun. :) In case of any trouble, see the mailing list below.

    Mailing list

    There is a single PyGiNaC mailing list, pyginac-users(at)lists.sourceforge.net. Since there are not separate development and/or bug reporting lists, any kind of discussion related to PyGiNaC is welcome, including suggestions and bug reports. There are also archives to browse.

    TODO

    The following are ongoing projects.

  • Wrap more of GiNaC classes and objects.
  • Pythonize the GiNaC regression tests.
  • Create a map_function system, probably based on Python function objects.
  • Add extra member access functions for higher-level access of containerish types, like power.basis() and power.exponent(), for example.
  • Make every function capable of taking more than one argument also take arguments in keyword form.
  • Prepare some documention with examples written in Python instead of ginsh or C++.

    Contributors

    PyGiNaC is originally written by Jonathan Brandmeyer and later co-authored by Matti Peltomäki. Patches have been submitted by Ondrej Certik.

    Some more information can also be found on the SF.net project page.