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

Commit

Permalink
Merge branch 't/30291/scalar_field_arithmetics__trivial_cases' into t…
Browse files Browse the repository at this point in the history
…/30239/tensorfield___call___alters_zero
  • Loading branch information
Michael Jung committed Aug 5, 2020
2 parents cf4fce5 + 4f3b69f commit 9d8720d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/sage/manifolds/differentiable/chart.py
Expand Up @@ -488,7 +488,7 @@ def coframe(self):
sage: ey = c_xy.frame()[1] ; ey
Vector field d/dy on the 2-dimensional differentiable manifold M
sage: dx(ex).display()
dx(d/dx): M --> R
dx(d/dx): M --> R
(x, y) |--> 1
sage: dx(ey).display()
zero: M --> R
Expand Down
4 changes: 2 additions & 2 deletions src/sage/manifolds/differentiable/tensorfield.py
Expand Up @@ -4538,7 +4538,7 @@ def apply_map(self, fun, frame=None, chart=None,
sage: v.display(P.frame(), P)
(p^2 - q^2 - 2*p - 2*q) d/dp + (2*pi - 2*pi^2 - 2*(pi - pi^2)*p) d/dq
sage: v.display(P.frame(), X)
(x^2 - y^2) d/dp - 2*(pi - pi^2)*x d/dq
(x + y)*(x - y) d/dp + 2*pi*(pi - 1)*x d/dq
By default, the components of ``v`` in frames distinct from the
specified one have been deleted::
Expand All @@ -4553,7 +4553,7 @@ def apply_map(self, fun, frame=None, chart=None,
is effective in ``X.frame()`` as well::
sage: v.display(X.frame(), X)
(x^2 - y^2) d/dx - 2*(pi - pi^2)*x d/dy
(x + y)*(x - y) d/dx + 2*pi*(pi - 1)*x d/dy
When the requested operation does not change the value of the tensor
field, one can use the keyword argument ``keep_other_components=True``,
Expand Down
2 changes: 1 addition & 1 deletion src/sage/manifolds/local_frame.py
Expand Up @@ -119,7 +119,7 @@
Let us check that the coframe `(e^i)` is indeed the dual of the vector
frame `(e_i)`::
sage: e_dual[1](e[1]) # the linear form e^1 applied to the local section e_1
sage: e_dual[1](e[1]) # linear form e^1 applied to local section e_1
Scalar field e^1(e_1) on the Open subset U of the 3-dimensional topological
manifold M
sage: e_dual[1](e[1]).expr() # the explicit expression of e^1(e_1)
Expand Down
35 changes: 21 additions & 14 deletions src/sage/manifolds/scalarfield.py
Expand Up @@ -2508,10 +2508,10 @@ def _add_(self, other):
True
"""
# Special cases:
if self._is_zero:
# Trivial cases:
if self.is_trivial_zero():
return other
if other._is_zero:
if other.is_trivial_zero():
return self
# Generic case:
com_charts = self.common_charts(other)
Expand Down Expand Up @@ -2557,11 +2557,13 @@ def _sub_(self, other):
True
"""
# Special cases:
if self._is_zero:
# Trivial cases:
if self.is_trivial_zero():
return -other
if other._is_zero:
if other.is_trivial_zero():
return self
if self is other:
return self.parent().zero()
# Generic case:
com_charts = self.common_charts(other)
if com_charts is None:
Expand All @@ -2576,7 +2578,6 @@ def _sub_(self, other):
result._latex_name = self._latex_name + '-' + other._latex_name
return result


def _mul_(self, other):
r"""
Scalar field multiplication.
Expand Down Expand Up @@ -2609,12 +2610,16 @@ def _mul_(self, other):
True
"""
from sage.tensor.modules.format_utilities import (format_mul_txt,
format_mul_latex)
# Special cases:
if self._is_zero or other._is_zero:
# Trivial cases:
if self.is_trivial_zero() or other.is_trivial_zero():
return self._domain.zero_scalar_field()
if (self - 1).is_trivial_zero():
return other
if (other - 1).is_trivial_zero():
return self
# Generic case:
from sage.tensor.modules.format_utilities import (format_mul_txt,
format_mul_latex)
com_charts = self.common_charts(other)
if com_charts is None:
raise ValueError("no common chart for the multiplication")
Expand Down Expand Up @@ -2661,10 +2666,10 @@ def _div_(self, other):
"""
from sage.tensor.modules.format_utilities import format_mul_txt, \
format_mul_latex
# Special cases:
if other._is_zero:
# Trivial cases:
if other.is_trivial_zero():
raise ZeroDivisionError("division of a scalar field by zero")
if self._is_zero:
if self.is_trivial_zero():
return self._domain.zero_scalar_field()
# Generic case:
com_charts = self.common_charts(other)
Expand Down Expand Up @@ -2726,6 +2731,7 @@ def _lmul_(self, number):
True
"""
# Trivial cases:
try:
if number.is_trivial_zero():
return self.parent().zero()
Expand All @@ -2737,6 +2743,7 @@ def _lmul_(self, number):
return self.parent().zero()
if number == 1:
return self
# Generic case:
result = type(self)(self.parent())
if isinstance(number, Expression):
var = number.variables() # possible symbolic variables in number
Expand Down

0 comments on commit 9d8720d

Please sign in to comment.