ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 13 Nov 2013 17:25:45 +0100help with a maxima functionhttps://ask.sagemath.org/question/10732/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
Wed, 13 Nov 2013 16:49:04 +0100https://ask.sagemath.org/question/10732/help-with-a-maxima-function/Comment by kcrisman for <p>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:</p>
<pre><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]))));
</code></pre>
<p>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:</p>
<pre><code>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)
</code></pre>
<p>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:</p>
<p>with_stdout ("maxima_bode0.f", fortran_optimize (bode0))</p>
<p>Thanks,</p>
<p>Ryan</p>
https://ask.sagemath.org/question/10732/help-with-a-maxima-function/?comment=16710#post-id-16710Just 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).Wed, 13 Nov 2013 17:25:45 +0100https://ask.sagemath.org/question/10732/help-with-a-maxima-function/?comment=16710#post-id-16710