Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge #31276
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Aug 28, 2022
2 parents 134c44f + 3929d2e commit bc1dc24
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 @@ -2855,3 +2855,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 bc1dc24

Please sign in to comment.