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

Commit c104fc8

Browse files
author
Michael Jung
committed
Scalar field zero treatment
1 parent 2865535 commit c104fc8

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

src/sage/manifolds/differentiable/automorphismfield.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def _del_derived(self):
247247
# then deletes the inverse automorphism:
248248
self._inverse = None
249249

250-
def set_comp(self, basis=None, **kwargs):
250+
def set_comp(self, basis=None):
251251
r"""
252252
Return the components of ``self`` w.r.t. a given module basis for
253253
assignment.
@@ -319,7 +319,7 @@ class :class:`~sage.tensor.modules.comp.Components`; if such
319319
"changed")
320320
return TensorField._set_comp_unsafe(self, basis=basis)
321321

322-
def add_comp(self, basis=None, **kwargs):
322+
def add_comp(self, basis=None):
323323
r"""
324324
325325
Return the components of ``self`` w.r.t. a given module basis for

src/sage/manifolds/differentiable/tensorfield_paral.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ class :class:`~sage.tensor.modules.comp.Components`; if such
886886

887887
if basis._domain == self._domain:
888888
# Setting components on the tensor field domain:
889-
return FreeModuleTensor.set_comp(self, basis=basis, **kwargs)
889+
return FreeModuleTensor.set_comp(self, basis=basis)
890890

891891
# Setting components on a subdomain:
892892
#

src/sage/manifolds/scalarfield.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1673,12 +1673,29 @@ def set_expr(self, coord_expression, chart=None):
16731673
sage: f._express # the (u,v) expression has been lost:
16741674
{Chart (M, (x, y)): 3*y}
16751675
1676+
Since zero and one are special elements, their components cannot be
1677+
changed::
1678+
1679+
sage: z = M.zero_scalar_field()
1680+
sage: z.set_expr(3*y)
1681+
Traceback (most recent call last):
1682+
...
1683+
AssertionError: the components of the element zero cannot be changed
1684+
sage: one = M.one_scalar_field()
1685+
sage: one.set_expr(3*y)
1686+
Traceback (most recent call last):
1687+
...
1688+
AssertionError: the components of the element 1 cannot be changed
1689+
16761690
"""
1691+
if self is self.parent().one() or self is self.parent().zero():
1692+
raise AssertionError("the components of the element "
1693+
"{} cannot be changed".format(self._name))
16771694
if chart is None:
16781695
chart = self._domain._def_chart
1679-
self._is_zero = False # a priori
16801696
self._express.clear()
16811697
self._express[chart] = chart.function(coord_expression)
1698+
self._is_zero = False # a priori
16821699
self._del_derived()
16831700

16841701
def add_expr(self, coord_expression, chart=None):
@@ -1718,7 +1735,24 @@ def add_expr(self, coord_expression, chart=None):
17181735
sage: f._express # random (dict. output); f has now 2 expressions:
17191736
{Chart (M, (x, y)): 3*y, Chart (M, (u, v)): cos(u) - sin(v)}
17201737
1738+
Since zero and one are special elements, their components cannot be
1739+
changed::
1740+
1741+
sage: z = M.zero_scalar_field()
1742+
sage: z.add_expr(cos(u)-sin(v), c_uv)
1743+
Traceback (most recent call last):
1744+
...
1745+
AssertionError: the components of the element zero cannot be changed
1746+
sage: one = M.one_scalar_field()
1747+
sage: one.add_expr(cos(u)-sin(v), c_uv)
1748+
Traceback (most recent call last):
1749+
...
1750+
AssertionError: the components of the element 1 cannot be changed
1751+
17211752
"""
1753+
if self is self.parent().one() or self is self.parent().zero():
1754+
raise AssertionError("the components of the element "
1755+
"{} cannot be changed".format(self._name))
17221756
if chart is None:
17231757
chart = self._domain._def_chart
17241758
self._express[chart] = chart.function(coord_expression)

0 commit comments

Comments
 (0)