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

Commit

Permalink
VectorFieldModule.tensor, VectorFieldFreeModule.tensor: Use CompWithS…
Browse files Browse the repository at this point in the history
…ym._canonicalize_sym_antisym
  • Loading branch information
Matthias Koeppe committed Sep 1, 2022
1 parent a1a3f36 commit 8a2c71a
Showing 1 changed file with 23 additions and 49 deletions.
72 changes: 23 additions & 49 deletions src/sage/manifolds/differentiable/vectorfield_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,11 @@ def tensor(self, tensor_type, name=None, latex_name=None, sym=None,
AutomorphismField
from sage.manifolds.differentiable.metric import (PseudoRiemannianMetric,
DegenerateMetric)
if tensor_type==(1,0):
from sage.tensor.modules.comp import CompWithSym
sym, antisym = CompWithSym._canonicalize_sym_antisym(
tensor_type[0] + tensor_type[1], sym, antisym,
trivial_symmetries='error')
if tensor_type == (1,0):
return self.element_class(self, name=name,
latex_name=latex_name)
elif tensor_type == (0,1):
Expand All @@ -783,31 +787,14 @@ def tensor(self, tensor_type, name=None, latex_name=None, sym=None,
return self.automorphism(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)
elif tensor_type==(0,2) and specific_type is not None:
tensor_type[0], name=name, latex_name=latex_name)
elif tensor_type == (0,2) and specific_type is not None:
if issubclass(specific_type, PseudoRiemannianMetric):
return self.metric(name, latex_name=latex_name)
# NB: the signature is not treated
Expand All @@ -816,9 +803,9 @@ def tensor(self, tensor_type, name=None, latex_name=None, sym=None,
return self.metric(name, latex_name=latex_name,
signature=(0, sign-1, 1))
# Generic case
return self.tensor_module(*tensor_type).element_class(self,
tensor_type, name=name, latex_name=latex_name,
sym=sym, antisym=antisym)
return self.tensor_module(*tensor_type).element_class(
self, tensor_type, name=name, latex_name=latex_name,
sym=sym, antisym=antisym)

def alternating_contravariant_tensor(self, degree, name=None,
latex_name=None):
Expand Down Expand Up @@ -2088,6 +2075,10 @@ def tensor(self, tensor_type, name=None, latex_name=None, sym=None,
AutomorphismField, AutomorphismFieldParal)
from sage.manifolds.differentiable.metric import (PseudoRiemannianMetric,
DegenerateMetric)
from sage.tensor.modules.comp import CompWithSym
sym, antisym = CompWithSym._canonicalize_sym_antisym(
tensor_type[0] + tensor_type[1], sym, antisym,
trivial_symmetries='error')
if tensor_type == (1,0):
return self.element_class(self, name=name,
latex_name=latex_name)
Expand All @@ -2098,31 +2089,14 @@ def tensor(self, tensor_type, name=None, latex_name=None, sym=None,
(AutomorphismField, AutomorphismFieldParal)):
return self.automorphism(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)
elif tensor_type==(0,2) and specific_type is not None:
tensor_type[0], name=name, latex_name=latex_name)
elif tensor_type == (0,2) and specific_type is not None:
if issubclass(specific_type, PseudoRiemannianMetric):
return self.metric(name, latex_name=latex_name)
# NB: the signature is not treated
Expand All @@ -2131,9 +2105,9 @@ def tensor(self, tensor_type, name=None, latex_name=None, sym=None,
return self.metric(name, latex_name=latex_name,
signature=(0, sign-1, 1))
# Generic case
return self.tensor_module(*tensor_type).element_class(self,
tensor_type, name=name, latex_name=latex_name,
sym=sym, antisym=antisym)
return self.tensor_module(*tensor_type).element_class(
self, tensor_type, name=name, latex_name=latex_name,
sym=sym, antisym=antisym)

def tensor_from_comp(self, tensor_type, comp, name=None,
latex_name=None):
Expand Down

0 comments on commit 8a2c71a

Please sign in to comment.