Fwd: expression parse tree API?



Sorry, I forgot to CC the list on this.

---------- Forwarded message ----------
From: Stavros Macrakis <macrakis at alum.mit.edu>
Date: Nov 26, 2006 7:42 PM
Subject: Re: [Maxima] expression parse tree API?
To: Jurgis Pralgauskis <jurgpral at soften.ktu.lt>


On 11/26/06, Jurgis Pralgauskis <jurgpral at soften.ktu.lt> wrote:
> could smb point me how to access the formula parse tree.

The internal form of Maxima expressions is a Lisp s-expression, which
you can see using the ?print function.  For example,

         sin(x)/x-x-1

is represented as

        ((MPLUS SIMP) -1
                                    ((MTIMES SIMP) -1 $X)
                                    ((MTIMES SIMP) ((MEXPT SIMP) $X -1)
                                    ((%SIN SIMP) $X)))

There are a few salient points here:

  -- op(a) is represented as ((OP ...) a) The ... are various flags,
most commonly SIMP indicating that the expression has already been
simplified.
  -- x/y is represented as x*y^-1
  -- -x is represented as -1*x
  -- there is a canonical ordering of terms in simplified expressions

You can also access the operator and operands using the OP and ARGS
functions in Maxima itself.  These normally reflect the *external*
form of the expression, so op(-x)=> - (not *).  To see the internal
forms, set inflag:true.

              -s