how to print algebraic expressions as an S-expression which is valid CL code
Subject: how to print algebraic expressions as an S-expression which is valid CL code
From: Tamas K Papp
Date: Sat, 11 Apr 2009 15:45:44 +0000 (UTC)
Hi,
How can I print algebraic expressions as an S-expression which is
valid Common Lisp code? For example,
eq1: 1-rho*chi*(mu-1)=lw*beta*mu+q;
eq2: q=lf*(1-beta)*mu;
eq3: chi*(mu+1)=beta*mu+1-q;
sol:solve([eq1, eq2, eq3], [mu,q,beta]);
rhs(sol[1][1]); /* how to emit this as an S-expression? */
gives
(chi lf + chi) rho + (1 - chi) lw + chi lf + 1
-------------------------------------------------
(chi lf + chi) rho + (lf + chi) lw + (1 - chi) lf
and I would like to have
(/ (+ (* (+ (* chi lf) chi) rho) ...
which I could just copy-paste into my Lisp program.
Thanks,
Tamas