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

Commit 451ebe5

Browse files
author
Matthias Koeppe
committed
src/sage/tensor/modules/finite_rank_free_module.py (FiniteRankFreeModule_abstract): Move tensor_power, tensor_product here from FiniteRankFreeModule
1 parent bc1dc24 commit 451ebe5

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

src/sage/tensor/modules/finite_rank_free_module.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,45 @@ def _latex_(self):
608608
else:
609609
return self._latex_name
610610

611+
def tensor_power(self, n):
612+
r"""
613+
Return the ``n``-fold tensor product of ``self``.
614+
615+
EXAMPLES::
616+
617+
sage: M = FiniteRankFreeModule(QQ, 2)
618+
sage: M.tensor_power(3)
619+
Free module of type-(3,0) tensors on the 2-dimensional vector space over the Rational Field
620+
sage: M.tensor_module(1,2).tensor_power(3)
621+
Free module of type-(3,6) tensors on the 2-dimensional vector space over the Rational Field
622+
"""
623+
tensor_type = self.tensor_type()
624+
return self.base_module().tensor_module(n * tensor_type[0], n * tensor_type[1])
625+
626+
def tensor_product(self, *others):
627+
r"""
628+
Return the tensor product of ``self`` and ``others``.
629+
630+
EXAMPLES::
631+
632+
sage: M = FiniteRankFreeModule(QQ, 2)
633+
sage: M.tensor_product(M)
634+
Free module of type-(2,0) tensors on the 2-dimensional vector space over the Rational Field
635+
sage: M.tensor_product(M.tensor_module(1,2))
636+
Free module of type-(2,2) tensors on the 2-dimensional vector space over the Rational Field
637+
sage: M.tensor_module(1,2).tensor_product(M)
638+
Free module of type-(2,2) tensors on the 2-dimensional vector space over the Rational Field
639+
sage: M.tensor_module(1,1).tensor_product(M.tensor_module(1,2))
640+
Free module of type-(2,3) tensors on the 2-dimensional vector space over the Rational Field
641+
642+
"""
643+
from sage.modules.free_module_element import vector
644+
base_module = self.base_module()
645+
if not all(module.base_module() == base_module for module in others):
646+
raise NotImplementedError('all factors must be tensor modules over the same base module')
647+
tensor_type = sum(vector(module.tensor_type()) for module in [self] + list(others))
648+
return base_module.tensor_module(*tensor_type)
649+
611650
def rank(self) -> int:
612651
r"""
613652
Return the rank of the free module ``self``.
@@ -2881,42 +2920,3 @@ def tensor_type(self):
28812920
28822921
"""
28832922
return (1, 0)
2884-
2885-
def tensor_power(self, n):
2886-
r"""
2887-
Return the ``n``-fold tensor product of ``self``.
2888-
2889-
EXAMPLES::
2890-
2891-
sage: M = FiniteRankFreeModule(QQ, 2)
2892-
sage: M.tensor_power(3)
2893-
Free module of type-(3,0) tensors on the 2-dimensional vector space over the Rational Field
2894-
sage: M.tensor_module(1,2).tensor_power(3)
2895-
Free module of type-(3,6) tensors on the 2-dimensional vector space over the Rational Field
2896-
"""
2897-
tensor_type = self.tensor_type()
2898-
return self.base_module().tensor_module(n * tensor_type[0], n * tensor_type[1])
2899-
2900-
def tensor_product(self, *others):
2901-
r"""
2902-
Return the tensor product of ``self`` and ``others``.
2903-
2904-
EXAMPLES::
2905-
2906-
sage: M = FiniteRankFreeModule(QQ, 2)
2907-
sage: M.tensor_product(M)
2908-
Free module of type-(2,0) tensors on the 2-dimensional vector space over the Rational Field
2909-
sage: M.tensor_product(M.tensor_module(1,2))
2910-
Free module of type-(2,2) tensors on the 2-dimensional vector space over the Rational Field
2911-
sage: M.tensor_module(1,2).tensor_product(M)
2912-
Free module of type-(2,2) tensors on the 2-dimensional vector space over the Rational Field
2913-
sage: M.tensor_module(1,1).tensor_product(M.tensor_module(1,2))
2914-
Free module of type-(2,3) tensors on the 2-dimensional vector space over the Rational Field
2915-
2916-
"""
2917-
from sage.modules.free_module_element import vector
2918-
base_module = self.base_module()
2919-
if not all(module.base_module() == base_module for module in others):
2920-
raise NotImplementedError('all factors must be tensor modules over the same base module')
2921-
tensor_type = sum(vector(module.tensor_type()) for module in [self] + list(others))
2922-
return base_module.tensor_module(*tensor_type)

0 commit comments

Comments
 (0)