Re: Algebraic Expression Simplification
 From: pjb@xxxxxxxxxxxxxxxxx (Pascal J. Bourguignon)
 Date: Sat, 13 Sep 2008 17:09:51 +0200
wrf3@xxxxxxxxxxxxxxx (Bob Felts) writes:
Frank Buss <fb@xxxxxxxxxxxxx> wrote:
Bob Felts wrote:
Anyone have any pointers to code for simplifying algegraic expressions
expressed as sexprs?
No source code, but in compiled form. First a quick hack for converting the
prefix form to infix:
(defun p2i (exp)
(let ((op (car exp))
(rest (cdr exp)))
(format t "(")
(loop for term in rest
for first = t then nil do
(unless first
(format t "~a" op))
(if (atom term)
(format t "(~a)" term)
(p2i term)))
(format t ")")))
This gives the more readable term
(((((K)*((K)(1))*((K)(2))*((K)(3))*((K)(4)))/(120))((((((K)*((K)
(1))*((K)(2)))/(720)))*((((K)+(4))*((K)+(3)))/(2)))+((0)*((((K)+
(4))*((K)+(3))*((K)+(2)))/(6)))+(((K)/(12))*((((K)+(4))*((K)+(
3))*((K)+(2))*((K)+(1)))/(24)))+(((1)/(2))*((((K)+(4))*((K)+(3)
)*((K)+(2))*((K)+(1))*((K)+(0)))/(120)))+(((1)/((K)+(1)))*((((K)
+(4))*((K)+(3))*((K)+(2))*((K)+(1))*((K)+(0))*((K)+(1)))/(720)
))))/((K)+(4)))
Pasting it to Mathematica gives (k3)*(k2)*(k1)*k/720
Oh, rats. I copied the wrong one. I had already done that one by hand
and came up with the same results as Mathematica.
maxima says the same:
(%i16) (((((K)*((K)(1))*((K)(2))*((K)(3))*((K)(4)))/(120))((((((K)*((K)(1))*((K)(2)))/(720)))*((((K)+(4))*((K)+(3)))/(2)))+((0)*((((K)+(4))*((K)+(3))*((K)+(2)))/(6)))+(((K)/(12))*((((K)+(4))*((K)+(3))*((K)+(2))*((K)+(1)))/(24)))+(((1)/(2))*((((K)+(4))*((K)+(3))*((K)+(2))*((K)+(1))*((K)+(0)))/(120)))+(((1)/((K)+(1)))*((((K)+(4))*((K)+(3))*((K)+(2))*((K)+(1))*((K)+(0))*((K)+(1)))/(720)))))/((K)+(4)));
(K  3) (K  2) (K  1) K
(%o16)  
720
But there are two problems with this. First, I don't have Mathematica
and, if I'm going to spend that kind of money, I'd rather first get
Lispworks.
maxima works on free lisps.
Second, there are potentially thousands of these equations.
you can call lisp from maxima, or maxima from lisp.
(%i25) to_lisp();
Type (tomaxima) to restart, ($quit) to quit Maxima.
MAXIMA> (dolist (expr (list #$x^2+4*x+2$ #$x^22*x+1$ )) (displa expr) (terpri))
2
x + 4 x + 2
2
x  2 x + 1
NIL
MAXIMA> (tomaxima)
Returning to Maxima
(%o25) true
(%i26) quit();
Process maxima finished

__Pascal Bourguignon__ http://www.informatimago.com/
Until real software engineering is developed, the next best practice
is to develop with a dynamic system that has extreme late binding in
all aspects. The first system to really do this in an important way
is Lisp.  Alan Kay
.
 FollowUps:
 Re: Algebraic Expression Simplification
 From: Bob Felts
 Re: Algebraic Expression Simplification
 References:
 Algebraic Expression Simplification
 From: Bob Felts
 Re: Algebraic Expression Simplification
 From: Frank Buss
 Re: Algebraic Expression Simplification
 From: Bob Felts
 Algebraic Expression Simplification
 Prev by Date: Re: Algebraic Expression Simplification
 Next by Date: Re: Yet another redblack tree implementation.
 Previous by thread: Re: Algebraic Expression Simplification
 Next by thread: Re: Algebraic Expression Simplification
 Index(es):
Relevant Pages
