Visualize Expression Trees

A useful model for visualizing a MuPAD® expression is the expression tree. It reflects the internal representation of an expression. The operators or their corresponding functions are the vertices, and the arguments are sub-trees. The lowest precedence operator is always at the root of an expression tree.

For example, you can represent the expression a + b * c + d * e *sin(f)^g using this expression tree.

The following expression tree represents the expression int(exp(x^4), x = 0..1).

MuPAD internally represents the difference a - b as a + b*(-1). Therefore, MuPAD represents the difference using this expression tree.

Similarly, a quotient a/b has the internal representation a * b^(-1).

To display expression trees in a MuPAD notebook, use the prog::exprtree function. It replaces operators with the names of the corresponding system functions:

prog::exprtree(a + b * c + d * e *sin(f)^g):
_plus
|
+-- a
|
+-- _mult
|   |
|   +-- b
|   |
|   `-- c
|
`-- _mult
    |
    +-- d
    |
    +-- e
    |
    `-- _power
        |
        +-- sin
        |   |
        |   `-- f
        |
        `-- g
Was this topic helpful?