Accessing individual parts of expressions through indexing
One can access also the internal parts of an expression (those inside the square brackets), by using indexing (Part command).
The following example illustrates this:In[]:= {a[[0]], a[[1]], a[[2]], a[[2, 0]], a[[2, 1]], a[[2, 1, 0]], a[[2, 1, 1]], a[[2, 1, 2]]}
Out[]:= {Times, z, Sin[x +y], Sin, x +y, Plus, x, y}
We have just deconstructed our expression to pieces. In fact, we started from the "stem" and then went down along the "branches" to the "leaves" of the tree which we have seen above with the TreeForm.Note:
- We see that the addresses (index sequences) which end with zero give the Heads of the subexpressions - this is a convention.
- In principle, any complex expression can be deconstructed in this way, and moreover, one can change its subexpressions.