Help to get started with the code of Maxima



Not quite.  The Maxima system is written in Lisp, but the Maxima language
is not the same as the Lisp language, though they are similar.  Maxima has
its own interpreter (eval function) and compiler (which compiles into Lisp
then uses the local Lisp compiler).  An important process which doesn't
exist in Lisp is "simplification".  Many things you might think are
"evaluation" are in fact simplification, e.g. the transformation of 2*3 =>
6.

Instead of an explanation, I'll give you a quick example using the "trace"
facility.  I hope this gives you some insight.

          -s

:lisp (trace $diff meval simplifya)          <<< set up function tracing
diff(x^2+1/2,x);           <<< user input

  0: (MEVAL (($DIFF) ((MPLUS) ((MEXPT) $X 2) ((MQUOTIENT) 1 2)) $X))
^^ Maxima parses the input into (($DIFF) ((MPLUS) ((MEXPT) $X 2)
((MQUOTIENT) 1 2)) $X) and called meval on it
    1: (MEVAL ((MPLUS) ((MEXPT) $X 2) ((MQUOTIENT) 1 2)))
^^ meval notices that $diff is a normal function (evaluates its arguments)
and so calls meval on each of its arguments
      2: (MEVAL ((MEXPT) $X 2))
        3: (MEVAL $X)
          4: (SIMPLIFYA $X NIL)
          4: SIMPLIFYA returned $X
        3: MEVAL returned $X
^^ note that (meval '$x) => $x   That is, unassigned variables are used as
symbolic variables
        3: (MEVAL 2)
          4: (SIMPLIFYA 2 NIL)
          4: SIMPLIFYA returned 2
        3: MEVAL returned 2
        3: (SIMPLIFYA ((MEXPT) $X 2) NIL)
          4: (SIMPLIFYA $X NIL)
          4: SIMPLIFYA returned $X
          4: (SIMPLIFYA 2 NIL)
          4: SIMPLIFYA returned 2
        3: SIMPLIFYA returned ((MEXPT SIMP) $X 2)
^^ the caar of a Maxima object is the operator; the cdar is a list of
'flags', in this case a flag indicating that the object is simplified
      2: MEVAL returned ((MEXPT SIMP) $X 2)
      2: (MEVAL ((MQUOTIENT) 1 2))
        3: (MEVAL 1)
          4: (SIMPLIFYA 1 NIL)
          4: SIMPLIFYA returned 1
        3: MEVAL returned 1
        3: (MEVAL 2)
          4: (SIMPLIFYA 2 NIL)
          4: SIMPLIFYA returned 2
        3: MEVAL returned 2
        3: (SIMPLIFYA ((MQUOTIENT) 1 2) NIL)
        3: SIMPLIFYA returned ((RAT SIMP) 1 2)
      2: MEVAL returned ((RAT SIMP) 1 2)
^^ simplified form of ((mquotient) 1 2) is ((rat simp) 1 2) (a rational
number); ((mquotient) x y) simplifies to ((mtimes simp) x ((mexpt simp) y
-1))
      2: (SIMPLIFYA ((MPLUS) ((MEXPT SIMP) $X 2) ((RAT SIMP) 1 2)) NIL)
        3: (SIMPLIFYA ((MEXPT SIMP) $X 2) NIL)
        3: SIMPLIFYA returned ((MEXPT SIMP) $X 2)
        3: (SIMPLIFYA ((RAT SIMP) 1 2) NIL)
        3: SIMPLIFYA returned ((RAT SIMP) 1 2)
      2: SIMPLIFYA returned ((MPLUS SIMP) ((RAT SIMP) 1 2) ((MEXPT SIMP) $X
2))
    1: MEVAL returned ((MPLUS SIMP) ((RAT SIMP) 1 2) ((MEXPT SIMP) $X 2))
^^ This is the evaluated/simplified form of x^2+1/2
    1: (MEVAL $X)
      2: (SIMPLIFYA $X NIL)
      2: SIMPLIFYA returned $X
    1: MEVAL returned $X
    1: ($DIFF ((MPLUS SIMP) ((RAT SIMP) 1 2) ((MEXPT SIMP) $X 2)) $X)
      2: (SIMPLIFYA ((MTIMES) 2 $X) T)
      2: SIMPLIFYA returned ((MTIMES SIMP) 2 $X)
      2: (SIMPLIFYA ((MPLUS) 0 ((MTIMES SIMP) 2 $X)) T)
^^ somewhere inside the diff process, diff(1/2,x) is found to be 0.
      2: SIMPLIFYA returned ((MTIMES SIMP) 2 $X)
^^ here, 2*x+0 => 2*x
    1: $DIFF returned ((MTIMES SIMP) 2 $X)
    1: (SIMPLIFYA ((MTIMES SIMP) 2 $X) NIL)
    1: SIMPLIFYA returned ((MTIMES SIMP) 2 $X)
  0: MEVAL returned ((MTIMES SIMP) 2 $X)
(%o14) 2*x


On Mon, Jun 24, 2013 at 7:02 PM, Samuel L? <samuel.le at gmail.com> wrote:

> Hi!
>
> I'd like to start playing with Maxima's code. I suppose the maxima's
> software is organized as follow:
> 1. the maxima prompt takes the input from the user
> 2. it is passed to a lisp function that translates it into some LISP sexpr
> ( something like "derivative (x^2,x);"  -> (some-function-for-derivative
> '(^x 2) 'x) )
> 3. it is evaluated (i.e (* 2 x))
> 4. it is translated back into standard notation  (i.e "2*x") and passed
> back to the prompt.
>
> Please correct me if I am wrong. Now, what I'd like to do is to call the
> maths functions directly from Common Lisp (i.e access directly to
> "some-function-for-derivative" in my example). Is it possible to do so?
>
> Many thanks,
> Sam
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>