# 9a. Tensors on modules¶

This notebook is part of the Introduction to manifolds in SageMath by Andrzej Chrzeszczyk (Jan Kochanowski University of Kielce, Poland).

In :
version()

Out:
'SageMath version 9.6, Release Date: 2022-05-15'

### Reminder. Vectors and linear forms on modules¶

Recall that for free modules of finite rank (in notebook 6) we have introduced vectors and linear forms.

Example 9.1a

Define a free module of finite rank and some vector and linear form.

In :
N=3                                     # dimension of the module
%display latex
M=FiniteRankFreeModule(SR,3,name='M')   # 3-dim module over SR
e = M.basis('e')                        # basis of M
v=var('v',n=3)                          # components of vector v
v=M(list(v))                            # define vector v

In :
print(v)                                # information on v
v.comp()[:]                             # components of v

Element of the 3-dimensional vector space M over the Symbolic Ring

Out:
$\displaystyle \left[v_{0}, v_{1}, v_{2}\right]$

General linear forms on a 3-dimensional module can be defined as follows:

In :
a=M.linear_form()                       # linear form a on M
a[:]=var('a',n=4)                       # components of a

In :
a.disp()                                # show a as combination
# of dual basis

Out:
$\displaystyle a_{0} e^{0} + a_{1} e^{1} + a_{2} e^{2}$

The linear form applied to a vector gives a scalar.

In :
a(v)                                   # value a(v)

Out:
$\displaystyle a_{0} v_{0} + a_{1} v_{1} + a_{2} v_{2}$

The value of a vector $v\in M$ on a linear form $a\in M^*$ is by definition equal to $a(v)$.

In :
v(a)                                   # value v(a)

Out:
$\displaystyle a_{0} v_{0} + a_{1} v_{1} + a_{2} v_{2}$

Now we are ready to define more general objects.

## Tensors on modules¶

If $M$ is a vector space or a module, by a multilinear or more precisely $k$-linear form we mean a function $t: M^k\to R$ which is linear in each of its arguments, i.e., for $i=1,\ldots,k$

$$t(v_1\ldots,\alpha v_i+\beta w_i,\ldots v_k)= \alpha t(v_1\ldots,v_i,\ldots v_k)+\beta t(v_1\ldots,w_i,\ldots v_k),\quad \alpha,\beta\in R,\quad v_i,w_i\in M.$$

Assume that $M$ is a module.

### Tensor module $T^{(k,l)}M$¶

Tensors of type (k,l) on $M$ are multilinear maps:

$$T^{(k,l)}M = \{t:\underbrace{M^*\times\cdots\times M^*}_{k\ \; \mbox{times}} \times \underbrace{M\times\cdots\times M}_{l\ \; \mbox{times}}\to R\},$$

where $\ M^*\$ denotes the dual module, i.e. the module of linear forms on $M$ (cf. notebook 6).

Since $a\to v(a)$ defines a linear form $M^*\to R$, the elements $v\in M$ can be considered as elements of $T^{(1,0)}M$. On the other hand $T^{(0,1)}M$ as the space of linear forms on $M$ is equal to $M^*$. Thus, tensors generalize vectors and linear forms.

Example 9.2a

Let us show how to use tensor_module method of SageMath Manifolds.

In :
# continuation
M.tensor_module(1,0)    # elements of T^(1,0) are vectors

Out:
$\displaystyle M$
In :
print(M.tensor_module(1,0))         # T^(1,0) = M
# since the ring SR is a field we obtain vector space

3-dimensional vector space M over the Symbolic Ring

In :
M.tensor_module(0,1)               # T^(0,1) = M*

Out:
$\displaystyle M^*$
In :
print(M.tensor_module(0,1))

Free module of type-(0,1) tensors on the 3-dimensional vector space M over the Symbolic Ring


### Module $T^{(0,k)}M$ - of covariant tensors of rank $k$¶

is the module of multilinear maps

$$T^{(0,k)}M = \{t:\underbrace{M\times\cdots\times M}_{k\ \; \mbox{times}}\to R\}.$$

For k=1 we obtain the module of linear forms or covectors on $M$.

In $T^{(0,k)}M$ we introduce the algebraic operations by

$$(at+bs)(v_1\ldots,v_k)=at(v_1\ldots,v_k)+bs(v_1\ldots,v_k),$$

where $t,s\in T^{(0,k)}M$, $v_1,\ldots,v_k\in M$ and $a,b\in R$.

For $t\in T^{(0,k)},\ s\in T^{(0,l)}M$ we define the tensor product $\ t\otimes s\in T^{(0,k+l)}M\$ by

\begin{equation} (t ⊗ s )(v_1 ,\ldots , v_{k+l} ) = t (v_1 ,\ldots, v_k ) s (v_{k+1} , . . . , v_{k+l} ), \label{eq:tensor_product}\tag{9.1a} \end{equation}

for $v_1,\ldots,v_{k+l}\in M$.

In SageMath Manifolds the symbol of tensor product is simply $*$.

Example 9.3a

Let us check the last formula in the case of two general tensors from $T^{(0,2)}$ and 2-dimensional module.

In :
N=2;                              # dimension of module
%display latex
Mo=FiniteRankFreeModule(SR,2,name='Mo')   # module Mo
e = Mo.basis('e')                 # basis of Mo
t=Mo.tensor((0,2))                # (0,2) type tensor t
s=Mo.tensor((0,2))                # (0,2) type tensor s

In :
M=4                               # number of vectors
vv=[[var('v'+str(i)+str(j),       # components of four vectors
latex_name='v'+'^'+str(i)+'_'+str(j))
for i in range(N)] for j in range(M)]
vv

Out:
$\displaystyle \left[\left[{v^0_0}, {v^1_0}\right], \left[{v^0_1}, {v^1_1}\right], \left[{v^0_2}, {v^1_2}\right], \left[{v^0_3}, {v^1_3}\right]\right]$
In :
v=[Mo(vv[k]) for k in range(M)]   # list of vectors
tt=[[var('t'+str(i)+str(j))       # components of tensor t
for j in range(M)] for i in range(N)]
ss=[[var('t'+str(i)+str(j))       # components of tensor s
for j in range(M)] for i in range(N)]

t[:]=tt                 # define tensor t components t_{ij}
s[:]=ss                 # define tensor s components s_{ij}

In :
# check the equality (9.1a) defining tensor product
bool((t*s)(v,v,v,v)==t(v,v)*s(v,v))

Out:
$\displaystyle \mathrm{True}$

Tensor product has the following properties (proofs for modules $T_pM,$ where $M$ denotes a manifold are given in the next notebook)

\begin{equation} \begin{matrix} (ar + bs ) ⊗ t = ar ⊗ t + bs ⊗ t ,\\ r ⊗ (as + bt ) = ar ⊗ s + br ⊗ t ,\\ (r ⊗ s ) ⊗ t = r ⊗ (s ⊗ t ), \end{matrix} \label{eq:tensor_product_prop}\tag{9.2a} \end{equation}

for $a,b\in R\$ and for arbitrary covariant tensors $r,s,t$ (the addition is defined only for tensors of the same rank $(0,k)$).

### Covariant tensors in components¶

One can check that if $e_1,\ldots,e_n$ is a basis of the module $M$ and $e^1,\ldots,e^n\$ its dual basis (defined in notebook 6), then the elements

\begin{equation} e^{j_1}\otimes\ldots \otimes e^{j_m}, \quad j_q\in\{1,\ldots,n\} \tag{9.2a} \end{equation}

form a basis for $T^{(0,m)}M$ and if we put

$$t_{j_1\ldots j_m} =t(e_{j_1},\ldots,e_{j_m}),$$

then

\begin{equation} t=t_{j_1\ldots j_m} e^{j_1}\otimes\ldots\otimes e^{j_m}, \quad \text{for }\ t\in T^{(0,m)}M. \tag{9.3a} \end{equation}

In fact, since $\ v_1=e^{j_1}(v_1)e_{j_1},\ldots, v_m=e^{j_m}(v_m)e_{j_m},\$ then

$$t(v_1,\ldots,v_m)=t(e^{j_1}(v_1)e_{j_1},\ldots,e^{j_m}(v_m)e_{j_m})\\ =e^{j_1}(v_1)\ldots e^{j_m}(v_m)t(e_{j_1},\ldots,e_{j_m})\\ =t_{j_1\ldots j_m}e^{j_1}\otimes \ldots \otimes e^{j_m}(v_1,\ldots v_m).$$

Example 9.4a

Let us show the representation of a tensor $\ t\in T^{(0,3)}M\$ in components.

In :
N=2                                     # dimension of module
st=[[[var('t'+str(i0)+str(i1)+str(i2))  # components of t
for i2 in range(N)]
for i1 in range(N)]
for i0 in range(N)]
st                                      # show components

Out:
$\displaystyle \left[\left[\left[t_{000}, t_{001}\right], \left[t_{010}, t_{011}\right]\right], \left[\left[t_{100}, t_{101}\right], \left[t_{110}, t_{111}\right]\right]\right]$
In :
Mo=FiniteRankFreeModule(SR,2,name='Mo') # module Mo
e = Mo.basis('e')                       # basis of Mo
%display latex
t = Mo.tensor((0,3), name='t')          # tensor of (0,3) type
t[:]=st                                 # define all components


General tensor of type (0,3) on a 2-dimensional module:

In :
t.disp()                                # show t

Out:
$\displaystyle t = t_{000} e^{0}\otimes e^{0}\otimes e^{0} + t_{001} e^{0}\otimes e^{0}\otimes e^{1} + t_{010} e^{0}\otimes e^{1}\otimes e^{0} + t_{011} e^{0}\otimes e^{1}\otimes e^{1} + t_{100} e^{1}\otimes e^{0}\otimes e^{0} + t_{101} e^{1}\otimes e^{0}\otimes e^{1} + t_{110} e^{1}\otimes e^{1}\otimes e^{0} + t_{111} e^{1}\otimes e^{1}\otimes e^{1}$

Tensor of type (0,3) on a 2-dimensional module with concrete components:

In :
# continuation
ct=range(1,9)      #  [1,...,8] consecutive components
for i0 in range(N):
for i1 in range(N):
for i2 in range(N):
t[i0,i1,i2]=ct[i0*N*N+i1*N+i2]
t.disp()

Out:
$\displaystyle t = e^{0}\otimes e^{0}\otimes e^{0} + 2 e^{0}\otimes e^{0}\otimes e^{1} + 3 e^{0}\otimes e^{1}\otimes e^{0} + 4 e^{0}\otimes e^{1}\otimes e^{1} + 5 e^{1}\otimes e^{0}\otimes e^{0} + 6 e^{1}\otimes e^{0}\otimes e^{1} + 7 e^{1}\otimes e^{1}\otimes e^{0} + 8 e^{1}\otimes e^{1}\otimes e^{1}$
In :
print(e)                              # basis

Basis (e_0,e_1) on the 2-dimensional vector space Mo over the Symbolic Ring


Check that the coefficient $t_{011}$ is equal to $t(e_0,e_1,e_1)$:

In :
t(e,e,e)                    # t(e_0,e_1,e_1)

Out:
$\displaystyle 4$

### Module $T^{(k,0)}M$ of contravariant tensors of rank $k$¶

is the module of $k$-linear forms:

$$T^{(k,0)}M = \{t:\underbrace{M^*\times\cdots\times M^*}_{k\ \;\mbox{times}} \to R\}.$$

In $T^{(k,0)}M$ we introduce the module structure by

$$(at+bs)(\alpha_1\ldots,\alpha_k)=at(\alpha_1\ldots,\alpha_k)+bs(\alpha_1\ldots,\alpha_k),$$

where $t,s\in T^{(k,0)}M$, $\alpha_1,\ldots,\alpha_k\in M^*$ and $a,b\in R$.

For $t,s\in T^{(k,0)}M$ we define the tensor product $t\otimes s\$ by

\begin{equation} (t ⊗ s )(\alpha_1 ,\ldots , \alpha_{k+l} ) ≡ t (\alpha_1 ,\ldots, \alpha_k ) s(\alpha_{k+1} , \ldots , \alpha_{k+l} ), \tag{9.4a} \end{equation}

for $\alpha_1,\ldots,\alpha_{k+l}\in M^*$.

### Contravariant tensors in components¶

One can check that if $e_1,\ldots,e_n$ is a basis of the module $M$ and $e^1,\ldots,e^n$ its dual basis then the elements

$$e_{i_1}\otimes\ldots\otimes e_{i_k}, \quad i_p\in\{1,\ldots,n\}$$

form a basis for $T^{(k,0)}M$ and if we put

$$t^{i_1\ldots i_k} =t(e^{i_1},\ldots,e^{i_k}),$$

then

\begin{equation} t=t^{i_1\ldots i_k} e_{i_1}\otimes\ldots\otimes e_{i_k}, \quad \text{for }\ t\in T^{(k,0)}M. \tag{9.5a} \end{equation}

This follows from $\alpha(v)=\alpha(e^i(v)e_ i)=\alpha(e_i)e^i(v),\$ and $\ v(\alpha)=\alpha(v)$ for linear form $\ \alpha\in M^*\$ and $\ v\in M,\$since we have

$$t(\alpha_1,\ldots,\alpha_k)= t(\alpha_1(e_{i_1})e^{i_1},\ldots,\alpha_k(e_{i_k})e^{i_k})\\ =\alpha_1(e_{i_1})\ldots \alpha_k(e_{i_k})t(e^{i_1},\ldots,e^{i_k})\\ =e_{i_1}(\alpha_1)\ldots e_{i_k}(\alpha_k)t(e^{i_1},\ldots, e^{i_k})\\ =t^{i_1\ldots i_k} e_{i_1}\otimes \ldots \otimes e_{i_k}(\alpha_1,\ldots,\alpha_k).$$

Example 9.5a

Let us show the representation of a tensor of type (3,0) in components.

In :
%display latex
N=2                                      # dimension of module
st=[[[var('t'+str(i0)+str(i1)+str(i2),
latex_name='t'+'^'+'{'+str(i0)+str(i1)+str(i2)+'}')
for i2 in range(N)]
for i1 in range(N)]           # components of t
for i0 in range(N)]       # with superscripts
st                                       # show components

Out:
$\displaystyle \left[\left[\left[{t^{000}}, {t^{001}}\right], \left[{t^{010}}, {t^{011}}\right]\right], \left[\left[{t^{100}}, {t^{101}}\right], \left[{t^{110}}, {t^{111}}\right]\right]\right]$
In :
Mo=FiniteRankFreeModule(SR,2,name='Mo')  # module Mo
e = Mo.basis('e')                        # basis of Mo
t = Mo.tensor((3,0), name='t')           # tensor of (3,0) type
t[:]=st                                  # define all components


General tensor of type (3,0) on a 2-dimensional module:

In :
t.disp()                                 # show t

Out:
$\displaystyle t = {t^{000}} e_{0}\otimes e_{0}\otimes e_{0} + {t^{001}} e_{0}\otimes e_{0}\otimes e_{1} + {t^{010}} e_{0}\otimes e_{1}\otimes e_{0} + {t^{011}} e_{0}\otimes e_{1}\otimes e_{1} + {t^{100}} e_{1}\otimes e_{0}\otimes e_{0} + {t^{101}} e_{1}\otimes e_{0}\otimes e_{1} + {t^{110}} e_{1}\otimes e_{1}\otimes e_{0} + {t^{111}} e_{1}\otimes e_{1}\otimes e_{1}$

Tensor of type (3,0) on a 2-dimensional module with concrete components:

In :
# continuation
ct=range(1,9)            # [1,...,8]- consecutive components
for i0 in range(N):
for i1 in range(N):
for i2 in range(N):
t[i0,i1,i2]=ct[i0*N*N+i1*N+i2]
t.disp()

Out:
$\displaystyle t = e_{0}\otimes e_{0}\otimes e_{0} + 2 e_{0}\otimes e_{0}\otimes e_{1} + 3 e_{0}\otimes e_{1}\otimes e_{0} + 4 e_{0}\otimes e_{1}\otimes e_{1} + 5 e_{1}\otimes e_{0}\otimes e_{0} + 6 e_{1}\otimes e_{0}\otimes e_{1} + 7 e_{1}\otimes e_{1}\otimes e_{0} + 8 e_{1}\otimes e_{1}\otimes e_{1}$
In :
d=e.dual_basis()                        # dual basis
print(d)

Dual basis (e^0,e^1) on the 2-dimensional vector space Mo over the Symbolic Ring


Check that the coefficient $t^{011}$ is equal to $t( e^0,e^1, e^1)$:

In :
t(d,d,d)                       # t(e^0,e^1,e^1)

Out:
$\displaystyle 4$

### General tensors from $T^{(k,l)}M$ in components¶

For $t\in T^{(k_1,l_1)}M,\ \ s\in T^{(k_2,l_2)}M$ we define the tensor product $t\otimes s\in T^{(k_1+k_2,l_1+l_2)}$ by

\begin{equation} (t ⊗ s )(\alpha_1,\ldots\alpha_{k_1+k_2},v_1 ,\ldots , v_{l_1+l_2} )\\ =t(\alpha_1,\ldots,\alpha_{k_1},v_1 ,\ldots, v_{l_1} ) s (\alpha_{k_1+1},\ldots,\alpha_{k_1+k_2},v_{l_1+1},\ldots, v_{l_1+l_2} ), \tag{9.6a} \end{equation}

for $\alpha_1,\ldots,\alpha_{k_1+k_2}\in M^*$ and $v_1,\ldots,v_{l_1+l_2}\in M$.

Generalizing the formulas (9.3a) and (9.5a) we obtain the following expression for the general tensor $t\in T^{(k,l)}M$ in components

\begin{equation} t= t\big(e^{i_1},..,e^{i_k},e_{j_1},..,e_{j_l}) e_{i_1}\otimes\dots\otimes e_{i_k}\otimes e^{j_1}\otimes\ldots\otimes e^{j_l}. \label{}\tag{9.7a} \end{equation}

Very often the notation $$t^{i_1\ldots i_k}_{j_1\ldots j_l}=t_p\big(e^{i_1},..,e^{i_k},e_{j_1},..,e_{j_l})$$ is used and then $$t=t^{i_1\ldots i_k}_{j_1\ldots j_l}e_{i_1}\otimes\dots\otimes e_{i_k}\otimes e^{j_1}\otimes\ldots\otimes e^{j_l}.$$

To check that the elements \begin{equation} e_{i_1}\otimes\dots\otimes e_{i_k}\otimes e^{j_1}\otimes\ldots\otimes e^{j_l} \label{} \tag{9.8a} \end{equation}

are linearly independent, assume that the linear combination

$$a^{i_1\ldots i_k}_{j_1\ldots j_l}e_{i_1}\otimes\dots\otimes e_{i_k}\otimes e^{j_1}\otimes\ldots\otimes e^{j_l}$$

vanishes. If we apply this combination to $\quad(e^{m_1},\ldots,e^{m_k}, e_{n_1},..,e_{n_l}\big)$ we get $\displaystyle a^{m_1\ldots m_k}_{n_1\ldots n_l}=0$.
Since as in previous cases we can check that elements of the type (9.8a) span $T^{(k,l)}M$, we have proved that these elements form a basis for $T^{(k,l)}M$.

Example 9.6a

Now we show the representation of a tensor of (2,2) type in components.

In :
%display latex
N=2                                            # dimension of module
st=[[[[var('t'+str(i0)+str(i1)+str(i2)+str(i3),
latex_name='t'+'^'+'{'+str(i0)+str(i1)+'}'+'_'+
'{'+str(i2)+str(i3)+'}')
for i3 in range(N)] for i2 in range(N)]    # comp. with upper
for i1 in range(N)] for i0 in range(N)]  # and lower indices
st                                             # show components

Out:
$\displaystyle \left[\left[\left[\left[{t^{00}_{00}}, {t^{00}_{01}}\right], \left[{t^{00}_{10}}, {t^{00}_{11}}\right]\right], \left[\left[{t^{01}_{00}}, {t^{01}_{01}}\right], \left[{t^{01}_{10}}, {t^{01}_{11}}\right]\right]\right], \left[\left[\left[{t^{10}_{00}}, {t^{10}_{01}}\right], \left[{t^{10}_{10}}, {t^{10}_{11}}\right]\right], \left[\left[{t^{11}_{00}}, {t^{11}_{01}}\right], \left[{t^{11}_{10}}, {t^{11}_{11}}\right]\right]\right]\right]$
In :
Mo=FiniteRankFreeModule(SR,2,name='Mo')   # module Mo
e = Mo.basis('e')                         # basis of Mo
t = Mo.tensor((2,2), name='t')            # tensor of (2,2) type
t[:]=st                                   # define all components


General tensor from $T^{(2,2)}M$ on a 2-dimensional module ($2^4$ components):

In :
t.disp()                                  # show t

Out:
$\displaystyle t = {t^{00}_{00}} e_{0}\otimes e_{0}\otimes e^{0}\otimes e^{0} + {t^{00}_{01}} e_{0}\otimes e_{0}\otimes e^{0}\otimes e^{1} + {t^{00}_{10}} e_{0}\otimes e_{0}\otimes e^{1}\otimes e^{0} + {t^{00}_{11}} e_{0}\otimes e_{0}\otimes e^{1}\otimes e^{1} + {t^{01}_{00}} e_{0}\otimes e_{1}\otimes e^{0}\otimes e^{0} + {t^{01}_{01}} e_{0}\otimes e_{1}\otimes e^{0}\otimes e^{1} + {t^{01}_{10}} e_{0}\otimes e_{1}\otimes e^{1}\otimes e^{0} + {t^{01}_{11}} e_{0}\otimes e_{1}\otimes e^{1}\otimes e^{1} + {t^{10}_{00}} e_{1}\otimes e_{0}\otimes e^{0}\otimes e^{0} + {t^{10}_{01}} e_{1}\otimes e_{0}\otimes e^{0}\otimes e^{1} + {t^{10}_{10}} e_{1}\otimes e_{0}\otimes e^{1}\otimes e^{0} + {t^{10}_{11}} e_{1}\otimes e_{0}\otimes e^{1}\otimes e^{1} + {t^{11}_{00}} e_{1}\otimes e_{1}\otimes e^{0}\otimes e^{0} + {t^{11}_{01}} e_{1}\otimes e_{1}\otimes e^{0}\otimes e^{1} + {t^{11}_{10}} e_{1}\otimes e_{1}\otimes e^{1}\otimes e^{0} + {t^{11}_{11}} e_{1}\otimes e_{1}\otimes e^{1}\otimes e^{1}$

Here is a version with concrete components:

In :
ct=range(1,17)            # [1,..,16]-consecutive components
for i0 in range(N):
for i1 in range(N):
for i2 in range(N):
for i3 in range(N):
t[i0,i1,i2,i3]=ct[i0*N*N*N+i1*N*N+i2*N+i3]

In :
t.disp()

Out:
$\displaystyle t = e_{0}\otimes e_{0}\otimes e^{0}\otimes e^{0} + 2 e_{0}\otimes e_{0}\otimes e^{0}\otimes e^{1} + 3 e_{0}\otimes e_{0}\otimes e^{1}\otimes e^{0} + 4 e_{0}\otimes e_{0}\otimes e^{1}\otimes e^{1} + 5 e_{0}\otimes e_{1}\otimes e^{0}\otimes e^{0} + 6 e_{0}\otimes e_{1}\otimes e^{0}\otimes e^{1} + 7 e_{0}\otimes e_{1}\otimes e^{1}\otimes e^{0} + 8 e_{0}\otimes e_{1}\otimes e^{1}\otimes e^{1} + 9 e_{1}\otimes e_{0}\otimes e^{0}\otimes e^{0} + 10 e_{1}\otimes e_{0}\otimes e^{0}\otimes e^{1} + 11 e_{1}\otimes e_{0}\otimes e^{1}\otimes e^{0} + 12 e_{1}\otimes e_{0}\otimes e^{1}\otimes e^{1} + 13 e_{1}\otimes e_{1}\otimes e^{0}\otimes e^{0} + 14 e_{1}\otimes e_{1}\otimes e^{0}\otimes e^{1} + 15 e_{1}\otimes e_{1}\otimes e^{1}\otimes e^{0} + 16 e_{1}\otimes e_{1}\otimes e^{1}\otimes e^{1}$
In :
d=e.dual_basis()                      # dual basis


Check that the coefficient $t^{10}_{01}$ is equal to $t(e^1,e^0,e_0,e_1)$:

In :
t(d,d,e,e)                # t(e^1,e^0,e_0,e_1)

Out:
$\displaystyle 10$

## What's next?¶

Take a look at the notebook Tensors on $T_pM$.