Re: Algebraic Expression Simplification



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 s-exprs?

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 -(k-3)*(k-2)*(k-1)*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 (to-maxima) to restart, ($quit) to quit Maxima.

MAXIMA> (dolist (expr (list #$x^2+4*x+2$ #$x^2-2*x+1$ )) (displa expr) (terpri))
2
x + 4 x + 2

2
x - 2 x + 1

NIL
MAXIMA> (to-maxima)
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
.



Relevant Pages

  • Re: Is Xlisp-Stat Dead?
    ... Well, I wonder if you have looked at Maxima, a computer algebra ... it is easy to drop into Lisp ... making a start on assembling quality numerics libraries. ... If/when you have some CL libraries to release, ...
    (comp.lang.lisp)
  • Re: Errors when using Maxima code
    ... called "Sin" (it was published by Moses in 1967). ... Is the Lisp of Maxima different from the ANSI ... Common Lisp I use and how can I reconcile the differences? ...
    (comp.lang.lisp)
  • Re: performance and eloquence
    ... Maxima and Macsyma of which I both have and use have composed their entire ... user interface using basically a custom reader as far as I can tell. ... but then it wouldn't be lisp, ... I am not saying that maxima should not be a source of knowledge, ...
    (comp.lang.lisp)
  • Re: How to embed Maxima in Common Lisp?
    ... how can I call Maxima from within a Lisp program? ... Then you can launch Clisp ... Now I'll create the saved image. ...
    (comp.lang.lisp)
  • maxima error in linux but not windows
    ... Operating System Microsoft Windows XP Professional ... System Memory 512 MB ... Maxima 5.13.0 http://maxima.sourceforge.net ... Using Lisp GNU Common Lisp GCL 2.6.8 ...
    (sci.math.symbolic)