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

Commit

Permalink
Minor changes in the zero and one treatment of tensor fields
Browse files Browse the repository at this point in the history
  • Loading branch information
egourgoulhon committed Oct 22, 2019
1 parent a91dba0 commit 2783253
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 47 deletions.
2 changes: 0 additions & 2 deletions src/sage/manifolds/differentiable/diff_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,6 @@ def wedge(self, other):
dest_map = self._vmodule._dest_map
dest_map_resu = dest_map.restrict(dom_resu,
subcodomain=ambient_dom_resu)
###
# Facilitate computations involving zero:
if resu_degree > ambient_dom_resu._dim:
return dom_resu.diff_form_module(resu_degree,
Expand All @@ -540,7 +539,6 @@ def wedge(self, other):
if self is other and (self._tensor_rank % 2) == 1:
return dom_resu.diff_form_module(resu_degree,
dest_map=dest_map_resu).zero()
###
# Generic case:
self_r = self.restrict(dom_resu)
other_r = other.restrict(dom_resu)
Expand Down
17 changes: 5 additions & 12 deletions src/sage/manifolds/differentiable/mixed_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ class MixedForm(AlgebraElement):
`\varphi: M \to N` between two differentiable manifolds `M` and `N`. More
precisely, a mixed form `a` along `\varphi: M \to N` can be considered as a
differentiable map
.. MATH::
a: M \longrightarrow \bigoplus^n_{k=0} T^{(0,k)}N,
where `T^{(0,k)}` denotes the tensor bundle of type `(0,k)`, `\bigoplus`
the Whitney sum and `n` the dimension of `N`, such that
.. MATH::
\forall x\in M, \quad a(x) \in \bigoplus^n_{k=0} \Lambda^k\left( T_{\varphi(x)}^* N \right),
where `\Lambda^k(T^*_{\varphi(x)} N)` is the `k`-th exterior power of the
dual of the tangent space `T_{\varphi(x)} N`.
Expand Down Expand Up @@ -656,13 +656,11 @@ def _add_(self, other):
True
"""
###
# Case zero:
if self._is_zero:
return other
if other._is_zero:
return self
###
# Generic case:
resu_comp = [self[j] + other[j]
for j in range(self._max_deg + 1)]
Expand Down Expand Up @@ -730,13 +728,11 @@ def _sub_(self, other):
True
"""
###
# Case zero:
if self._is_zero:
return -other
if other._is_zero:
return self
###
# Generic case:
resu_comp = [self[j] - other[j]
for j in range(self._max_deg + 1)]
Expand Down Expand Up @@ -851,17 +847,14 @@ def wedge(self, other):
A/\eta = [0] + [x*y dy] + [x*y dx/\dy] + [-y*z dx/\dy/\dz]
"""
###
# Case zero:
if self._is_zero or other._is_zero:
return self.parent().zero()
###
# Case one:
if self is self.parent().one():
return other
if other is self.parent().one():
return self
###
# Generic case:
resu_comp = [None] * (self._max_deg + 1)
resu_comp[0] = self[0] * other[0]
Expand Down Expand Up @@ -941,7 +934,7 @@ def exterior_derivative(self):
`\Omega^*(M,\varphi)`:
.. MATH::
\mathrm{d}: \Omega^*(M,\varphi) \to \Omega^*(M,\varphi).
OUTPUT:
Expand Down
2 changes: 0 additions & 2 deletions src/sage/manifolds/differentiable/multivector_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,6 @@ def zero(self):
manifold M
"""
zero = self.element_class(self._vmodule, self._degree,
name='zero', latex_name='0')
zero = self._element_constructor_(name='zero', latex_name='0')
for frame in self._domain._frames:
if self._dest_map.restrict(frame._domain) == frame._dest_map:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/manifolds/differentiable/tangent_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def __init__(self, point):
if frame is frame2:
basis = basis2
if basis is not None:
cauto = auto.add_comp(basis)
cauto = auto.add_comp(basis=basis)
for ind, val in comp._comp.items():
cauto._comp[ind] = val(point)
except ValueError:
Expand Down
11 changes: 2 additions & 9 deletions src/sage/manifolds/differentiable/tensorfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ def set_comp(self, basis=None):
basis = self._domain._def_frame
self._del_derived() # deletes the derived quantities
rst = self.restrict(basis._domain, dest_map=basis._dest_map)
return rst.set_comp(basis)
return rst.set_comp(basis=basis)

def _add_comp_unsafe(self, basis=None):
r"""
Expand Down Expand Up @@ -1342,7 +1342,7 @@ def add_comp(self, basis=None):
basis = self._domain._def_frame
self._del_derived() # deletes the derived quantities
rst = self.restrict(basis._domain, dest_map=basis._dest_map)
return rst.add_comp(basis)
return rst.add_comp(basis=basis)

def add_comp_by_continuation(self, frame, subdomain, chart=None):
r"""
Expand Down Expand Up @@ -2294,13 +2294,11 @@ def _add_(self, other):
True
"""
###
# Case zero:
if self._is_zero:
return other
if other._is_zero:
return self
###
# Generic case:
resu_rst = {}
for dom in self._common_subdomains(other):
Expand Down Expand Up @@ -2365,13 +2363,11 @@ def _sub_(self, other):
True
"""
###
# Case zero:
if self._is_zero:
return -other
if other._is_zero:
return self
###
# Generic case:
resu_rst = {}
for dom in self._common_subdomains(other):
Expand Down Expand Up @@ -2446,15 +2442,12 @@ def _rmul_(self, scalar):
True
"""
###
# Case zero:
if scalar._is_zero:
return self.parent().zero()
###
# Case one:
if scalar is self._domain._one_scalar_field:
return self
###
# Generic case:
resu = self._new_instance()
for dom, rst in self._restrictions.items():
Expand Down
4 changes: 2 additions & 2 deletions src/sage/manifolds/differentiable/tensorfield_paral.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ class :class:`~sage.tensor.modules.comp.Components`; if such
# deleted by _del_derived):
self._restrictions[basis._domain] = rst
# The set_comp operation is performed on the subdomain:
return rst.set_comp(basis)
return rst.set_comp(basis=basis)

def _add_comp_unsafe(self, basis=None):
r"""
Expand Down Expand Up @@ -1077,7 +1077,7 @@ class :class:`~sage.tensor.modules.comp.Components`; if such
# subdomains:
self._del_derived(del_restrictions=False)
# The add_comp operation is performed on the subdomain:
return rst.add_comp(basis)
return rst.add_comp(basis=basis)

def comp(self, basis=None, from_basis=None):
r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/manifolds/differentiable/vectorfield_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ def _element_constructor_(self, comp=[], basis=None, name=None,
"to a vector field in {}".format(self))
resu = self.element_class(self, name=name, latex_name=latex_name)
if comp != []:
resu.set_comp(basis)[:] = comp
resu.set_comp(basis=basis)[:] = comp
return resu

# Rem: _an_element_ is declared in the superclass FiniteRankFreeModule
Expand Down
2 changes: 1 addition & 1 deletion src/sage/manifolds/differentiable/vectorframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ def __init__(self, vector_field_module, symbol, latex_symbol=None,
xsd = sd._vector_field_modules[dest_map]
if not isinstance(xsd, FiniteRankFreeModule):
for t in xsd._tensor_modules.values():
t(0)._add_comp_unsafe(self)
t.zero()._add_comp_unsafe(self)
# (since new components are initialized to zero)
if dest_map is self._domain.identity_map():
# The frame is added to the list of the domain's covering frames:
Expand Down
16 changes: 8 additions & 8 deletions src/sage/manifolds/scalarfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -1673,23 +1673,23 @@ def set_expr(self, coord_expression, chart=None):
sage: f._express # the (u,v) expression has been lost:
{Chart (M, (x, y)): 3*y}
Since zero and one are special elements, their components cannot be
Since zero and one are special elements, their expressions cannot be
changed::
sage: z = M.zero_scalar_field()
sage: z.set_expr(3*y)
Traceback (most recent call last):
...
AssertionError: the components of the element zero cannot be changed
AssertionError: the expressions of the element zero cannot be changed
sage: one = M.one_scalar_field()
sage: one.set_expr(3*y)
Traceback (most recent call last):
...
AssertionError: the components of the element 1 cannot be changed
AssertionError: the expressions of the element 1 cannot be changed
"""
if self is self.parent().one() or self is self.parent().zero():
raise AssertionError("the components of the element "
raise AssertionError("the expressions of the element "
"{} cannot be changed".format(self._name))
if chart is None:
chart = self._domain._def_chart
Expand Down Expand Up @@ -1735,23 +1735,23 @@ def add_expr(self, coord_expression, chart=None):
sage: f._express # random (dict. output); f has now 2 expressions:
{Chart (M, (x, y)): 3*y, Chart (M, (u, v)): cos(u) - sin(v)}
Since zero and one are special elements, their components cannot be
Since zero and one are special elements, their expressions cannot be
changed::
sage: z = M.zero_scalar_field()
sage: z.add_expr(cos(u)-sin(v), c_uv)
Traceback (most recent call last):
...
AssertionError: the components of the element zero cannot be changed
AssertionError: the expressions of the element zero cannot be changed
sage: one = M.one_scalar_field()
sage: one.add_expr(cos(u)-sin(v), c_uv)
Traceback (most recent call last):
...
AssertionError: the components of the element 1 cannot be changed
AssertionError: the expressions of the element 1 cannot be changed
"""
if self is self.parent().one() or self is self.parent().zero():
raise AssertionError("the components of the element "
raise AssertionError("the expressions of the element "
"{} cannot be changed".format(self._name))
if chart is None:
chart = self._domain._def_chart
Expand Down
2 changes: 0 additions & 2 deletions src/sage/tensor/modules/free_module_alt_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,15 +614,13 @@ def wedge(self, other):
return self * other
fmodule = self._fmodule
rank_r = self._tensor_rank + other._tensor_rank
###
# Facilitate computations involving zero:
if rank_r > fmodule._rank:
return fmodule.dual_exterior_power(rank_r).zero()
if self._is_zero or other._is_zero:
return fmodule.dual_exterior_power(rank_r).zero()
if self is other and (self._tensor_rank % 2) == 1:
return fmodule.dual_exterior_power(rank_r).zero()
###
# Generic case:
basis = self.common_basis(other)
if basis is None:
Expand Down
8 changes: 4 additions & 4 deletions src/sage/tensor/modules/free_module_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,21 +601,21 @@ def __init__(self, fmodule, symbol, latex_symbol=None, indices=None,
# base module itself, since it is considered as a type-(1,0) tensor
# module):
for t in fmodule._tensor_modules.values():
t(0)._add_comp_unsafe(self)
t.zero()._add_comp_unsafe(self)
# (since new components are initialized to zero)
# Initialization of the components w.r.t the current basis of the zero
# elements of all exterior powers of the module and its dual
# constructed up to now:
for t in fmodule._exterior_powers.values():
t(0)._add_comp_unsafe(self)
t.zero()._add_comp_unsafe(self)
for t in fmodule._dual_exterior_powers.values():
t(0)._add_comp_unsafe(self)
t.zero()._add_comp_unsafe(self)
# Initialization of the components w.r.t. the current basis of the
# identity map of the general linear group:
if fmodule._general_linear_group is not None:
from .comp import KroneckerDelta
gl = fmodule._general_linear_group
gl(1)._components[self] = KroneckerDelta(fmodule._ring, self,
gl.one()._components[self] = KroneckerDelta(fmodule._ring, self,
start_index=fmodule._sindex,
output_formatter=fmodule._output_formatter)
# The dual basis:
Expand Down
11 changes: 8 additions & 3 deletions src/sage/tensor/modules/free_module_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ class being:
# *****************************************************************************
from __future__ import absolute_import

from sage.misc.cachefunc import cached_method
from sage.rings.integer import Integer
from sage.structure.element import ModuleElement
from sage.tensor.modules.comp import (Components, CompWithSym, CompFullySym,
Expand Down Expand Up @@ -2025,13 +2024,12 @@ def _add_(self, other):
"""
# No need for consistency check since self and other are guaranteed
# to belong to the same tensor module
###
#
# Case zero:
if self._is_zero:
return other
if other._is_zero:
return self
###
# Generic case:
basis = self.common_basis(other)
if basis is None:
Expand Down Expand Up @@ -2088,6 +2086,13 @@ def _sub_(self, other):
"""
# No need for consistency check since self and other are guaranted
# to belong to the same tensor module
#
# Case zero:
if self._is_zero:
return -other
if other._is_zero:
return self
# Generic case:
basis = self.common_basis(other)
if basis is None:
raise ValueError("no common basis for the subtraction")
Expand Down

0 comments on commit 2783253

Please sign in to comment.