[SciPy-user] symbolic strings

Travis Oliphant oliphant.travis at ieee.org
Fri Feb 3 12:08:33 CST 2006

Ryan Krauss wrote:

>I may be getting in over my head, but I think this can work.  I do a
>lot of analysis with matrices using the transfer matrix method.  
>Sometimes I want to do numeric work with them and sometimes I use
>python to generate an input script for Maxima.  Right now I have two
>methods for my transfer matrix element, one that outputs a numeric
>matrix and one that outputs a string for Maxima.  I am working on a
>new element and would like to combined these two expressions by
>creating a symbolic string method so that expressions like
>make sense whether L0, m1, r1, s, etc are floats or symstrs (my new
>class).  I overrode the __mul__, __add__, __div__,__sub__, and __pow__
>methods but don't know if there are methods to override to deal with
>the parenthesis and the unary - out in front.  Can this be done with
>only a little bit more work?  Basically I want the output of this
>expression to be 'a=-(L0*m1*r1*s**2-c1*s-k1)/(c1*s+k1)' if it is a
>string and a float or complex if the variables are numbers.
This can be done, but you would basically have to add the parenthesis in 
yourself as you build up your string...

Yes, the unary '-' can be over-written (see __neg__ special method). 


More information about the SciPy-user mailing list