{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tensors on free modules\n", "## A tutorial\n", "\n", "This worksheet provides some introduction to **tensors on free modules of finite rank**. This is a pure algebraic subpart of SageManifolds (version 1.0), which does not depend on other parts of SageManifolds and which has been integrated in SageMath 6.6.\n", "\n", "Click [here](https://raw.githubusercontent.com/sagemanifolds/SageManifolds/master/Worksheets/v1.0/SM_tensors_modules.ipynb) to download the worksheet file (ipynb format). To run it, you must start SageMath with the Jupyter notebook, via the command `sage -n jupyter`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First we set up the notebook to display mathematical objects using LaTeX rendering:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "%display latex" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Constructing a free module of finite rank\n", "\n", "Let $R$ be a commutative ring and $M$ a *free module of finite rank over* $R$, i.e. a module over $R$ that admits a *finite basis* (finite family of linearly independent generators). Since $R$ is commutative, it has the invariant basis number property: all bases of $M$ have the same cardinality, which is called the *rank of* $M$. In this tutorial, we consider a free module of rank 3 over the integer ring $\\mathbb{Z}$:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "M = FiniteRankFreeModule(ZZ, 3, name='M', start_index=1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The first two arguments are the ring and the rank; the third one is a string to denote the module and the last one defines the range of indices to be used for tensor components on the module: setting it to 1 means that indices will range in $\\{1,2,3\\}$. The default value is start_index=0.

\n", "

The function print returns a short description of the just constructed module:

" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "print(M)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

If we ask just for M,  the module's LaTeX symbol is returned (provided that the worksheet's Typeset box has been selected); by default, this is the same as the argument name in the constructor (this can be changed by providing the optional argument latex_name):

" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Rank-3 free module M over the Integer Ring" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Rank-3 free module M over the Integer Ring" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M1 = FiniteRankFreeModule(ZZ, 3, name='M', latex_name=r'\\mathcal{M}', start_index=1)\n", "M1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The indices of basis elements or tensor components on the module are generated by the method irange(), to be used in loops:

" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "2\n", "3\n" ] } ], "source": [ "for i in M.irange(): \n", " print(i)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

If the parameter start_index had not been specified, the default range of the indices would have been $\\{0,1,2\\}$ instead:

" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n" ] } ], "source": [ "M0 = FiniteRankFreeModule(ZZ, 3, name='M')\n", "for i in M0.irange():\n", " print(i)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

$M$ is the category of finite dimensional modules over $\\mathbb{Z}$:

" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Category of finite dimensional modules over Integer Ring\n" ] } ], "source": [ "print(M.category())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Self-inquiry commands are

" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Integer Ring" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.base_ring()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "3" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.rank()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Defining bases on the free module\n", "\n", "At construction, the free module $M$ has no pre-defined basis:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "No basis has been defined on the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "M.print_bases()" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.bases()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

For this reason, the class FiniteRankFreeModule does not inherit from Sage class CombinatorialFreeModule:

" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "False" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "isinstance(M, CombinatorialFreeModule)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and $M$ does not belong to the category of modules with a distinguished basis:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "False" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M in ModulesWithBasis(ZZ)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It simply belongs to the category of modules over $\\mathbb{Z}$:" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M in Modules(ZZ)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "More precisely, it belongs to the subcategory of finite dimensional modules over $\\mathbb{Z}$:" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M in Modules(ZZ).FiniteDimensional()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

We define a first basis on $M$ as follows:

" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Basis (e_1,e_2,e_3) on the Rank-3 free module M over the Integer Ring" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = M.basis('e') ; e" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Bases defined on the Rank-3 free module M over the Integer Ring:\n", " - (e_1,e_2,e_3) (default basis)\n" ] } ], "source": [ "M.print_bases()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The elements of the basis are accessed via their indices:

" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Element e_1 of the Rank-3 free module M over the Integer Ring" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e[1]" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Element e_1 of the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "print(e[1])" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e[1] in M" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Rank-3 free module M over the Integer Ring" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e[1].parent()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us introduce a second basis on the free module $M$ from a family of 3 linearly independent module elements:" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Basis (f_1,f_2,f_3) on the Rank-3 free module M over the Integer Ring\n" ] }, { "data": { "text/html": [ "" ], "text/plain": [ "Basis (f_1,f_2,f_3) on the Rank-3 free module M over the Integer Ring" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f = M.basis('f', from_family=(-e[1]+2*e[2]-4*e[3], e[2]+2*e[3], e[2]+3*e[3]))\n", "print(f) ; f" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We may ask to view each element of basis $f$ in terms of its expansion onto basis $e$, via the method `display()`, abridged as `disp()`:" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "f_1 = -e_1 + 2 e_2 - 4 e_3" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f[1].disp(e)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "f_2 = e_2 + 2 e_3" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f[2].disp(e)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "f_3 = e_2 + 3 e_3" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f[3].disp(e)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Conversely, the expression of basis $e$ is terms of basis $f$ is" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "e_1 = -f_1 + 10 f_2 - 8 f_3" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e[1].disp(f)" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "e_2 = 3 f_2 - 2 f_3" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e[2].disp(f)" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "e_3 = -f_2 + f_3" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e[3].disp(f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The module automorphism $a$ relating the two bases is obtained as" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Automorphism of the Rank-3 free module M over the Integer Ring" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = M.change_of_basis(e,f) ; a" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It belongs to the general linear group of the free module $M$:" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "General linear group of the Rank-3 free module M over the Integer Ring" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.parent()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

and its matrix w.r.t. basis $e$ is

" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[-1 0 0]\n", "[ 2 1 1]\n", "[-4 2 3]" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.matrix(e)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Let us check that the elements of basis $f$ are images of the elements of basis $e$ via $a$:

" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "(True, True, True)" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f[1] == a(e[1]), f[2] == a(e[2]), f[3] == a(e[3])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The reverse change of basis is of course the inverse automorphism:

" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.change_of_basis(f,e) == a^(-1)" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[-1 0 0]\n", "[10 3 -1]\n", "[-8 -2 1]" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(a^(-1)).matrix(f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "At this stage, two bases have been defined on $M$:" ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Bases defined on the Rank-3 free module M over the Integer Ring:\n", " - (e_1,e_2,e_3) (default basis)\n", " - (f_1,f_2,f_3)\n" ] } ], "source": [ "M.print_bases()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The first defined basis, $e$, is considered as the *default basis*, which means that it can be skipped in any method argument requirying a basis. For instance, let us consider the method `display()`:" ] }, { "cell_type": "code", "execution_count": 37, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "f_1 = -e_1 + 2 e_2 - 4 e_3" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f[1].display(e)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Since $e$ is the default basis, the above command is fully equivalent to

" ] }, { "cell_type": "code", "execution_count": 38, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "f_1 = -e_1 + 2 e_2 - 4 e_3" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f[1].display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Of course, the names of non-default bases have to be specified:

" ] }, { "cell_type": "code", "execution_count": 39, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "f_1 = f_1" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f[1].display(f)" ] }, { "cell_type": "code", "execution_count": 40, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "e_1 = -f_1 + 10 f_2 - 8 f_3" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e[1].display(f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Note that the concept of default basis is different from that of distinguished basis which is implemented in other free module constructions in Sage (e.g. CombinatorialFreeModule): the default basis is intended only for shorthand notations in user commands, avoiding to repeat the basis name many times; it is by no means a privileged basis on the module. For user convenience, the default basis can be changed at any moment by means of the method set_default_basis():

" ] }, { "cell_type": "code", "execution_count": 41, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "e_1 = -f_1 + 10 f_2 - 8 f_3" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.set_default_basis(f)\n", "e[1].display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Let us revert to $e$ as the default basis:

" ] }, { "cell_type": "code", "execution_count": 42, "metadata": { "collapsed": false }, "outputs": [], "source": [ "M.set_default_basis(e)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Module elements\n", "\n", "Elements of the free module $M$ are constructed by providing their components with respect to a given basis to the operator `()` acting on the module:" ] }, { "cell_type": "code", "execution_count": 43, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Element v of the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "v = M([3,-4,1], basis=e, name='v')\n", "print(v)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Since $e$ is the default basis, its mention can be skipped:

" ] }, { "cell_type": "code", "execution_count": 44, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Element v of the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "v = M([3,-4,1], name='v')\n", "print(v)" ] }, { "cell_type": "code", "execution_count": 45, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "v = 3 e_1 - 4 e_2 + e_3" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v.disp()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "While $v$ has been defined from the basis $e$, its expression in terms of the basis $f$ can be evaluated, thanks to the known relation between the two bases:" ] }, { "cell_type": "code", "execution_count": 46, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "v = -3 f_1 + 17 f_2 - 15 f_3" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v.disp(f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

According to Sage terminology, the parent of $v$ is of course $M$:

" ] }, { "cell_type": "code", "execution_count": 47, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Rank-3 free module M over the Integer Ring" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v.parent()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

We have also

" ] }, { "cell_type": "code", "execution_count": 48, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v in M" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us define a second module element, from the basis $f$ this time:" ] }, { "cell_type": "code", "execution_count": 49, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "u = -f_1 + 3 f_2 + 5 f_3" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u = M([-1,3,5], basis=f, name='u')\n", "u.disp(f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Another way to define module elements is of course via linear combinations:

" ] }, { "cell_type": "code", "execution_count": 50, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Element of the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "w = 2*e[1] - e[2] - 3*e[3]\n", "print(w)" ] }, { "cell_type": "code", "execution_count": 51, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "2 e_1 - e_2 - 3 e_3" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.disp()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As the result of a linear combination, $w$ has no name; it can be given one by the method `set_name()` and the LaTeX symbol can be specified if different from the name:" ] }, { "cell_type": "code", "execution_count": 52, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "w = 2 e_1 - e_2 - 3 e_3" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.set_name('w', latex_name=r'\\omega')\n", "w.disp()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Module operations are implemented, independently of the bases:

" ] }, { "cell_type": "code", "execution_count": 53, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Element of the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "s = u + 3*v\n", "print(s)" ] }, { "cell_type": "code", "execution_count": 54, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "10 e_1 - 6 e_2 + 28 e_3" ] }, "execution_count": 54, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s.disp()" ] }, { "cell_type": "code", "execution_count": 55, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "-10 f_1 + 54 f_2 - 40 f_3" ] }, "execution_count": 55, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s.disp(f)" ] }, { "cell_type": "code", "execution_count": 56, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Element u-v of the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "s = u - v\n", "print(s)" ] }, { "cell_type": "code", "execution_count": 57, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "u-v = -2 e_1 + 10 e_2 + 24 e_3" ] }, "execution_count": 57, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s.disp()" ] }, { "cell_type": "code", "execution_count": 58, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "u-v = 2 f_1 - 14 f_2 + 20 f_3" ] }, "execution_count": 58, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s.disp(f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The components of a module element with respect to a given basis are given by the method components():

" ] }, { "cell_type": "code", "execution_count": 59, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "1-index components w.r.t. Basis (f_1,f_2,f_3) on the Rank-3 free module M over the Integer Ring" ] }, "execution_count": 59, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v.components(f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

A shortcut is comp():

" ] }, { "cell_type": "code", "execution_count": 60, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 60, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v.comp(f) is v.components(f)" ] }, { "cell_type": "code", "execution_count": 61, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-3\n", "17\n", "-15\n" ] } ], "source": [ "for i in M.irange(): \n", " print(v.comp(f)[i])" ] }, { "cell_type": "code", "execution_count": 62, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[-3, 17, -15]" ] }, "execution_count": 62, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v.comp(f)[:]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The function display_comp() provides a list of components w.r.t. to a given basis:

" ] }, { "cell_type": "code", "execution_count": 63, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "v^1 = -3 \n", "v^2 = 17 \n", "v^3 = -15 " ] }, "execution_count": 63, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v.display_comp(f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

As a shortcut, instead of calling the method comp(), the basis can be provided as the first argument of the square bracket operator:

" ] }, { "cell_type": "code", "execution_count": 64, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "17" ] }, "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v[f,2]" ] }, { "cell_type": "code", "execution_count": 65, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[-3, 17, -15]" ] }, "execution_count": 65, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v[f,:]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

For the default basis, the basis can be omitted:

" ] }, { "cell_type": "code", "execution_count": 66, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[3, -4, 1]" ] }, "execution_count": 66, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v[:]" ] }, { "cell_type": "code", "execution_count": 67, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "-4" ] }, "execution_count": 67, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v[2]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

A specific module element is the zero one:

" ] }, { "cell_type": "code", "execution_count": 68, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Element zero of the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "print(M.zero())" ] }, { "cell_type": "code", "execution_count": 69, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[0, 0, 0]" ] }, "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.zero()[:]" ] }, { "cell_type": "code", "execution_count": 70, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[0, 0, 0]" ] }, "execution_count": 70, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.zero()[f,:]" ] }, { "cell_type": "code", "execution_count": 71, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v + M.zero() == v" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Linear forms\n", "\n", "Let us introduce some linear form on the free module $M$:" ] }, { "cell_type": "code", "execution_count": 72, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Linear form a on the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "a = M.linear_form('a')\n", "print(a)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$a$ is specified by its components with respect to the basis dual to $e$:" ] }, { "cell_type": "code", "execution_count": 73, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "a = 2 e^1 - e^2 + 3 e^3" ] }, "execution_count": 73, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a[:] = [2,-1,3]\n", "a.disp()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The notation $e^i$ stands for the elements of the basis dual to $e$, i.e. the basis of the dual module $M^*$ such that \n", "\n", "$$e^i(e_j) = \\delta^i_{\\ \\, j} $$\n", "\n", "Indeed" ] }, { "cell_type": "code", "execution_count": 74, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Dual basis (e^1,e^2,e^3) on the Rank-3 free module M over the Integer Ring" ] }, "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ed = e.dual_basis()\n", "ed" ] }, { "cell_type": "code", "execution_count": 75, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Linear form e^1 on the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "print(ed[1])" ] }, { "cell_type": "code", "execution_count": 76, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "(1, 0, 0)" ] }, "execution_count": 76, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ed[1](e[1]), ed[1](e[2]), ed[1](e[3])" ] }, { "cell_type": "code", "execution_count": 77, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "(0, 1, 0)" ] }, "execution_count": 77, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ed[2](e[1]), ed[2](e[2]), ed[2](e[3])" ] }, { "cell_type": "code", "execution_count": 78, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "(0, 0, 1)" ] }, "execution_count": 78, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ed[3](e[1]), ed[3](e[2]), ed[3](e[3])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The linear form $a$ can also be defined by its components with respect to the basis dual to $f$:" ] }, { "cell_type": "code", "execution_count": 79, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "a = 2 f^1 - f^2 + 3 f^3" ] }, "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a[f,:] = [2,-1,3]\n", "a.disp(f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For consistency, the previously defined components with respect to the basis dual to $e$ are automatically deleted and new ones are computed from the change-of-basis formula:" ] }, { "cell_type": "code", "execution_count": 80, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "a = -36 e^1 - 9 e^2 + 4 e^3" ] }, "execution_count": 80, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.disp()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

By definition, linear forms belong to the dual module:

" ] }, { "cell_type": "code", "execution_count": 81, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Dual of the Rank-3 free module M over the Integer Ring" ] }, "execution_count": 81, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.parent()" ] }, { "cell_type": "code", "execution_count": 82, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Dual of the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "print(a.parent())" ] }, { "cell_type": "code", "execution_count": 83, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 83, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.parent() is M.dual()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The dual module is itself a free module of the same rank as $M$:

" ] }, { "cell_type": "code", "execution_count": 84, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 84, "metadata": {}, "output_type": "execute_result" } ], "source": [ "isinstance(M.dual(), FiniteRankFreeModule)" ] }, { "cell_type": "code", "execution_count": 85, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "3" ] }, "execution_count": 85, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.dual().rank()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Linear forms map module elements to ring elements:

" ] }, { "cell_type": "code", "execution_count": 86, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "-68" ] }, "execution_count": 86, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a(v)" ] }, { "cell_type": "code", "execution_count": 87, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "10" ] }, "execution_count": 87, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a(u)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

in a linear way:

" ] }, { "cell_type": "code", "execution_count": 88, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 88, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a(u+2*v) == a(u) + 2*a(v)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Alternating forms

\n", "

Let us introduce a second linear form, $b$, on the free module $M$:

" ] }, { "cell_type": "code", "execution_count": 89, "metadata": { "collapsed": false }, "outputs": [], "source": [ "b = M.linear_form('b')\n", "b[:] = [-4,2,5]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

and take its exterior product with the linear form $a$:

" ] }, { "cell_type": "code", "execution_count": 90, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Alternating form a/\\b of degree 2 on the Rank-3 free module M over the Integer Ring\n" ] }, { "data": { "text/html": [ "" ], "text/plain": [ "Alternating form a/\\b of degree 2 on the Rank-3 free module M over the Integer Ring" ] }, "execution_count": 90, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c = a.wedge(b)\n", "print(c)\n", "c" ] }, { "cell_type": "code", "execution_count": 91, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "a/\\b = -108 e^1/\\e^2 - 164 e^1/\\e^3 - 53 e^2/\\e^3" ] }, "execution_count": 91, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c.disp()" ] }, { "cell_type": "code", "execution_count": 92, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "a/\\b = 12 f^1/\\f^2 + 70 f^1/\\f^3 - 53 f^2/\\f^3" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c.disp(f)" ] }, { "cell_type": "code", "execution_count": 93, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "8894" ] }, "execution_count": 93, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c(u,v)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

$c$ is antisymmetric:

" ] }, { "cell_type": "code", "execution_count": 94, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "-8894" ] }, "execution_count": 94, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c(v,u)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

and is multilinear:

" ] }, { "cell_type": "code", "execution_count": 95, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 95, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c(u+4*w,v) == c(u,v) + 4*c(w,v)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

We may check the standard formula for the exterior product of two linear forms:

" ] }, { "cell_type": "code", "execution_count": 96, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 96, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c(u,v) == a(u)*b(v) - b(u)*a(v)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

In terms of tensor product (denoted here by *), it reads

" ] }, { "cell_type": "code", "execution_count": 97, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 97, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c == a*b - b*a" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The parent of the alternating form $c$ is the second external power of the dual module $M^*$, which is denoted by $\\Lambda^2(M^*)$:

" ] }, { "cell_type": "code", "execution_count": 98, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "2nd exterior power of the dual of the Rank-3 free module M over the Integer Ring" ] }, "execution_count": 98, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c.parent()" ] }, { "cell_type": "code", "execution_count": 99, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2nd exterior power of the dual of the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "print(c.parent())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

$c$ is a tensor field of type $(0,2)$:

" ] }, { "cell_type": "code", "execution_count": 100, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "(0, 2)" ] }, "execution_count": 100, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c.tensor_type()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

whose components with respect to any basis are antisymmetric:

" ] }, { "cell_type": "code", "execution_count": 101, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ 0 -108 -164]\n", "[ 108 0 -53]\n", "[ 164 53 0]" ] }, "execution_count": 101, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c[:] # components with respect to the default basis (e)" ] }, { "cell_type": "code", "execution_count": 102, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ 0 12 70]\n", "[-12 0 -53]\n", "[-70 53 0]" ] }, "execution_count": 102, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c[f,:] # components with respect to basis f" ] }, { "cell_type": "code", "execution_count": 103, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Fully antisymmetric 2-indices components w.r.t. Basis (f_1,f_2,f_3) on the Rank-3 free module M over the Integer Ring" ] }, "execution_count": 103, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c.comp(f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

An alternating form can be constructed from scratch:

" ] }, { "cell_type": "code", "execution_count": 104, "metadata": { "collapsed": false }, "outputs": [], "source": [ "c1 = M.alternating_form(2) # 2 stands for the degree" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Only the non-zero and non-redundant components are to be defined (the others are deduced by antisymmetry); for the components with respect to the default basis, we write:

" ] }, { "cell_type": "code", "execution_count": 105, "metadata": { "collapsed": false }, "outputs": [], "source": [ "c1[1,2] = -108\n", "c1[1,3] = -164\n", "c1[2,3] = -53" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Then

" ] }, { "cell_type": "code", "execution_count": 106, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ 0 -108 -164]\n", "[ 108 0 -53]\n", "[ 164 53 0]" ] }, "execution_count": 106, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c1[:]" ] }, { "cell_type": "code", "execution_count": 107, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 107, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c1 == c" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Internally, only non-redundant components are stored, in a dictionary whose keys are the indices:

" ] }, { "cell_type": "code", "execution_count": 108, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "{(1, 2): -108, (1, 3): -164, (2, 3): -53}" ] }, "execution_count": 108, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c.comp(e)._comp" ] }, { "cell_type": "code", "execution_count": 109, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "{(1, 2): 12, (1, 3): 70, (2, 3): -53}" ] }, "execution_count": 109, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c.comp(f)._comp" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The other components are deduced by antisymmetry.

\n", "\n", "

The exterior product of a linear form with an alternating form of degree 2 leads to an alternating form of degree 3:

" ] }, { "cell_type": "code", "execution_count": 110, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Alternating form d/\\a/\\b of degree 3 on the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "d = M.linear_form('d')\n", "d[:] = [-1,-2,4]\n", "s = d.wedge(c)\n", "print(s)" ] }, { "cell_type": "code", "execution_count": 111, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "d/\\a/\\b = -707 e^1/\\e^2/\\e^3" ] }, "execution_count": 111, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s.disp()" ] }, { "cell_type": "code", "execution_count": 112, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "d/\\a/\\b = 707 f^1/\\f^2/\\f^3" ] }, "execution_count": 112, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s.disp(f)" ] }, { "cell_type": "code", "execution_count": 113, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "-707" ] }, "execution_count": 113, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s(e[1], e[2], e[3])" ] }, { "cell_type": "code", "execution_count": 114, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "707" ] }, "execution_count": 114, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s(f[1], f[2], f[3])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

$s$ is antisymmetric:

" ] }, { "cell_type": "code", "execution_count": 115, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "(-144228, 144228, -144228, 144228, -144228, 144228)" ] }, "execution_count": 115, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s(u,v,w), s(u,w,v), s(v,w,u), s(v,u,w), s(w,u,v), s(w,v,u)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Tensors\n", "$k$ and $l$ being non negative integers, a tensor of type $(k,l)$ on the free module $M$ is a multilinear map\n", "\n", "$$ t: \\underbrace{M^*\\times\\cdots\\times M^*}_{k\\ \\; \\mbox{times}}    \n", "\\times \\underbrace{M\\times\\cdots\\times M}_{l\\ \\; \\mbox{times}}\n", "\\longrightarrow R $$\n", "\n", "In the present case the ring $R$ is $\\mathbb{Z}$.\n", "\n", "For free modules of finite rank, we have the canonical isomorphism $M^{**} \\simeq M$, so that the set of all tensors of type $(k,l)$ can be identified with the tensor product\n", "\n", "$$ T^{(k,l)}(M) = \\underbrace{M\\otimes\\cdots\\otimes M}_{k\\ \\; \\mbox{times}}  \\otimes \\underbrace{M^*\\otimes\\cdots\\otimes M^*}_{l\\ \\; \\mbox{times}}$$\n", "\n", "In particular, tensors of type $(1,0)$ are identified with elements of $M$:" ] }, { "cell_type": "code", "execution_count": 116, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 116, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.tensor_module(1,0) is M" ] }, { "cell_type": "code", "execution_count": 117, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "(1, 0)" ] }, "execution_count": 117, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v.tensor_type()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

According to the above definition, linear forms are tensors of type (0,1):

" ] }, { "cell_type": "code", "execution_count": 118, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 118, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a in M.tensor_module(0,1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that, at the Python level, we do *not* have the identification of $T^{(0,1)}(M)$ with $M^*$:" ] }, { "cell_type": "code", "execution_count": 119, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "False" ] }, "execution_count": 119, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.tensor_module(0,1) is M.dual()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is because $T^{(0,1)}(M)$ and $M^*$ are different objects:" ] }, { "cell_type": "code", "execution_count": 120, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 120, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(M.tensor_module(0,1))" ] }, { "cell_type": "code", "execution_count": 121, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 121, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(M.dual())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

However, we have coercion (automatic conversion) of elements of $M^*$ into elements of $T^{(0,1)}(M)$:

" ] }, { "cell_type": "code", "execution_count": 122, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 122, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.tensor_module(0,1).has_coerce_map_from(M.dual())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

as well as coercion in the reverse direction:

" ] }, { "cell_type": "code", "execution_count": 123, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 123, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.dual().has_coerce_map_from(M.tensor_module(0,1))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Arbitrary tensors are constructed via the module method tensor(), by providing the tensor type $(k,l)$ and possibly the symbol to denote the tensor:

" ] }, { "cell_type": "code", "execution_count": 124, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Type-(1,1) tensor t on the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "t = M.tensor((1,1), name='t')\n", "print(t)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Let us set some component of $t$ in the basis $e$, for instance the component $t^1_{\\ \\, 2}$:

" ] }, { "cell_type": "code", "execution_count": 125, "metadata": { "collapsed": false }, "outputs": [], "source": [ "t[e,1,2] = -3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Since $e$ is the default basis, a shortcut for the above is

" ] }, { "cell_type": "code", "execution_count": 126, "metadata": { "collapsed": false }, "outputs": [], "source": [ "t[1,2] = -3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The unset components are zero:

" ] }, { "cell_type": "code", "execution_count": 127, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ 0 -3 0]\n", "[ 0 0 0]\n", "[ 0 0 0]" ] }, "execution_count": 127, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t[:]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Components can be set at any time:

" ] }, { "cell_type": "code", "execution_count": 128, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ 0 -3 0]\n", "[ 0 0 4]\n", "[ 0 0 0]" ] }, "execution_count": 128, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t[2,3] = 4\n", "t[:]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The components with respect to the basis $f$ are evaluated by the change-of-basis formula $e\\rightarrow f$:

" ] }, { "cell_type": "code", "execution_count": 129, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ 6 3 3]\n", "[-108 -6 6]\n", "[ 80 8 0]" ] }, "execution_count": 129, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t[f,:]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Another view of $t$, which reflects the fact that $T^{(1,1)}(M) = M\\otimes M^*$, is

" ] }, { "cell_type": "code", "execution_count": 130, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "t = -3 e_1*e^2 + 4 e_2*e^3" ] }, "execution_count": 130, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Recall that $(e^i)$ is the basis of $M^*$ that is dual to the basis $(e_i)$ of $M$.

\n", "

In term of the basis $(f_i)$ and its dual basis $(f^i)$, we have

" ] }, { "cell_type": "code", "execution_count": 131, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "t = 6 f_1*f^1 + 3 f_1*f^2 + 3 f_1*f^3 - 108 f_2*f^1 - 6 f_2*f^2 + 6 f_2*f^3 + 80 f_3*f^1 + 8 f_3*f^2" ] }, "execution_count": 131, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t.display(f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

As a tensor of type (1,1), $t$ maps pairs (linear form, module element) to ring elements:

" ] }, { "cell_type": "code", "execution_count": 132, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "-468" ] }, "execution_count": 132, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t(a,v)" ] }, { "cell_type": "code", "execution_count": 133, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Integer Ring" ] }, "execution_count": 133, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t(a,v).parent()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Tensors of type (1,1) can be considered as endomorphisms, thanks to the isomorphism\n", "\n", "$$ \\begin{array}{cccccc} \\mathrm{End}(M) & \\longrightarrow & T^{(1,1)}(M) \\\\ \\tilde t & \\longmapsto &  t: & M^*\\times M & \\longrightarrow & R \\\\&     & & (a,v) & \\longmapsto & a(\\tilde t(v)) \\end{array} $$\n" ] }, { "cell_type": "code", "execution_count": 134, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Generic endomorphism of Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "tt = End(M)(t)\n", "print(tt)" ] }, { "cell_type": "code", "execution_count": 135, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Set of Morphisms from Rank-3 free module M over the Integer Ring to Rank-3 free module M over the Integer Ring in Category of finite dimensional modules over Integer Ring" ] }, "execution_count": 135, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tt.parent()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

In a given basis, the matrix ${\\tilde t}^i_{\\ \\, j}$ of the endomorphism $\\tilde t$ is identical to the matrix of the tensor $t$:

" ] }, { "cell_type": "code", "execution_count": 136, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ 0 -3 0]\n", "[ 0 0 4]\n", "[ 0 0 0]" ] }, "execution_count": 136, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tt.matrix(e)" ] }, { "cell_type": "code", "execution_count": 137, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ 0 -3 0]\n", "[ 0 0 4]\n", "[ 0 0 0]" ] }, "execution_count": 137, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t[e,:]" ] }, { "cell_type": "code", "execution_count": 138, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 138, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tt.matrix(e) == t[e,:]" ] }, { "cell_type": "code", "execution_count": 139, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ 6 3 3]\n", "[-108 -6 6]\n", "[ 80 8 0]" ] }, "execution_count": 139, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tt.matrix(f)" ] }, { "cell_type": "code", "execution_count": 140, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ 6 3 3]\n", "[-108 -6 6]\n", "[ 80 8 0]" ] }, "execution_count": 140, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t[f,:]" ] }, { "cell_type": "code", "execution_count": 141, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 141, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tt.matrix(f) == t[f,:]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

As an endomorphism, $t$ maps module elements to module elements:

" ] }, { "cell_type": "code", "execution_count": 142, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Element t(v) of the Rank-3 free module M over the Integer Ring" ] }, "execution_count": 142, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tt(v)" ] }, { "cell_type": "code", "execution_count": 143, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Rank-3 free module M over the Integer Ring" ] }, "execution_count": 143, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tt(v).parent()" ] }, { "cell_type": "code", "execution_count": 144, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "t(v) = 12 e_1 + 4 e_2" ] }, "execution_count": 144, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tt(v).disp()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

$t$ belongs to the module $T^{(1,1)}(M)$:

" ] }, { "cell_type": "code", "execution_count": 145, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 145, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t in M.tensor_module(1,1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

or, in Sage terminology,

" ] }, { "cell_type": "code", "execution_count": 146, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 146, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t.parent() is M.tensor_module(1,1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

$T^{(1,1)}(M)$ is itself a free module of finite rank over $\\mathbb{Z}$:

" ] }, { "cell_type": "code", "execution_count": 147, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 147, "metadata": {}, "output_type": "execute_result" } ], "source": [ "isinstance(M.tensor_module(1,1), FiniteRankFreeModule)" ] }, { "cell_type": "code", "execution_count": 148, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Integer Ring" ] }, "execution_count": 148, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.tensor_module(1,1).base_ring()" ] }, { "cell_type": "code", "execution_count": 149, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "9" ] }, "execution_count": 149, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M.tensor_module(1,1).rank()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Tensor calculus

\n", "

In addition to the arithmetic operations inherent to the module structure of $T^{(k,l)}(M)$, the following operations are implemented:

\n", "\n", "\n", "

Tensor product

\n", "

The tensor product is formed with the * operator. For instance the tensor product $t\\otimes a$ is

" ] }, { "cell_type": "code", "execution_count": 150, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Type-(1,2) tensor t*a on the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "ta = t*a\n", "print(ta)" ] }, { "cell_type": "code", "execution_count": 151, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Type-(1,2) tensor t*a on the Rank-3 free module M over the Integer Ring" ] }, "execution_count": 151, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ta" ] }, { "cell_type": "code", "execution_count": 152, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "t*a = 108 e_1*e^2*e^1 + 27 e_1*e^2*e^2 - 12 e_1*e^2*e^3 - 144 e_2*e^3*e^1 - 36 e_2*e^3*e^2 + 16 e_2*e^3*e^3" ] }, "execution_count": 152, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ta.disp()" ] }, { "cell_type": "code", "execution_count": 153, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "t*a = 12 f_1*f^1*f^1 - 6 f_1*f^1*f^2 + 18 f_1*f^1*f^3 + 6 f_1*f^2*f^1 - 3 f_1*f^2*f^2 + 9 f_1*f^2*f^3 + 6 f_1*f^3*f^1 - 3 f_1*f^3*f^2 + 9 f_1*f^3*f^3 - 216 f_2*f^1*f^1 + 108 f_2*f^1*f^2 - 324 f_2*f^1*f^3 - 12 f_2*f^2*f^1 + 6 f_2*f^2*f^2 - 18 f_2*f^2*f^3 + 12 f_2*f^3*f^1 - 6 f_2*f^3*f^2 + 18 f_2*f^3*f^3 + 160 f_3*f^1*f^1 - 80 f_3*f^1*f^2 + 240 f_3*f^1*f^3 + 16 f_3*f^2*f^1 - 8 f_3*f^2*f^2 + 24 f_3*f^2*f^3" ] }, "execution_count": 153, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ta.disp(f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The components w.r.t. a given basis can also be displayed as an array:

" ] }, { "cell_type": "code", "execution_count": 154, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[[[0, 0, 0], [108, 27, -12], [0, 0, 0]],\n", " [[0, 0, 0], [0, 0, 0], [-144, -36, 16]],\n", " [[0, 0, 0], [0, 0, 0], [0, 0, 0]]]" ] }, "execution_count": 154, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ta[:] # components w.r.t. the default basis (e)" ] }, { "cell_type": "code", "execution_count": 155, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[[[12, -6, 18], [6, -3, 9], [6, -3, 9]],\n", " [[-216, 108, -324], [-12, 6, -18], [12, -6, 18]],\n", " [[160, -80, 240], [16, -8, 24], [0, 0, 0]]]" ] }, "execution_count": 155, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ta[f,:] # components w.r.t. basis f" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Each component ca be accessed individually:

" ] }, { "cell_type": "code", "execution_count": 156, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "-12" ] }, "execution_count": 156, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ta[1,2,3] # access to a component w.r.t. the default basis" ] }, { "cell_type": "code", "execution_count": 157, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "9" ] }, "execution_count": 157, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ta[f,1,2,3]" ] }, { "cell_type": "code", "execution_count": 158, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Free module of type-(1,2) tensors on the Rank-3 free module M over the Integer Ring" ] }, "execution_count": 158, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ta.parent()" ] }, { "cell_type": "code", "execution_count": 159, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 159, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ta in M.tensor_module(1,2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The tensor product is not commutative:

" ] }, { "cell_type": "code", "execution_count": 160, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Type-(1,2) tensor a*t on the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "print(a*t)" ] }, { "cell_type": "code", "execution_count": 161, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "False" ] }, "execution_count": 161, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a*t == t*a" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Forming a tensor of rank 4:

" ] }, { "cell_type": "code", "execution_count": 162, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Type-(2,2) tensor t*a*v on the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "tav = ta*v\n", "print(tav)" ] }, { "cell_type": "code", "execution_count": 163, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "t*a*v = 324 e_1*e_1*e^2*e^1 + 81 e_1*e_1*e^2*e^2 - 36 e_1*e_1*e^2*e^3 - 432 e_1*e_2*e^2*e^1 - 108 e_1*e_2*e^2*e^2 + 48 e_1*e_2*e^2*e^3 + 108 e_1*e_3*e^2*e^1 + 27 e_1*e_3*e^2*e^2 - 12 e_1*e_3*e^2*e^3 - 432 e_2*e_1*e^3*e^1 - 108 e_2*e_1*e^3*e^2 + 48 e_2*e_1*e^3*e^3 + 576 e_2*e_2*e^3*e^1 + 144 e_2*e_2*e^3*e^2 - 64 e_2*e_2*e^3*e^3 - 144 e_2*e_3*e^3*e^1 - 36 e_2*e_3*e^3*e^2 + 16 e_2*e_3*e^3*e^3" ] }, "execution_count": 163, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tav.disp()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Symmetrization / antisymmetrization

\n", "

The (anti)symmetrization of a tensor $t$ over $n$ arguments involve the division by $n!$, which does not always make sense in the base ring $R$. In the present case, $R=\\mathbb{Z}$ and to (anti)symmetrize over 2 arguments, we restrict to tensors with even components:

" ] }, { "cell_type": "code", "execution_count": 164, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ 0 2 0]\n", "[-4 8 0]\n", "[ 0 2 -6]" ] }, "execution_count": 164, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = M.tensor((0,2), name='g')\n", "g[1,2], g[2,1], g[2,2], g[3,2], g[3,3] = 2, -4, 8, 2, -6\n", "g[:]" ] }, { "cell_type": "code", "execution_count": 165, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Symmetric bilinear form on the Rank-3 free module M over the Integer Ring" ] }, "execution_count": 165, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s = g.symmetrize() ; s" ] }, { "cell_type": "code", "execution_count": 166, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "symmetry: (0, 1); no antisymmetry\n" ] } ], "source": [ "s.symmetries()" ] }, { "cell_type": "code", "execution_count": 167, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ 0 -1 0]\n", "[-1 8 1]\n", "[ 0 1 -6]" ] }, "execution_count": 167, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s[:]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Symmetrization can be performed on an arbitray number of arguments, by providing their positions (first position = 0). In the present case

" ] }, { "cell_type": "code", "execution_count": 168, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 168, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s == g.symmetrize(0,1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

One may use index notation to specify the symmetry:

" ] }, { "cell_type": "code", "execution_count": 169, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 169, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s == g['_(ab)']" ] }, { "cell_type": "code", "execution_count": 170, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 170, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s == g['_{(ab)}'] # LaTeX type notation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Of course, since $s$ is already symmetric:

" ] }, { "cell_type": "code", "execution_count": 171, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 171, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s.symmetrize() == s" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The antisymmetrization proceeds accordingly:

" ] }, { "cell_type": "code", "execution_count": 172, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Alternating form of degree 2 on the Rank-3 free module M over the Integer Ring" ] }, "execution_count": 172, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s = g.antisymmetrize() ; s" ] }, { "cell_type": "code", "execution_count": 173, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "no symmetry; antisymmetry: (0, 1)\n" ] } ], "source": [ "s.symmetries()" ] }, { "cell_type": "code", "execution_count": 174, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ 0 3 0]\n", "[-3 0 -1]\n", "[ 0 1 0]" ] }, "execution_count": 174, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s[:]" ] }, { "cell_type": "code", "execution_count": 175, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 175, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s == g.antisymmetrize(0,1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

As for symmetries, index notation can be used, instead of antisymmetrize():

" ] }, { "cell_type": "code", "execution_count": 176, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 176, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s == g['_[ab]']" ] }, { "cell_type": "code", "execution_count": 177, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 177, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s == g['_{[ab]}'] # LaTeX type notation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Of course, since $s$ is already antisymmetric:

" ] }, { "cell_type": "code", "execution_count": 178, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 178, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s == s.antisymmetrize()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Tensor contractions

\n", "

Contracting the type-(1,1) tensor $t$ with the module element $v$ results in another module element:

" ] }, { "cell_type": "code", "execution_count": 179, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Element of the Rank-3 free module M over the Integer Ring" ] }, "execution_count": 179, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t.contract(v)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The components (w.r.t. a given basis) of the contraction are of course $t^i_{\\\\  j} v^j$:

" ] }, { "cell_type": "code", "execution_count": 180, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 180, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t.contract(v)[i] == sum(t[i,j]*v[j] for j in M.irange())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

This contraction coincides with the action of $t$ as an endomorphism:

" ] }, { "cell_type": "code", "execution_count": 181, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 181, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t.contract(v) == tt(v)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Instead of contract(), index notations can be used to denote the contraction:

" ] }, { "cell_type": "code", "execution_count": 182, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 182, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t['^i_j']*v['j'] == t.contract(v)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Contracting the linear form $a$ with the module element $v$ results in a ring element:

" ] }, { "cell_type": "code", "execution_count": 183, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "-68" ] }, "execution_count": 183, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.contract(v)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

It is of course the result of the linear form acting on the module element:

" ] }, { "cell_type": "code", "execution_count": 184, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 184, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.contract(v) == a(v)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

By default, the contraction is performed on the last index of the first tensor and the first index of the second one. To perform contraction on other indices, one should specify the indices positions (with the convention position=0 for the first index): for instance to get the contraction $z^i_{\\ \\, j} = T^i_{\\ \\, kj} v^k$ (with $T=t\\otimes a$):

" ] }, { "cell_type": "code", "execution_count": 185, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Type-(1,1) tensor on the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "z = ta.contract(1,v) # 1 -> second index of ta\n", "print(z)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

To get $z^i_{\\ \\, jk} = t^l_{\\ \\, j} T^i_{\\ \\, l k}$:

" ] }, { "cell_type": "code", "execution_count": 186, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Type-(1,2) tensor on the Rank-3 free module M over the Integer Ring\n" ] } ], "source": [ "z = t.contract(0, ta, 1) # 0 -> first index of t, 1 -> second index of ta\n", "print(z)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

or, in terms of index notation:

" ] }, { "cell_type": "code", "execution_count": 187, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 187, "metadata": {}, "output_type": "execute_result" } ], "source": [ "z1 = t['^l_j']*ta['^i_lk']\n", "z1 == z" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

As for any function, inline documentation is obtained via the quotation mark:

" ] }, { "cell_type": "code", "execution_count": 188, "metadata": { "collapsed": false }, "outputs": [], "source": [ "t.contract?" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "SageMath 7.5.rc1", "language": "", "name": "sagemath" }, "language": "python", "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.12" } }, "nbformat": 4, "nbformat_minor": 0 }