# help with a maxima function

I have a number of maxima batch files (*.mac) for doing symbolic matrix work. I can sort of batch these in sage by calling maxima(line) for each line in the file. When I am done, I want to dump the results to a text file that I can convert to valid fortran code or code for numeric python evaluation using numpy and friends. Someone on the Maxima mailing list wrote a function for me for converting a Maxima expression to fortran code while collecting common sub expressions. However, I don't seem to be able to get this code to work with maxima. Here is the Maxima code:

```
optimprefix : 'a_ ; /* 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 (apply ("=", ['RESULT, 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]))));
```

It is in my ~/.maxima/maxima-init.mac file and sage seems to load this file. I say that because under my tab completion options, I have a maxima.fortran_optimize. But the function doesn't do anything:

```
sage: a, b = var('a','b')
sage: a,b,c = var('a','b','c')
sage: d = a^3+b*c*a^5
sage: maxima.fortran_optimize(d)
fortran_optimize(a^5*b*c+a^3)
```

Is there something else I need to do to get maxima to recognize this function from the sage maxima interface? Does the function need to be altered to get it to return the lines of fortran code? FYI, my maxima batch files end in lines like this for dumping the results to a file:

with_stdout ("maxima_bode0.f", fortran_optimize (bode0))

Thanks,

Ryan

Just a total guess - is there something you need to do to get this to *compile* Fortran? Or is there something pre-compiled that is being used here? I don't see any actual Fortran code hidden in here... (or are you just looking for it to dump out Fortran code for use elsewhere? sorry for not understanding).