symbolic computation, sort of
Greg Ewing (using news.cis.dfn.de)
me at privacy.net
Wed Mar 12 20:47:28 EST 2003
Mathew Yeates wrote:
> I want to feed the function
>
> def f(x):
> t = 2*x
> b = t+1
> return b
>
> to a tool and have it tell me that f(x) -> 2x+1
You could feed to f a special object which overloaded all the
arithmetic operations to build a symbolic expression tree.
What you got out would then represent all the operations
performed.
This would automatically expand any nested function calls.
It would only work if f and any functions called by it
contained only straight-line code -- no if-statements,
loops or anything like that.
You may also want to perform some simplifications on
the resulting expression. That can get tricky -- people
have written entire theses on subjects like that...
--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
More information about the Python-list
mailing list