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]:=

expr = 4T[a, b, -c, Dir[v[d]]] v[-a] r[]^2CD[-e][S[LI[1], -b, d]]

Out[870]=

4 r_^^2 T_ (  cv)^ab   v_a^  (▽_e^ S_ ( b )^(1 d))

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]:=

FindIndices[Evaluate[expr]]

Out[871]=

{a, b, -c, Dir[v_ ^d], -a, LI[1], -b, d, -e}

In[872]:=

FindFreeIndices[Evaluate[expr]]

Out[872]=

{-c, d, -e}

In[873]:=

FindDummyIndices[Evaluate[expr]]

Out[873]=

{a, b}

In[874]:=

FindBlockedIndices[Evaluate[expr]]

Out[874]=

{Dir[v_ ^d], LI[1]}

This attribute is given to be able to extract indices of expressions before they get evaluated:

In[875]:=

n[a] n[-a]

Out[875]=

-1

In[876]:=

FindIndices[n[a] n[-a]]

Out[876]=

{a, -a}

Note that the returned lists of indices have head IndexList, in order to avoid confusion with basis and component indices:

In[877]:=

InputForm[%]

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]:=

IndicesOf[][expr]

Out[878]=

{a, b, -c, Dir[v_ ^d], -a, LI[1], -b, d, -e}

We can select indices by type:

In[879]:=

IndicesOf[AIndex][expr]

Out[879]=

{a, b, -c, -a, -b, d, -e}

In[880]:=

IndicesOf[DIndex][expr]

Out[880]=

{Dir[v_ ^d]}

In[881]:=

IndicesOf[LIndex][expr]

Out[881]=

{LI[1]}

or by character:

In[882]:=

IndicesOf[Up][expr]

Out[882]=

{a, b, LI[1], d}

In[883]:=

IndicesOf[Down][expr]

Out[883]=

{-c, Dir[v_ ^d], -a, -b, -e}

or by state:

In[884]:=

IndicesOf[Free][expr]

Out[884]=

{-c, d, -e}

In[885]:=

IndicesOf[Dummy][expr]

Out[885]=

{-a, a, -b, b}

In[886]:=

IndicesOf[Blocked][expr]

Out[886]=

{Dir[v_ ^d], LI[1]}

We can also specify a vbundle (or a basis):

In[887]:=

IndicesOf[TangentM3][expr]

Out[887]=

{a, b, -c, Dir[v_ ^d], -a, -b, d, -e}

or a tensor:

In[888]:=

IndicesOf[S][expr]

Out[888]=

{-b, d, LI[1]}

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]:=

IndicesOf[{DIndex, LIndex}][expr]

Out[889]=

{Dir[v_ ^d], LI[1]}

Free indices on the tensor S:

In[890]:=

IndicesOf[Free, S][expr]

Out[890]=

{d}

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]:=

IndicesOf[S, Free][expr]

Out[891]=

{-b, d}

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) Valid XHTML 1.1!