3.3. Expressions and validation

Once we use abstract indices, there is no need to have a special TensorTimes. The usual Times product is enough and has one important advantage: we can use many built-in rules in Mathematica to simplify Times expressions. As usual, contractions are given using Einstein rule of staggered up/down repeated indices.

The order of factors is irrelevant in Times expressions:

In[128]:=

v[-a] T[a, b]

Out[128]=

T_  ^ab v_a^

In[129]:=

v[-a] T[a, b] + T[a, b] v[-a]

Out[129]=

2 T_  ^ab v_a^

The syntax of any expression can be checked using the function Validate. This function works recursively from the most external structures to the most internal ones, calling private functions ValidateTensor, ValidateCovD, etc. That gives you an idea of which problems will be detected first.

Validate                Validate an input expression

Functions that deal with validation.

If we get no errors, the input is syntactically correct:

In[130]:=

Validate[T[a, b, -c] S[c, d] v[-d] + r[]^3S[a, b]]

Out[130]=

r_^^3 S_  ^ab + S_  ^cd T_ (  c)^ab  v_d^

In[131]:=

Validate[T[a, b, c] S[-c, d] v[-d] + r[]^3S[a, b]]

Validate :: error : Invalid character of index in tensor T

Validate :: error : Invalid character of index in tensor S

Out[131]=

r_^^3 S_  ^ab + ERROR[S_c ^( d)] ERROR[T_   ^abc] v_d^

Some errors cannot be always localized in a single object. We do not return the expression:

In[132]:=

Validate[T[a, b, -c] v[-c]]

Validate :: repeated : Found indices with the same name -c .

In[133]:=

Validate[S[a, b] v[-b] + v[-a]]

Validate :: inhom : Found inhomogeneous indices: {{-a}, {a}}.

Because validation takes up some time, it is not automatic. xTensor` has the command Validate to be used by the user as required. However, if validation is needed in all computations it is possible to switch on automatic validation, by acting on the $Pre variable:

Here, there is not automatic validation:

In[134]:=

S[a, b] v[b]

Out[134]=

S_  ^ab v_ ^b

In[135]:=

Validate[%]

Validate :: repeated : Found indices with the same name b .

This switches on automatic validation:

In[136]:=

$Pre

Out[136]=

$Pre

In[137]:=

$Pre = Validate ;

In[138]:=

S[a, b] v[b]

Validate :: repeated : Found indices with the same name b .

This switches off automatic validation:

In[139]:=

$Pre=.

In[140]:=

S[a, b] v[b]

Out[140]=

S_  ^ab v_ ^b

In[141]:=

UndefTensor[S]

** UndefTensor: Undefined tensor S


Created by Mathematica  (May 16, 2008) Valid XHTML 1.1!