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

Commit

Permalink
TensorFreeSubmoduleBasis_comp._element_constructor_: Fix for zero; im…
Browse files Browse the repository at this point in the history
…plement retract
  • Loading branch information
Matthias Koeppe committed Aug 28, 2022
1 parent b0812b1 commit 8cd3cc4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
60 changes: 56 additions & 4 deletions src/sage/tensor/modules/tensor_free_submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ def __init__(self, fmodule, tensor_type, name=None, latex_name=None,
sage: e = M.basis('e')
sage: Sym0123x45M = TensorFreeSubmodule_comp(M, (6, 0), sym=((0, 1, 2, 3), (4, 5)))
sage: TestSuite(Sym0123x45M).run()
Traceback (most recent call last):
...
The following tests failed: _test_not_implemented_methods, _test_zero
"""
self._fmodule = fmodule
self._tensor_type = tuple(tensor_type)
Expand Down Expand Up @@ -260,7 +257,7 @@ def _element_constructor_(self, comp=[], basis=None, name=None,
sage: e = M.basis('e')
sage: T60M = M.tensor_module(6, 0)
sage: Sym0123x45M = TensorFreeSubmodule_comp(M, (6, 0), sym=((0, 1, 2, 3), (4, 5)))
sage: t = Sym0123x45M(e[0]*e[0]*e[0]*e[0]*e[1]*e[2]); t.disp()
sage: Sym0123x45M(e[0]*e[0]*e[0]*e[0]*e[1]*e[2])
Traceback (most recent call last):
...
ValueError: this tensor does not have the symmetries of
Expand Down Expand Up @@ -289,6 +286,10 @@ def _element_constructor_(self, comp=[], basis=None, name=None,
basis=basis, name=name,
latex_name=latex_name,
sym=sym, antisym=antisym)
if not symmetrized._components:
# zero tensor - methods symmetrize, antisymmetrize are broken
return resu

# TODO: Implement a fast symmetry check, either as part of the symmetrize method,
# or as a separate method
try:
Expand Down Expand Up @@ -367,3 +368,54 @@ def lift(self):
on the Rank-3 free module M over the Integer Ring
"""
return self.module_morphism(function=lambda x: x, codomain=self.ambient())

@lazy_attribute
def retract(self):
r"""
The retract map from the ambient space.
This is a partial map, which gives an error for elements not in the subspace.
Calling this map on elements of the ambient space is the same as calling the
element constructor of ``self``.
EXAMPLES::
sage: from sage.tensor.modules.tensor_free_submodule import TensorFreeSubmodule_comp
sage: M = FiniteRankFreeModule(ZZ, 3, name='M')
sage: e = M.basis('e')
sage: X = M.tensor_module(6, 0)
sage: Y = M.tensor_module(6, 0, sym=((0, 1, 2, 3), (4, 5)))
sage: e_Y = Y.basis('e')
sage: Y.retract
Generic morphism:
From: Free module of type-(6,0) tensors on the Rank-3 free module M over the Integer Ring
To: Free module of type-(6,0) tensors with 6-indices components w.r.t. (0, 1, 2),
with symmetry on the index positions (0, 1, 2, 3),
with symmetry on the index positions (4, 5)
on the Rank-3 free module M over the Integer Ring
sage: t = e[0]*e[0]*e[0]*e[0]*e[1]*e[2]; t.disp()
e_0⊗e_0⊗e_0⊗e_0⊗e_1⊗e_2 = e_0⊗e_0⊗e_0⊗e_0⊗e_1⊗e_2
sage: Y.retract(t)
Traceback (most recent call last):
...
ValueError: this tensor does not have the symmetries of
Free module of type-(6,0) tensors with 6-indices components w.r.t. (0, 1, 2),
with symmetry on the index positions (0, 1, 2, 3),
with symmetry on the index positions (4, 5)
on the Rank-3 free module M over the Integer Ring
sage: t = e[0]*e[0]*e[0]*e[0]*e[1]*e[2] + e[0]*e[0]*e[0]*e[0]*e[2]*e[1]
sage: y = Y.retract(t); y
Type-(6,0) tensor on the Rank-3 free module M over the Integer Ring
sage: y.disp()
e_0⊗e_0⊗e_0⊗e_0⊗e_1⊗e_2 + e_0⊗e_0⊗e_0⊗e_0⊗e_2⊗e_1
sage: y.parent()._name
'Sym^{0,1,2,3}(M)⊗Sym^{4,5}(M)'
TESTS::
sage: all(Y.retract(u.lift()) == u for u in e_Y)
True
"""
return self.ambient().module_morphism(function=lambda x: self(x), codomain=self)
5 changes: 0 additions & 5 deletions src/sage/tensor/modules/tensor_free_submodule_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,3 @@ def __getitem__(self, index):
element = tensor_module([])
element.set_comp(base_module_basis)[index] = 1
return element

# Todo:
# dual basis
# add test for dual
# lift/reduce/retract

0 comments on commit 8cd3cc4

Please sign in to comment.