5.3. Index patterns
In the previous definitions of the vector w[a] we always used the pattern a_ which stands for any possible input, including up-indices and down-indices of any manifold, or even directional or label (or basis or component) indices. Sometimes this is what we want, but often it is not. In the following definitions there are no dummies or conflicts between indices and tensor names, so that we can safely use the usual SetDelayed (:=) definitions to simplify the examples.
The notation for tensors and indices in xTensor` is very simple, but that complicates working with patterns. On the other hand, there are always several ways to represent the same pattern.
Define, for the sake of simplicity:
In[349]:=
This pattern stands for everything. Every w is converted into T:
In[351]:=
In[352]:=
Out[352]=
In[353]:=
Let us first work with the character of the indices: use the functions
UpIndexQ Detect up-indices
DownIndexQ Detect down-indices
This pattern matches only up-indices:
In[354]:=
In[355]:=
Out[355]=
In[356]:=
This pattern matches only down-indices:
In[357]:=
In[358]:=
Out[358]=
In[359]:=
And now we work with the type of index: use the functions
AIndexQ Detect abstract indices
BIndexQ Detect basis indices
CIndexQ Detect component indices
DIndexQ Detect directional indices
LIndexQ Detect label indices
GIndexQ Detect all generalized indices, but not patterns
ABIndexQ Detect contractible indices (abstract or basis indices)
BCIndexQ Detect indices associated to a basis or chart (basis or component indices)
CDIndexQ Detect indices representing a direction (component or directional indices)
PIndexQ Detect pattern indices
Detect types of indices.
This pattern matches only abstract indices, from any manifold:
In[360]:=
In[361]:=
Out[361]=
In[362]:=
There is a simple and efficient pattern for abstract up-indices or abstract down-indices:
In[363]:=
In[364]:=
Out[364]=
In[365]:=
In[366]:=
In[367]:=
Out[367]=
In[368]:=
This pattern matches only directional indices. Recall that directions do not have a sign in front. A message is sent complaining about the character of the vector v.
In[369]:=
In[370]:=
Out[370]=
In[371]:=
There is also a simpler version (which does not find the problem with the position of the ultraindex):
In[372]:=
In[373]:=
Out[373]=
In[374]:=
The functions AIndexQ, BIndexQ, CIndexQ, DIndexQ and GIndexQ admit a second argument restricting the manifold to which the indices must belong.
This pattern only matches abstract indices on TangentM3:
In[375]:=
In[376]:=
Out[376]=
In[377]:=
Again there are simpler and cleaner versions, also discriminating between upindices and downindices (Q-functions) or not (pmQ-functions). The use of Symbol is not needed now.
In[378]:=
In[379]:=
Out[379]=
In[380]:=
In[381]:=
In[382]:=
Out[382]=
In[383]:=
In[384]:=
In[385]:=
Out[385]=
In[386]:=
In case of doubt use the function PatternIndex, which constructs patterns of the required form.
These are examples of different patterns for abstract indices named a. Note the minus sign in front of a for down-indices. The pattern is for the symbol of the index, and not for the whole index.
In[387]:=
Out[387]=
In[388]:=
Out[388]=
In[389]:=
Out[389]=
In[390]:=
Out[390]=
These are patterns for directional indices named d:
In[391]:=
Out[391]=
In[392]:=
Out[392]=
In[393]:=
Out[393]=
In[394]:=
Out[394]=
Created by Mathematica (May 16, 2008) |