9.1. Find indices
Given an expression, very often we want to extract all indices of the expression, or those of certain type, or character or state. We have already seen how to select indices of any type and any character. In this subsection we shall define functions to extract all indices according to a number of ` `selectors´ ´.
There are two sets of functions. There is first the internal function FindIndices, which returns all indices of an expression, without first evaluating it, and its relatives FindFreeIndices, FindDummyIndices and FindBlockedIndices. There is then the user driver for finding indices, called IndicesOf, which admits a number of criteria for index selection, and evaluates its input (as the user typically expects).
Let us start with this expression
In[870]:=
Out[870]=
The three Find*Indices functions have attribute HoldFirst, and hence require the use of Evaluate when we do not feed the expression itself:
In[871]:=
Out[871]=
In[872]:=
Out[872]=
In[873]:=
Out[873]=
In[874]:=
Out[874]=
This attribute is given to be able to extract indices of expressions before they get evaluated:
In[875]:=
Out[875]=
In[876]:=
Out[876]=
Note that the returned lists of indices have head IndexList, in order to avoid confusion with basis and component indices:
In[877]:=
Out[877]//InputForm=
IndexList[a, -a]
FindIndices Get all indices of an expression
FindFreeIndices Get all free indices of an expression
FindDummyIndices Get all dummy indices of an expression
FindBlockedIndices Get all blocked indices of an expression
IndexList Head for a list of indices
Finding indices. Internal functions
Then we have the user driver, with two pairs of brackets:
With no selectors, we get all indices in the expression:
In[878]:=
Out[878]=
We can select indices by type:
In[879]:=
Out[879]=
In[880]:=
Out[880]=
In[881]:=
Out[881]=
or by character:
In[882]:=
Out[882]=
In[883]:=
Out[883]=
or by state:
In[884]:=
Out[884]=
In[885]:=
Out[885]=
In[886]:=
Out[886]=
We can also specify a vbundle (or a basis):
In[887]:=
Out[887]=
or a tensor:
In[888]:=
Out[888]=
We can combine several selectors, in two possible ways: a list of selectors represents the union, and a sequence represents the intersection.
Directions or labels:
In[889]:=
Out[889]=
Free indices on the tensor S:
In[890]:=
Out[890]=
Members of a selectors list are conmutative, but not members of a sequence: the construction of the final list is performed from left to right. Compare with the previous result:
In[891]:=
Out[891]=
This powerful function is very flexible and has more possibilities once we allow the presence of bases (see xCobaDoc.nb).
IndicesOf Get all indices of an expression according to a number of selecting criteria
Finding indices. User driver
Created by Mathematica (May 16, 2008) | ![]() |