maxima debug feature? - or how to accomplish same



Max,

You will of course have to learn Lisp if you want to understand how
Maxima works.

But you can get a flavor of various aspects of Maxima using the
following techniques:

* To see the internal representation of Maxima expressions as Lisp
expressions, use the ?print function
* To trace functions, you do not need a specially-compiled version of
the code -- you can trace them at any time using the ?trace function
(functions starting with ? are Lisp functions)
* To trace the general simplifier, you can use ?trace(?simplifya)
* To trace the evaluator, you can use ?trace(?meval1)

You will see from the example below that much of the work in Maxima
happens in the simplifier -- thus the transformation 5^2 -> 25 is not
evaluation, but simplification.

Hope this helps you get started.

               -s

(%i1) ?print((x^2-1)/(x+y))$
((MTIMES SIMP) ((MPLUS SIMP) -1 ((MEXPT SIMP) $X 2))
 ((MEXPT SIMP) ((MPLUS SIMP) $X $Y) -1))
(%i2) ?print(rat((x^2-1)/(x+y)))$
((MRAT SIMP ($X $Y) (#:X33340 #:Y33341)) (#:X33340 2 1 0 -1) #:Y33341 1
 1 0 (#:X33340 1 1))
(%i3) ?trace(?simplifya)$
  1> (SIMPLIFYA (SIMPLIFYA) NIL)
  <1 (SIMPLIFYA (SIMPLIFYA))
(%i4) 2*x/3;
  1> (SIMPLIFYA 2 NIL)
  <1 (SIMPLIFYA 2)
  1> (SIMPLIFYA $X NIL)
  <1 (SIMPLIFYA $X)
  1> (SIMPLIFYA ((MTIMES) 2 $X) NIL)
    2> (SIMPLIFYA 2 NIL)
    <2 (SIMPLIFYA 2)
    2> (SIMPLIFYA $X NIL)
    <2 (SIMPLIFYA $X)
  <1 (SIMPLIFYA ((MTIMES SIMP) 2 $X))
  1> (SIMPLIFYA 3 NIL)
  <1 (SIMPLIFYA 3)
  1> (SIMPLIFYA ((MQUOTIENT) ((MTIMES SIMP) 2 $X) 3) NIL)
    2> (SIMPLIFYA ((MTIMES SIMP) 2 $X) NIL)
    <2 (SIMPLIFYA ((MTIMES SIMP) 2 $X))
    2> (SIMPLIFYA ((MEXPT) 3 -1) NIL)
      3> (SIMPLIFYA 3 NIL)
      <3 (SIMPLIFYA 3)
      3> (SIMPLIFYA -1 NIL)
      <3 (SIMPLIFYA -1)
    <2 (SIMPLIFYA ((RAT SIMP) 1 3))
    2> (SIMPLIFYA ((MTIMES) ((MTIMES SIMP) 2 $X) ((RAT SIMP) 1 3)) T)
    <2 (SIMPLIFYA ((MTIMES SIMP) ((RAT SIMP) 2 3) $X))
  <1 (SIMPLIFYA ((MTIMES SIMP) ((RAT SIMP) 2 3) $X))

          2 x
(%o4)
          ---

           3
(%i5) ?untrace();
(%o5)
      (simplifya)
(%i6) ?trace(?meval1);
(%o6)
        (meval1)
(%i7) ex:23;
  1> (MEVAL1 ((MSETQ) $EX 23))
    2> (MEVAL1 23)
    <2 (MEVAL1 23)
  <1 (MEVAL1 23)
(%o7)
           23
(%i8) ex^2-1;
  1> (MEVAL1 ((MPLUS) ((MEXPT) $EX 2) ((MMINUS) 1)))
    2> (MEVAL1 ((MEXPT) $EX 2))
      3> (MEVAL1 $EX)
      <3 (MEVAL1 23)
      3> (MEVAL1 2)
      <3 (MEVAL1 2)
    <2 (MEVAL1 ((MEXPT) 23 2))
    2> (MEVAL1 ((MMINUS) 1))
      3> (MEVAL1 1)
      <3 (MEVAL1 1)
    <2 (MEVAL1 ((MMINUS) 1))
  <1 (MEVAL1 ((MPLUS) 529 -1))
(%o8)
          528
(%i9) ?trace(?meval1,?simplifya)$
  1> (MEVAL1 ((TRACE) MEVAL1 SIMPLIFYA))
  <1 (MEVAL1 (MEVAL1 SIMPLIFYA))
  1> (SIMPLIFYA (MEVAL1 SIMPLIFYA) NIL)
    2> (SIMPLIFYA SIMPLIFYA NIL)
    <2 (SIMPLIFYA SIMPLIFYA)
  <1 (SIMPLIFYA (MEVAL1 SIMPLIFYA))
(%i10) ex^2-1;
  1> (MEVAL1 ((MPLUS) ((MEXPT) $EX 2) ((MMINUS) 1)))
    2> (MEVAL1 ((MEXPT) $EX 2))
      3> (MEVAL1 $EX)
      <3 (MEVAL1 23)
      3> (SIMPLIFYA 23 NIL)
      <3 (SIMPLIFYA 23)
      3> (MEVAL1 2)
      <3 (MEVAL1 2)
      3> (SIMPLIFYA 2 NIL)
      <3 (SIMPLIFYA 2)
    <2 (MEVAL1 ((MEXPT) 23 2))
    2> (SIMPLIFYA ((MEXPT) 23 2) NIL)
      3> (SIMPLIFYA 23 NIL)
      <3 (SIMPLIFYA 23)
      3> (SIMPLIFYA 2 NIL)
      <3 (SIMPLIFYA 2)
    <2 (SIMPLIFYA 529)
    2> (MEVAL1 ((MMINUS) 1))
      3> (MEVAL1 1)
      <3 (MEVAL1 1)
      3> (SIMPLIFYA 1 NIL)
      <3 (SIMPLIFYA 1)
    <2 (MEVAL1 ((MMINUS) 1))
    2> (SIMPLIFYA ((MMINUS) 1) NIL)
    <2 (SIMPLIFYA -1)
  <1 (MEVAL1 ((MPLUS) 529 -1))
  1> (SIMPLIFYA ((MPLUS) 529 -1) NIL)
    2> (SIMPLIFYA 529 NIL)
    <2 (SIMPLIFYA 529)
    2> (SIMPLIFYA -1 NIL)
    <2 (SIMPLIFYA -1)
  <1 (SIMPLIFYA 528)
(%o10)
          528
(%i11)

On Sun, Oct 10, 2010 at 05:56, Max B <txtmax at yahoo.ca> wrote:
>
> Hi,
>
> Thanks for Maxima - it is a great tool!? :)
>
> I am curious about how it operates; function call tree etc.? For example:
> identify the functions that are called when the user inputs '2+2;', or
> 'collectterms(expand(sbs));'.? Unfortunately, maxima is written in lisp and
> I can't seem to debug it.?? Tools with which I am familiar include gdb, the
> printf function, and the cpp macros __LINE__ etc.
>
> I do have the maxima-5.21.1 source code, and have managed to compile it.
>
> I have resolved to insert lines of code like 'at line __LINE__ in function
> __FUNC__' (or similar) into the functions in which I am interested, but
> cannot discover the syntax of lisp that would allow me to announce
> watchpoints like printf.
>
> So in my desperation I thought to email this listserv to ask for help.
>
> Is there a not-for-public-release 'debug' version of the source code with
> this type of code present?
>
> Thanks in advance,
> Max
>
>
>
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>