PyGiNaC - Python Interface to GiNaC


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)

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()
Above numeric(3,5) is a fraction 3/5.


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 login
cvs -z3 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

    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) 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.


    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++.


    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 project page.