[Maxima] Help calling maxima functions from lisp

Barton Willis willisb at unk.edu
Tue Feb 12 15:18:27 CST 2008

```Maybe some of what you need can be done with subst:

(%i4) subst('pow,"^", x^7);
(%o4) pow(x,7)

(%i5) subst('pow,"^",  a^(b+c));
(%o5) pow(a,c+b)

The other way (two steps):

(#1) Type your lambda form into Maxima and print it with ?print:

(%i1) lambda([xx],
if mapatom(xx) or op(xx) # "^" then xx
else pow(args(xx)[1], args(xx)[2]))\$

(%i2) ?print(%);
((LAMBDA SIMP) ((MLIST) \$XX)
((MCOND) ((MOR) ((\$MAPATOM) \$XX) ((MNOTEQUAL) ((\$OP) \$XX) "^")) \$XX T
((\$POW) ((MQAPPLY ARRAY) ((\$ARGS) \$XX) 1)
((MQAPPLY ARRAY) ((\$ARGS) \$XX) 2))))
(%o2) lambda([xx],if mapatom(xx) or op(xx)#^ then xx else
pow((args(xx))[1],(args(xx))[2]))

(#2) Test it

(%i3) to_lisp();
Type (to-maxima) to restart, (\$quit) to quit Maxima.

MAXIMA> (setf f `((LAMBDA SIMP) ((MLIST) \$XX) ((MCOND) ((MOR) ((\$MAPATOM)
\$XX) ((MNOTEQUAL)
((\$OP) \$XX) "^")) \$XX T  ((\$POW) ((MQAPPLY ARRAY) ((\$ARGS) \$XX) 1)
((MQAPPLY ARRAY)
((\$ARGS) \$XX) 2)))) ))
((LAMBDA SIMP) ((MLIST) \$XX)
((MCOND) ((MOR) ((\$MAPATOM) \$XX) ((MNOTEQUAL) ((\$OP) \$XX) "^")) \$XX T
((\$POW) ((MQAPPLY ARRAY) ((\$ARGS) \$XX) 1)
((MQAPPLY ARRAY) ((\$ARGS) \$XX) 2))))

MAXIMA> (mfuncall '\$scanmap f 'a)
A

MAXIMA> (mfuncall '\$scanmap f `((mplus) a b))
((MPLUS SIMP) A B)

MAXIMA> (mfuncall '\$scanmap f `((mtimes) a a a))
((\$POW SIMP) A 3)

Or something like that...

Barton

-----maxima-bounces at math.utexas.edu wrote: -----

>To: maxima at math.utexas.edu
>From: "Daniel Cabrini Hauagge" <daniel.hauagge at gmail.com>
>Sent by: maxima-bounces at math.utexas.edu
>Date: 02/12/2008 02:12PM
>Subject: [Maxima] Help calling maxima functions from lisp
>
>Hello,
>
>I'm trying to adapt f90.lisp to print out C code. I think that I got
>the easiest parts done already but I'm
>stuck trying to call scanmap from lisp. I've tried to do it like this
>
>(setq l (mfuncall '\$scanmap (mfuncal '\$lambda [x] x) l))
>
>and
>
>(setq l (\$scanmap (\$lambda [x] x) l))
>
>and got these errors
>
>EVAL: undefined function MFUNCAL
>EVAL: undefined function \$SCANMAP
>
>What I'm trying to do is get this into lisp
>
>  exp_trans: scanmap(lambda([xx],
>      if mapatom(xx) or op(xx) # "^" then xx
>      else pow(args(xx)[1], args(xx)[2])), exp);
>
>I searched the source code to see if there are any examples of such
>call but couldn't find any. If anybody knows
>how to do this or has suggestions for better ways of doing please let me
>know.
>
>--
>Daniel Cabrini Hauagge
>
>email: daniel.hauagge at gmail.com
>cel: +55 (19) 8194-8480
>_______________________________________________
>Maxima mailing list
>Maxima at math.utexas.edu
>http://www.math.utexas.edu/mailman/listinfo/maxima
```