ANNOUNCE: PySymbolic - Doing Symbolics in Python

Huaiyu Zhu hzhu at yahoo.com
Thu Oct 12 20:22:35 EDT 2000


On Thu, 12 Oct 2000 14:29:40 +0200, Pearu Peterson <pearu at ioc.ee> wrote:
>
>	http://cens.ioc.ee/~pearu/misc/symbolic.py
>
It does not run, for some reason.

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

This looks good, but unfortunately it does not run on my machine, either.

>>> from Symbolic import Symbolic 
>>> x = Symbolic ('x')
>>> x+1
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: __add__ nor __radd__ defined for these operands
  
>
>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.

Yes, this looks good.  I'd suggest using lower case letters, though.

Huaiyu



More information about the Python-list mailing list