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

Commit

Permalink
FiniteRankFreeModule.tensor: Use CompWithSym._canonicalize_sym_antisym
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Sep 1, 2022
1 parent d1a92e5 commit 319ecfa
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/sage/tensor/modules/finite_rank_free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ def tensor(self, tensor_type, name=None, latex_name=None, sym=None,
- ``latex_name`` -- (default: ``None``) string; LaTeX symbol to
denote the tensor; if none is provided, the LaTeX symbol is set
to ``name``
- ``sym`` -- (default: ``None``) a symmetry or a list of symmetries
- ``sym`` -- (default: ``None``) a symmetry or an iterable of symmetries
among the tensor arguments: each symmetry is described by a tuple
containing the positions of the involved arguments, with the
convention ``position = 0`` for the first argument. For instance:
Expand All @@ -1618,7 +1618,7 @@ def tensor(self, tensor_type, name=None, latex_name=None, sym=None,
* ``sym = [(0,2), (1,3,4)]`` for a symmetry between the 1st and 3rd
arguments and a symmetry between the 2nd, 4th and 5th arguments.
- ``antisym`` -- (default: ``None``) antisymmetry or list of
- ``antisym`` -- (default: ``None``) antisymmetry or iterable of
antisymmetries among the arguments, with the same convention
as for ``sym``
Expand Down Expand Up @@ -1653,33 +1653,20 @@ def tensor(self, tensor_type, name=None, latex_name=None, sym=None,
for more examples and documentation.
"""
from .comp import CompWithSym
sym, antisym = CompWithSym._canonicalize_sym_antisym(
tensor_type[0] + tensor_type[1], sym, antisym)
# Special cases:
if tensor_type == (1,0):
return self.element_class(self, name=name, latex_name=latex_name)
elif tensor_type == (0,1):
return self.linear_form(name=name, latex_name=latex_name)
elif tensor_type[0] == 0 and tensor_type[1] > 1 and antisym:
if isinstance(antisym[0], (int, Integer)):
# a single antisymmetry is provided as a tuple or a range
# object; it is converted to a 1-item list:
antisym = [tuple(antisym)]
if isinstance(antisym, (tuple, list)):
antisym0 = antisym[0]
else:
antisym0 = antisym
if len(antisym0) == tensor_type[1]:
if len(antisym[0]) == tensor_type[1]:
return self.alternating_form(tensor_type[1], name=name,
latex_name=latex_name)
elif tensor_type[0] > 1 and tensor_type[1] == 0 and antisym:
if isinstance(antisym[0], (int, Integer)):
# a single antisymmetry is provided as a tuple or a range
# object; it is converted to a 1-item list:
antisym = [tuple(antisym)]
if isinstance(antisym, (tuple, list)):
antisym0 = antisym[0]
else:
antisym0 = antisym
if len(antisym0) == tensor_type[0]:
if len(antisym[0]) == tensor_type[0]:
return self.alternating_contravariant_tensor(tensor_type[0],
name=name, latex_name=latex_name)
# Generic case:
Expand Down

0 comments on commit 319ecfa

Please sign in to comment.