### 4.3.2 Subexpressions

Xcas can operate on expressions in the expression editor or subexpressions of the expression. To understand subexpressions and how to select them, it helps to know that Xcas stores expressions as trees.

A tree, in this sense, consists of objects called nodes. A node can be connected to lower nodes, called the children of the first node. Each node (except one) will be connected to exactly one node above it, called the parent node. One special node, called the root node, won’t have a parent node. Two nodes with the same parent nodes are called siblings. Finally, if a node doesn’t have any children, it is called a leaf. This terminology comes from a visual representation of a tree,

which looks like an upside-down tree; the root is at the top and the leaves are at the bottom.

Given an expression, the nodes of the corresponding tree are the functions, operators, variables and constants. The children of a function node are its arguments, the children of an operator node are its operands, and the constants and variables will be the leaves. For example, the tree for sin(2*x + y) will look like

A subexpression of an expression will be a selected node together with the nodes below it. For example, both 2*x and 2*x+y are subexpressions of sin(2*x+y), but x+y is not.

A subexpression of the contents of the expression editor can be selected with the mouse; the selection will appear white on a black background. A subexpression can also be chosen with the keyboard using the arrow keys. Given a selection:

- The up arrow will go to the parent node.
- The down arrow will go to the leftmost child node.
- The right and left arrows will go to the right and left sibling nodes.
- The control key with the right and left arrows will switch the selection with the corresponding sibling.
- If a constant or variable is selected, the backspace key will delete it. For other selections, backspace will delete the function or operator, and another backspace will delete the arguments or operands.

You can use the arrow keys to navigate the tree structure of an expression, which isn’t always evident by looking at the expression itself. For example, suppose you enter x*y*z in the editor. The two multiplications will be a different levels; the tree will look like

If you select the entire expression with the up arrow and then go to the M menu to the right of the line and choose eval, then the expression will look the same but, as you can check by navigating it with the arrow keys, the tree will look like