ANNOUNCE: PySymbolic - Doing Symbolics in Python

Pearu Peterson pearu at ioc.ee
Thu Oct 12 08:29:40 EDT 2000


On Wed, 11 Oct 2000, Huaiyu Zhu wrote:

> On Wed, 11 Oct 2000 15:43:22 GMT, Victor S. Miller <victor at idaccr.org> wrote:
> >
> I just glanced over their pages.  They both claim to be computational
> number-theory packages, which doesn't sound like they will have any calculus
> stuff.  I checked GiNaC again.  It has symbolic differentiation, but no
> symbolic integration, either.  

Symbolic differentation is not difficult to implement in Python. Check out
what I did a year ago:

	http://cens.ioc.ee/~pearu/misc/symbolic.py

It is raw but works for arbitrary python expressions; even differentation
of abstract functions are handled.

> Are there better candidate packages?

I have checked out many packages from 

	http://sal.kachinatech.com/A/1/index.shtml

Most of them provide interactive interfaces but not low-level interfaces.
(if I have overlooked something, please complain).

I have also made an interface to Maxima. See

	http://cens.ioc.ee/~pearu/misc/maxima/

It uses `expect' for communicating Maxima interactive session. Similar
interfaces could be written also for Maple, Mathematica etc.
But eventually, I thought that a symbolic package for Python should not
depend on commercial products. And Maxima was not good enough (actually
it started to crash in my computer;)  

> Considering the existence of many low level packages, we might want to ask
> ourselves the question: what do we want the expressions look like in Python
> eventually? Maple? Mathematica? Or something completely different?

I would say that they should look like in Python. 
Internally, the expressions can be lisp-like objects that can be generated
with standard Python module `parser'. I believe that most symbolic
packages are written in lisp-like languages, and there must be a good
reason for that.

In PySymbolic, Parser.py is an interface to the module `parser'. It just
generates more compact and readable lisp-like Python lists.

Here follows a simple session with the latest PySymbolic
(get it from http://cens.ioc.ee/~pearu/misc/PySymbolic.tgz):

Python 1.5.2 (#8, Apr 20 2000, 12:39:28)  [GCC egcs-2.91.66 19990314/Linux 
(egcs- on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from Symbolic import Symbolic
>>> x=Symbolic("x")
>>> y = x/2 + 4 + 5*x - "2/3*x"
>>> y
<Symbolic.Symbolic instance at 80b2860>
>>> print y
(((x / 2) + 4) + (5 * x)) + (-2 / 3 * x)
>>> print y.simplify()
4 + 29 * x / 6
>>> 

In addition, I am thinking of the following syntax examples in Python:
	Diff(x*x,x)
	Integrate(a*x,x=[c,d])
	Limit(1/x,x=0)
	Factor(x**2-4*a**2,x)
	Sum(i**2,i=[2,N])
	Substitute(x*a+2,a=5) # or Subs(..)
	Expand(<expr>)
	Collect(<expr>)
	Simplify(<expr>)
	...

It is not possible to get this kind of a look for Python and it
looks pretty good to me.

However, the problem of finding a good CAS library that could be
interfaced to Python and doing difficult tasks such as factorization,
integration etc, remains.

Regards,
	Pearu





More information about the Python-list mailing list