Maxima helpful hints

From Maxima CAS Wiki

Jump to: navigation, search

Internal workings

How to display the internal form of an expression

The following function displays a the internal form of an expression in a friendly way. (Posted by Stavros Macrakis in the Maxima mailing list)

show_form(ex) :=
    if atom(ex)
    then ex
    else funmake(nounify(concat(" ", part(ex, 0))),
        maplist(show_form, ex));

For example, the following input

e: x/sqrt(5)+y**2+1/z;
show_form(e);

produces

+( /(1,z), ^(y,2), /(x, sqrt(5)))

An alternative is to use the command

?print(ex)

where ex is the expression to be printed. This executes a LISP command print. For example

?print(x/sqrt(5)+y**2+1/z);

produces

((MPLUS . #0=(SIMP))
 ((MTIMES . #0#) ((MEXPT SIMP) 5 ((RAT SIMP) -1 2)) $X)
 (#1=(MEXPT . #0#) $Y 2) (#1# $Z -1))

It is sometimes very helpful to have access to the underlying LISP representation of an expression.