9.3. Scalar and scalar functions
Another important problem is the following. In the same way that we are using Times for a product of tensors, we shall use Power, Sqrt, Exp and other functions acting on scalar tensor expressions. There is a problem: there are built-in definitions for those functions that could be incorrect for tensors. For example we have (a b)^n = a^n b^n. However (v[a] v[-a])^n is not equal to v[a]^n v[-a]^n. To prevent those problems we have two options: we could define new functions IndexPower, IndexSqrt, etc, or we can introduce a new head Scalar such that the arguments of those functions must be always wrapped with that head.
Scalar Wrapper to isolate scalar expressions
PutScalar Wrap scalars with the head Scalar
BreakScalars Break Scalar expressions into irreducible Scalar expressions
NoScalar Remove all Scalar heads, introducing new dummies wherever needed
Scalar expressions.
The direct use of Power could lead to unconsistent expressions:
In[915]:=
Out[915]=
Instead, the right way to write it would be
In[916]:=
Out[916]=
xTensor` can work with those objects as usual:
In[917]:=
Out[917]=
In[918]:=
Out[918]=
Note that Scalar effectively shields its argument from the rest of an expression and therefore there can be repeated indices:
In[919]:=
Out[919]=
In[920]:=
Out[920]=
By default the function Simplification does not add new Scalar heads, because that takes some time for large expressions:
In[921]:=
Out[921]=
You can force it using PutScalar:
In[922]:=
Out[922]=
In[923]:=
Out[923]=
Two other functions to manipulate Scalar expressions are BreakScalars and NoScalar:
In[924]:=
Out[924]=
In[925]:=
Out[925]=
In[926]:=
Out[926]=
In[927]:=
Out[927]=
DefScalarFunction Define an inert head
UndefScalarFunction Undefine an inert head
$ScalarFunctions List of defined inert heads
Definition of a scalar function.
A scalar function is one that only accepts scalar arguments and returns scalars. Some of them are
In[928]:=
Out[928]=
and we can define new scalar functions:
We define a scalar function SF:
In[929]:=
In[930]:=
Out[930]=
In[931]:=
Out[931]=
In[932]:=
Out[932]=
Created by Mathematica (May 16, 2008) | ![]() |