Ask for the syntax of representing operators in Common-Lisp
Subject: Ask for the syntax of representing operators in Common-Lisp
From: Robert Dodier
Date: Tue, 11 Jul 2006 21:50:40 -0600
Daniel,
> It seems that translate and translate_file are intended to take maxima
> code and produce lisp code that is equivalent to the maxima code. What
> I was hoping for was something closer to what the "fortran" function
> does. Consider a maxima expression as a mathematical expression and
> convert it to the straightforward common lisp expression.
Here is a half-hearted attempt.
(%i2) cl(e) := if atom(e) then e else buildq([o:op(e), a:map (cl,
args(e))], (o, splice(a)));
(%o2) cl(e) := if atom(e) then e else buildq([o : op(e),
a : map(cl, args(e))], (o, splice(a)))
(%i3) cl ((a*x^2 + b*x + c)/sin(x));
(%o3) (//, (+, (*, a, (^, x, 2)), (*, b, x), c), (sin, x))
(%i4) cl (expand ((x + y)^3));
(%o4) (+, (^, y, 3), (*, 3, x, (^, y, 2)), (*, 3, (^, x, 2), y), (^, x, 3))
(1) Need to omit commas in displayed stuff. Modification of
dimension-list in src/displa.lisp can change that.
(2) Some Maxima operators aren't named the same as the
corresponding Lisp operators, e.g. op(a/b) => // which is
a bug, and there are probably others which are not bugs.
(3) cl as shown above doesn't do anything useful with lists,
lambdas, or function definitions.
If there's interest maybe we can think about how to beef up
this cl function, or come up with some different solution.
HTH
Robert