[SciPy-user] evaluating a really long, multiline expression

Noel O'Boyle noel.oboyle2 at mail.dcu.ie
Thu Nov 24 03:20:32 CST 2005


On Wed, 2005-11-23 at 16:37 -0500, Ryan Krauss wrote:
> I have a really long symbolic expression that is being generated by
> Maxima and output to a text file.  I need to turn this into a python
> function that I will use in optimize.newton and optimize.fmin.  It is
> almost 9000 lines and the first 10 lines look like this :
> 
> bv3 = (s^5*(abeam^2*betabeam^2*c3beam
> 		   *(ml2*(rl2*(Kact*kj2
> 				   *(ml1
> 				    *((ml0
> 				     *(2*kbase*Lbeam*Ll0*rl0
> 				      -2*kbase*Lbeam*rl0^2)
> 				     -2*Izl0*kbase*Lbeam-2*cbase*cj1*Lbeam)
> 				     *rl1^2
> 				     +Ll1
> 				      *((ml0
> 				       *(2*kbase*Lbeam*rl0^2
> 					-2*kbase*Lbeam*Ll0*rl0)
> 				       +2*Izl0*kbase*Lbeam+2*cbase*cj1*Lbeam)
> 
> Aside from replacing the ^ with ** and needing to get rid of the
> un-python-ish spacing at the front,

I don't think you need to get rid of the spacing, as it's all within a
bracket (implicit continuation of lines -- only the start of the
expression needs to be indented correctly).


>  any thoughts on how to make python
> evalute this expression quickly (assuming that all the variables are
> assigned numeric values by the function).  I am a little nervous that
> such a long expression will take a really long time to evaluate.  But
> I haven't tried it yet.  Any thoughts on parsing this thing?  am I
> better off leaving it a 9000 line statement or making one really long
> line (I think about 300,000 characters)?  Is there any speed trade off
> with multiline commands?
> 
> Ryan
> 
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user



More information about the SciPy-user mailing list