Abstract data type "Tree"
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
adt::Tree(tree
)
adt::Tree
implements the abstract data type
"Tree".
A tree must be given as a special MuPAD^{®} list. The first object of the list is the root of the tree. All further objects are leaves or subtrees of the tree. A subtree is again a special list (as described), and any other MuPAD object will be interpreted as leaf of the tree (see Example 1).
A tree can be used to display data in tree structure using the
function output::tree
(or
the method "print"
of a tree). The nodes and leaves
of the tree will be printed by MuPAD when
the tree will be displayed.
A tree can also be used as datatype to keep and handle any MuPAD data.
Note: The methods of all abstract data types must be called especially and will result changing the object itself as side effect. 
T := adt::Tree([_plus, 3, 4, [_mult, 5, 3], 1])
builds
a tree and assigns it to the variable T
.
Every tree will be displayed as Tree
followed
by a number. This name is generated by genident
.
To display the content of a tree, the function expose
or the method "print"
of
the tree itself must be used.
Note:
All following methods changes the value of 
The methods nops
, op
, expr
, print
, indent
, chars
are
now available for handling with trees.
Creating a simple tree with only two leaves. To access and display a tree it must be assigned to a variable:
T := adt::Tree(["ROOT", "LEFT", "RIGHT"])
The tree will only be printed by its name. To display the tree,
the function expose
or
the method "print"
of the tree must be used:
T::print()
ROOT  + LEFT  ` RIGHT
expose(T)
ROOT  + LEFT  ` RIGHT
The next tree contains two subtrees as leaves:
T := adt::Tree(["ROOT", ["LROOT", "LLEFT", "LRIGHT"], ["RROOT", "RLEFT", "RRIGHT"]]): T::print()
ROOT  + LROOT    + LLEFT    ` LRIGHT  ` RROOT  + RLEFT  ` RRIGHT
Get the operands of a tree: Also a subtree can be an operand:
T := adt::Tree(["ROOT", ["LROOT", "LLEFT", "LRIGHT"], "MIDDLE", ["RROOT", "RLEFT", "RRIGHT"]]): T::op()
Use expose
to
display subtrees:
map(%, expose)
LROOT RROOT   + LLEFT , "MIDDLE", + RLEFT   ` LRIGHT ` RRIGHT
Get all operands including the root:
T::op(0..T::nops())
Access to various operands:
T::op(0); T::op(2..3); T::op([1, 2])
The default characters are ["", "+", "", „",
" "]
:
T := adt::Tree(["ROOT", ["LROOT", "LLEFT", "LRIGHT"], ["RROOT", "RLEFT", "RRIGHT"]]): T::print()
ROOT  + LROOT    + LLEFT    ` LRIGHT  ` RROOT  + RLEFT  ` RRIGHT
The characters can be changed:
T::chars(["", "", "_", "", " "]): T::print()
ROOT  __ LROOT    __ LLEFT    __ LRIGHT  __ RROOT  __ RLEFT  __ RRIGHT
A tree visualizes the structure of an expression:
T:= adt::Tree([_plus, [_power, [sin, x], 2], [_power, [cos, x], 2]]): T::print()
_plus  + _power    + sin      ` x    ` 2  ` _power  + cos    ` x  ` 2
A tree can be converted to a MuPAD expression:
T::expr(), simplify(T::expr())

The tree, given as a special list (see details) 