Subject: denominator of really complicated expression
From: Ryan Krauss
Date: Wed, 23 Nov 2005 20:20:53 -0500
Thanks Robert. That is helpful and very much in the right direction.
I am in the middle of learnign f2py which may allow me to do all this
fairly cleanly (i.e. take the fortran output of maxima and create a
python module from it).
My request about optimize may aid my using the output directly in a
python program without having to compile it as fortran first.
Ryan
On 11/23/05, Robert Dodier wrote:
> On 11/23/05, Ryan Krauss wrote:
>
> > 1. Is there a way to do something like the optimize command and
> > combined it with stringout?
>
> > 2. How do I get the output of the fortran command to dump to a file
> > instead of just printing to the screen?
>
> Well, about (1), how about this ---
>
> optimprefix : '_ ; /* default is %, which isn't OK for python variables */
>
> fortran_optimize (e) := block ([o : optimize (e)],
> if atom (o) or op (o) # 'block then fortran (e)
> else block ([a : args (o)],
> for x in rest(a) do
> if atom (x) then print ("Hey, whence this atom", x, "??")
> else if op (x )= ":" then fortran (apply ("=", args(x)))
> else fortran (apply ("=", ['RESULT, x]))));
>
> Applied to 4*x^2*%e^(y+x^2)/(y+x)+2*%e^(y+x^2)/(y+x)-4*x*%e^(y+x^2)/(y+x)^2+2*%e^(y+x^2)/(y+x)^3
> I get
>
> _1 = y+x
> _2 = x**2
> _3 = exp(y+_2)
> _4 = 1/_1
> RESULT = 4*_2*_4*_3+2*_4*_3-4*x*_3/_1**2+2*_3/_1**3
>
> I put fortran in there since its output is closer to Python.
>
> About (2), you want with_stdout ---
>
> with_stdout ("/tmp/foo.fortran", fortran_optimize (foo));
>
>
> Hope this is headed in the right direction here ---
>
> Robert Dodier
>