# [Maxima] Internal form of expressions

Stavros Macrakis macrakis at alum.mit.edu
Fri Oct 16 12:39:44 CDT 2009

```Martin,

Thanks for passing this function along to the list. There is a bug in Maxima
that causes a problem in that code for rational numbers (like 1/2); I have
worked around it in the revised code below.

Let me just add that "part" actually doesn't show the true internal form (as
shown in the 'inpart' command), but the internal version of the display form
(as shown in the 'part' command).  To show the true internal form, you can
use inflag:

show_form_internal(ex) := block([inflag:true],show_form(ex))\$
show_form(ex) :=
if atom(ex)
then ex
else funmake(nounify(concat(" ", part(ex, 0))),
map(show_form, args(ex)))\$

(%i1) expr: exp(x) - x/(2*a) + 1/x;

*** Standard 2d print form ***

x    x    1
(%o1)  %e  - --- + -
2 a   x

(%i2) print(expr),display2d:false;

*** Standard 1d print form ***

%e^x-x/(2*a)+1/x

(%i3) show_form(expr);

*** The form as seen by 'part' (display internal form) in Maxima syntax ***

(%o3)  +( ^(%e, x),  -( /(x,  *(2, a))),  /(1, x))

(%i4) show_form_internal(expr);

*** The form as seen by 'inpart' (internal form) in Maxima syntax ***

(%o4)  +( ^(x, - 1),  *( /(- 1, 2),  ^(a, - 1), x),  ^(%e, x))

(%i5) ?print(expr)\$

*** The internal form in Lisp syntax ***

((MPLUS SIMP) ((MEXPT SIMP) \$X -1)
((MTIMES SIMP) ((RAT SIMP) -1 2) ((MEXPT SIMP) \$A -1) \$X)
((MEXPT SIMP) \$%E \$X))

Remember that there are other representations, by far the most important of
which is CRE (Canonical Rational Expressions), whose internal form will not
be reflected by show_internal_form. It wouldn't be that hard to write a
version of show_form_internal for CREs.

-s

2009/10/16 Martin Schönecker <ms_usenet at gmx.de>:
> Wilhelm Haager schrieb:
>> Hi,
>>
>> Is there a possibility to display the "internal form" of expressions
>> (like the "FullForm" in Mathematica) in Maxima, e.g.
>> which displays the expression
>>
>>     x/sqrt(5)+y**2+1/z
>>
>> in the form
>>
>>     "+"("/"(x,sqrt(5)),"^"(y,2),"/"(1,z))
>
> Stavros Macrakis once posted a nice function show_form() on
> this list.
> http://www.math.utexas.edu/pipermail/maxima/2008/015004.html
>
>
> e: x/sqrt(5)+y**2+1/z;
> show_form(ex) :=
>   if atom(ex)
>   then ex
>   else funmake(nounify(concat(" ", part(ex, 0))),
>                maplist(show_form, ex))\$
> show_form(e);
>
>
> 1/z+y^2+x/sqrt(5)
>
> +( /(1,z), ^(y,2), /(x, sqrt(5)))
>
>
>
> Regards,
> Martin
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.math.utexas.edu/pipermail/maxima/attachments/20091016/9890ac2b/attachment.html
```