Skip to content

Commit

Permalink
Trac #31276: Tensor Product Method for FiniteRankFreeModule
Browse files Browse the repository at this point in the history
We introduce the methods `tensor_product` and `tensor_power` as per
#30373.

Things that are probably nice to get to work:

{{{
sage: M = FiniteRankFreeModule(QQ, 2)
sage: M.tensor_product(M)
sage: M.tensor_product(M.tensor_module(1,2))
sage: M.tensor_module(1,2).tensor_product(M)
sage: M.tensor_module(1,1).tensor_product(M.tensor_module(1,2))
sage: M.tensor_power(3)
sage: M.tensor_module(1,2).tensor_power(3)
}}}

Not in this ticket: products between different underlying modules such
as:
{{{
sage: M = FiniteRankFreeModule(QQ, 2)
sage: N = FiniteRankFreeModule(QQ, 3)
sage: M.tensor_product(N)
sage: N.tensor_product(M.tensor_module(1,2))
sage: N.tensor_module(1,2).tensor_product(M)
sage: N.tensor_module(1,1).tensor_product(M.tensor_module(1,2))
}}}

URL: https://trac.sagemath.org/31276
Reported by: gh-mjungmath
Ticket author(s): Matthias Koeppe
Reviewer(s): Eric Gourgoulhon
  • Loading branch information
Release Manager committed Aug 28, 2022
2 parents 3091ae9 + 3929d2e commit 2c4005d
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/sage/tensor/modules/finite_rank_free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2857,3 +2857,68 @@ def identity_map(self, name='Id', latex_name=None):
latex_name = name
self._identity_map.set_name(name=name, latex_name=latex_name)
return self._identity_map

def base_module(self):
r"""
Return the free module on which ``self`` is constructed, namely ``self`` itself.
EXAMPLES::
sage: M = FiniteRankFreeModule(ZZ, 3, name='M')
sage: M.base_module() is M
True
"""
return self

def tensor_type(self):
r"""
Return the tensor type of ``self``, the pair `(1, 0)`.
EXAMPLES::
sage: M = FiniteRankFreeModule(ZZ, 3)
sage: M.tensor_type()
(1, 0)
"""
return (1, 0)

def tensor_power(self, n):
r"""
Return the ``n``-fold tensor product of ``self``.
EXAMPLES::
sage: M = FiniteRankFreeModule(QQ, 2)
sage: M.tensor_power(3)
Free module of type-(3,0) tensors on the 2-dimensional vector space over the Rational Field
sage: M.tensor_module(1,2).tensor_power(3)
Free module of type-(3,6) tensors on the 2-dimensional vector space over the Rational Field
"""
tensor_type = self.tensor_type()
return self.base_module().tensor_module(n * tensor_type[0], n * tensor_type[1])

def tensor_product(self, *others):
r"""
Return the tensor product of ``self`` and ``others``.
EXAMPLES::
sage: M = FiniteRankFreeModule(QQ, 2)
sage: M.tensor_product(M)
Free module of type-(2,0) tensors on the 2-dimensional vector space over the Rational Field
sage: M.tensor_product(M.tensor_module(1,2))
Free module of type-(2,2) tensors on the 2-dimensional vector space over the Rational Field
sage: M.tensor_module(1,2).tensor_product(M)
Free module of type-(2,2) tensors on the 2-dimensional vector space over the Rational Field
sage: M.tensor_module(1,1).tensor_product(M.tensor_module(1,2))
Free module of type-(2,3) tensors on the 2-dimensional vector space over the Rational Field
"""
from sage.modules.free_module_element import vector
base_module = self.base_module()
if not all(module.base_module() == base_module for module in others):
raise NotImplementedError('all factors must be tensor modules over the same base module')
tensor_type = sum(vector(module.tensor_type()) for module in [self] + list(others))
return base_module.tensor_module(*tensor_type)

0 comments on commit 2c4005d

Please sign in to comment.