summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTravis Scrimshaw <tscrimsh at umn.edu>2016-05-02 21:29:49 -0500
committerTravis Scrimshaw <tscrimsh at umn.edu>2016-05-02 21:29:49 -0500
commit0fd44d691614b07ffc2cb2ae63e6a00ed13a23e8 (patch)
treeb22447bdf0896f516be2fe6f0c35adb6c8671f80
parentMerge branch 'develop' into public/manifolds/top_manif_scalar_fields (diff)
Some cleanup and creating a parent for coordinate functions.
-rw-r--r--src/sage/manifolds/chart.py59
-rw-r--r--src/sage/manifolds/coord_func.py603
-rw-r--r--src/sage/manifolds/coord_func_symb.py502
-rw-r--r--src/sage/manifolds/scalarfield.py18
-rw-r--r--src/sage/manifolds/scalarfield_algebra.py4
5 files changed, 493 insertions, 693 deletions
diff --git a/src/sage/manifolds/chart.py b/src/sage/manifolds/chart.py
index 8be827d..4c074b8 100644
--- a/src/sage/manifolds/chart.py
+++ b/src/sage/manifolds/chart.py
@@ -312,22 +312,15 @@ class Chart(UniqueRepresentation, SageObject):
# subsets as keys
# The null and one functions of the coordinates:
base_field_type = self._domain.base_field_type()
- if base_field_type in ['real', 'complex']:
- self._zero_function = CoordFunctionSymb(self, 0)
- self._one_function = CoordFunctionSymb(self, 1)
- else:
- base_field = self._domain.base_field()
- self._zero_function = CoordFunctionSymb(self, base_field.zero())
- self._one_function = CoordFunctionSymb(self, base_field.one())
# Expression in self of the zero and one scalar fields of open sets
# containing the domain of self:
for dom in self._domain._supersets:
if hasattr(dom, '_zero_scalar_field'):
# dom is an open set
- dom._zero_scalar_field._express[self] = self._zero_function
+ dom._zero_scalar_field._express[self] = self.function_ring().zero()
if hasattr(dom, '_one_scalar_field'):
# dom is an open set
- dom._one_scalar_field._express[self] = self._one_function
+ dom._one_scalar_field._express[self] = self.function_ring().one()
def _init_coordinates(self, coord_list):
r"""
@@ -844,6 +837,20 @@ class Chart(UniqueRepresentation, SageObject):
transformations = [transformations]
return CoordChange(chart1, chart2, *transformations)
+ def function_ring(self):
+ """
+ Return the ring of coordinate functions on ``self``.
+
+ EXAMPLES::
+
+ sage: M = Manifold(2, 'M', structure='topological')
+ sage: X.<x,y> = M.chart()
+ sage: X.function_ring()
+ Ring of coordinate functions on Chart (M, (x, y))
+ """
+ from sage.manifolds.coord_func_symb import CoordFunctionSymbRing
+ return CoordFunctionSymbRing(self)
+
def function(self, expression):
r"""
Define a coordinate function to the base field.
@@ -896,7 +903,7 @@ class Chart(UniqueRepresentation, SageObject):
sage: f
sin(x*y)
sage: type(f)
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
+ <class 'sage.manifolds.coord_func_symb.CoordFunctionSymbRing_with_category.element_class'>
sage: f.display()
(x, y) |--> sin(x*y)
sage: f(2,3)
@@ -907,7 +914,7 @@ class Chart(UniqueRepresentation, SageObject):
raise NotImplementedError("numerical coordinate function not " +
"implemented yet")
else:
- return CoordFunctionSymb(self, expression)
+ return self.function_ring()(expression)
def zero_function(self):
r"""
@@ -942,7 +949,7 @@ class Chart(UniqueRepresentation, SageObject):
sage: X.zero_function().display()
(x, y) |--> 0
sage: type(X.zero_function())
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
+ <class 'sage.manifolds.coord_func_symb.CoordFunctionSymbRing_with_category.element_class'>
The result is cached::
@@ -961,7 +968,7 @@ class Chart(UniqueRepresentation, SageObject):
(x, y) |--> 0
"""
- return self._zero_function
+ return self.function_ring().zero()
def one_function(self):
r"""
@@ -996,7 +1003,7 @@ class Chart(UniqueRepresentation, SageObject):
sage: X.one_function().display()
(x, y) |--> 1
sage: type(X.one_function())
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
+ <class 'sage.manifolds.coord_func_symb.CoordFunctionSymbRing_with_category.element_class'>
The result is cached::
@@ -1015,23 +1022,24 @@ class Chart(UniqueRepresentation, SageObject):
(x, y) |--> 1 + O(5^20)
"""
- return self._one_function
+ return self.function_ring().one()
def multifunction(self, *expressions):
r"""
Define a coordinate function to some Cartesian power of the base field.
- If `n` and `m` are two positive integers and `(U,\varphi)` is a chart on
- a topological manifold `M` of dimension `n` over a topological field `K`,
- a *multi-coordinate function* associated to `(U,\varphi)` is a map
+ If `n` and `m` are two positive integers and `(U, \varphi)` is a
+ chart on a topological manifold `M` of dimension `n` over a
+ topological field `K`, a *multi-coordinate function* associated
+ to `(U,\varphi)` is a map
.. MATH::
\begin{array}{llcl}
f:& V \subset K^n & \longrightarrow & K^m \\
- & (x^1,\ldots,x^n) & \longmapsto & (f_1(x^1,\ldots,x^n),\ldots,
- f_m(x^1,\ldots,x^n)) ,
+ & (x^1, \ldots, x^n) & \longmapsto & (f_1(x^1, \ldots, x^n),
+ \ldots, f_m(x^1, \ldots, x^n)),
\end{array}
where `V` is the codomain of `\varphi`. In other words, `f` is a
@@ -1051,10 +1059,10 @@ class Chart(UniqueRepresentation, SageObject):
OUTPUT:
- - an instance of :class:`~sage.manifolds.coord_func.MultiCoordFunction`
+ - a :class:`~sage.manifolds.coord_func.MultiCoordFunction`
representing `f`
- EXAMPLE:
+ EXAMPLES:
Function of two coordinates with values in `\RR^3`::
@@ -1062,11 +1070,14 @@ class Chart(UniqueRepresentation, SageObject):
sage: X.<x,y> = M.chart()
sage: f = X.multifunction(x+y, sin(x*y), x^2 + 3*y); f
Coordinate functions (x + y, sin(x*y), x^2 + 3*y) on the Chart (M, (x, y))
- sage: type(f)
- <class 'sage.manifolds.coord_func.MultiCoordFunction'>
sage: f(2,3)
(5, sin(6), 13)
+ TESTS::
+
+ sage: type(f)
+ <class 'sage.manifolds.coord_func.MultiCoordFunction'>
+
"""
from sage.manifolds.coord_func import MultiCoordFunction
return MultiCoordFunction(self, expressions)
diff --git a/src/sage/manifolds/coord_func.py b/src/sage/manifolds/coord_func.py
index 84a65ca..8e54e20 100644
--- a/src/sage/manifolds/coord_func.py
+++ b/src/sage/manifolds/coord_func.py
@@ -40,16 +40,17 @@ AUTHORS:
#*****************************************************************************
from sage.misc.abstract_method import abstract_method
+from sage.misc.cachefunc import cached_method
+from sage.structure.element import AlgebraElement
from sage.structure.sage_object import SageObject
-from sage.misc.latex import latex
-class CoordFunction(SageObject):
+class CoordFunction(AlgebraElement):
r"""
Abstract base class for coordinate functions.
If `(U, \varphi)` is a chart on a topological manifold `M` of
dimension `n` over a topological field `K`, a *coordinate function*
- associated to `(U, \varphi)` is a map `f: V\subset K^n \to K`, where
+ associated to `(U, \varphi)` is a map `f: V \subset K^n \to K`, where
`V` is the codomain of `\varphi`. In other words, `f` is a `K`-valued
function of the coordinates associated to the chart `(U, \varphi)`.
@@ -64,20 +65,20 @@ class CoordFunction(SageObject):
the chart `(U, \varphi)`
"""
- def __init__(self, chart):
+ def __init__(self, parent):
r"""
- Base constructor for derived classes.
+ Initialize ``self``.
TEST::
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
"""
- self._chart = chart
- self._nc = len(chart[:]) # number of coordinates
+ AlgebraElement.__init__(self, parent)
+ self._nc = len(parent._chart[:]) # number of coordinates
# ----------------------------------------------------------------
# Methods that do not need to be re-implemented by derived classes
@@ -85,8 +86,7 @@ class CoordFunction(SageObject):
def chart(self):
r"""
- Return the chart with respect to which the coordinate function
- is defined.
+ Return the chart with respect to which ``self`` is defined.
OUTPUT:
@@ -103,15 +103,15 @@ class CoordFunction(SageObject):
True
"""
- return self._chart
+ return self.parent()._chart
def scalar_field(self, name=None, latex_name=None):
r"""
- Construct the scalar field that has the coordinate function as
+ Construct the scalar field that has ``self`` as
coordinate expression.
The domain of the scalar field is the open subset covered by the
- chart on which the coordinate function is defined.
+ chart on which ``self`` is defined.
INPUT:
@@ -139,10 +139,11 @@ class CoordFunction(SageObject):
True
"""
- alg = self._chart.domain().scalar_field_algebra()
- return alg.element_class(alg, coord_expression={self._chart: self},
+ alg = self.parent()._chart.domain().scalar_field_algebra()
+ return alg.element_class(alg, coord_expression={self.parent()._chart: self},
name=name, latex_name=latex_name)
+ # TODO: This should be abstract up to SageObject at some point - TCS
def __ne__(self, other):
r"""
Inequality operator.
@@ -171,240 +172,6 @@ class CoordFunction(SageObject):
"""
return not (self == other)
- def __radd__(self, other):
- r"""
- Reflected addition operator: performs ``other + self``.
-
- INPUT:
-
- - ``other`` -- a :class:`CoordFunction` or a value
-
- OUTPUT:
-
- - coordinate function resulting from the addition of ``self`` to
- ``other``
-
- TESTS::
-
- sage: M = Manifold(2, 'M', structure='topological')
- sage: X.<x,y> = M.chart()
- sage: f = X.function(x+y)
- sage: g = X.function(x*y)
- sage: f.__radd__(g)
- (x + 1)*y + x
- sage: f.__radd__(X.zero_function()) == f
- True
- sage: 2 + f # indirect doctest
- x + y + 2
-
- """
- return self.__add__(other) # since + is commutative
-
- def __iadd__(self, other):
- r"""
- In-place addition operator.
-
- INPUT:
-
- - ``other`` -- a :class:`CoordFunction` or a value
-
- OUTPUT:
-
- - coordinate function resulting from the addition of ``self`` and
- ``other``
-
- TESTS::
-
- sage: M = Manifold(2, 'M', structure='topological')
- sage: X.<x,y> = M.chart()
- sage: f = X.function(x+y)
- sage: g = X.function(x*y)
- sage: f.__iadd__(g)
- (x + 1)*y + x
- sage: f += g; f
- (x + 1)*y + x
- sage: f.__iadd__(X.zero_function()) == f
- True
-
- """
- return self.__add__(other)
-
- def __rsub__(self, other):
- r"""
- Reflected subtraction operator: performs ``other - self``.
-
- INPUT:
-
- - ``other`` -- a :class:`CoordFunction` or a value
-
- OUTPUT:
-
- - coordinate function resulting from the subtraction of ``self``
- from ``other``
-
- TESTS::
-
- sage: M = Manifold(2, 'M', structure='topological')
- sage: X.<x,y> = M.chart()
- sage: f = X.function(x+y)
- sage: g = X.function(x*y)
- sage: f.__rsub__(g)
- (x - 1)*y - x
- sage: f.__rsub__(g) == -f + g
- True
- sage: 2 - f # indirect doctest
- -x - y + 2
-
- """
- return self.__neg__().__add__(other)
-
- def __isub__(self, other):
- r"""
- In-place subtraction operator.
-
- INPUT:
-
- - ``other`` -- a :class:`CoordFunction` or a value
-
- OUTPUT:
-
- - coordinate function resulting from the subtraction of ``other``
- from ``self``
-
- TESTS::
-
- sage: M = Manifold(2, 'M', structure='topological')
- sage: X.<x,y> = M.chart()
- sage: f = X.function(x+y)
- sage: g = X.function(x*y)
- sage: f.__isub__(g)
- -(x - 1)*y + x
- sage: f -= g; f
- -(x - 1)*y + x
- sage: f.__isub__(X.zero_function()) == f
- True
-
- """
- return self.__sub__(other)
-
- def __rmul__(self, other):
- r"""
- Reflected multiplication operator: performs ``other * self``.
-
- INPUT:
-
- - ``other`` -- a :class:`CoordFunction` or a value
-
- OUTPUT:
-
- - coordinate function resulting from the multiplication of ``other``
- by ``self``
-
- TESTS::
-
- sage: M = Manifold(2, 'M', structure='topological')
- sage: X.<x,y> = M.chart()
- sage: f = X.function(x+y)
- sage: g = X.function(x*y)
- sage: f.__rmul__(g)
- x^2*y + x*y^2
- sage: f.__rmul__(g) == g*f
- True
- sage: f.__rmul__(X.one_function()) == f
- True
- sage: 2*f # indirect doctest
- 2*x + 2*y
-
- """
- return self.__mul__(other) # since * is commutative
-
- def __imul__(self, other):
- r"""
- In-place multiplication operator.
-
- INPUT:
-
- - ``other`` -- a :class:`CoordFunction` or a value
-
- OUTPUT:
-
- - coordinate function resulting from the multiplication of ``self``
- by ``other``
-
- TESTS::
-
- sage: M = Manifold(2, 'M', structure='topological')
- sage: X.<x,y> = M.chart()
- sage: f = X.function(x+y)
- sage: g = X.function(x*y)
- sage: f.__imul__(g)
- x^2*y + x*y^2
- sage: f *= g; f
- x^2*y + x*y^2
- sage: f.__imul__(X.one_function()) == f
- True
-
- """
- return self.__mul__(other)
-
- def __rdiv__(self, other):
- r"""
- Reflected division operator: performs ``other / self``.
-
- INPUT:
-
- - ``other`` -- a :class:`CoordFunction` or a value
-
- OUTPUT:
-
- - coordinate function resulting from the division of ``other``
- by ``self``
-
- TESTS::
-
- sage: M = Manifold(2, 'M', structure='topological')
- sage: X.<x,y> = M.chart()
- sage: f = X.function(x+y)
- sage: g = X.function(x*y)
- sage: f.__rdiv__(g)
- x*y/(x + y)
- sage: f.__rdiv__(g) == g/f
- True
- sage: 2/f # indirect doctest
- 2/(x + y)
-
- """
- return self.__invert__().__mul__(other)
-
- def __idiv__(self, other):
- r"""
- In-place division operator.
-
- INPUT:
-
- - ``other`` -- a :class:`CoordFunction` or a value
-
- OUTPUT:
-
- - coordinate function resulting from the division of ``self`` by
- ``other``
-
- TESTS::
-
- sage: M = Manifold(2, 'M', structure='topological')
- sage: X.<x,y> = M.chart()
- sage: f = X.function(x+y)
- sage: g = X.function(x*y)
- sage: f.__idiv__(g)
- (x + y)/(x*y)
- sage: f /= g; f
- (x + y)/(x*y)
- sage: f.__idiv__(X.one_function()) == f
- True
-
- """
- return self.__div__(other)
-
# --------------------------------------------
# Methods to be implemented by derived classes
# --------------------------------------------
@@ -422,11 +189,11 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f._repr_()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction._repr_ not implemented
+ NotImplementedError: <abstract method _repr_ at 0x...>
"""
@abstract_method
@@ -442,11 +209,11 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f._latex_()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction._latex_ not implemented
+ NotImplementedError: <abstract method _latex_ at 0x...>
"""
@abstract_method
@@ -462,11 +229,11 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.display()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.display not implemented
+ NotImplementedError: <abstract method display at 0x...>
"""
disp = display
@@ -489,11 +256,11 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.expr()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.expr not implemented
+ NotImplementedError: <abstract method expr at 0x...>
"""
@@ -522,11 +289,11 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.__call__(2,-3)
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.__call__ not implemented
+ NotImplementedError: <abstract method __call__ at 0x...>
"""
@@ -543,11 +310,11 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.is_zero()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.is_zero not implemented
+ NotImplementedError: <abstract method is_zero at 0x...>
"""
@@ -568,18 +335,19 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.copy()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.copy not implemented
+ NotImplementedError: <abstract method copy at 0x...>
"""
@abstract_method
def diff(self, coord):
r"""
- Partial derivative with respect to a coordinate.
+ Return the partial derivative of ``self`` with respect to a
+ coordinate.
INPUT:
@@ -602,93 +370,11 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.diff(x)
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.diff not implemented
-
- """
-
- @abstract_method
- def __eq__(self, other):
- r"""
- Comparison (equality) operator.
-
- INPUT:
-
- - ``other`` -- a :class:`CoordFunction` or a value
-
- OUTPUT:
-
- - ``True`` if ``self`` is equal to ``other``, or ``False`` otherwise
-
- TESTS:
-
- This method must be implemented by derived classes; it is not
- implemented here::
-
- sage: M = Manifold(2, 'M', structure='topological')
- sage: X.<x,y> = M.chart()
- sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
- sage: g = CoordFunction(X)
- sage: f == g
- Traceback (most recent call last):
- ...
- NotImplementedError: CoordFunction.__eq__ not implemented
-
- """
-
- def __pos__(self):
- r"""
- Unary plus operator.
-
- OUTPUT:
-
- - ``self``
-
- TESTS:
-
- Coordinate functions associated to a 2-dimensional chart::
-
- sage: M = Manifold(2, 'M', structure='topological')
- sage: X.<x,y> = M.chart()
- sage: f = X.function(x+y^2)
- sage: g = +f; g
- y^2 + x
- sage: type(g)
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
- sage: g == f
- True
- sage: g is f
- True
-
- """
- return self
-
- @abstract_method
- def __neg__(self):
- r"""
- Unary minus operator.
-
- OUTPUT:
-
- - the opposite of the coordinate function ``self``
-
- TESTS:
-
- This method must be implemented by derived classes; it is not
- implemented here::
-
- sage: M = Manifold(2, 'M', structure='topological')
- sage: X.<x,y> = M.chart()
- sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
- sage: f.__neg__()
- Traceback (most recent call last):
- ...
- NotImplementedError: CoordFunction.__neg__ not implemented
+ NotImplementedError: <abstract method diff at 0x...>
"""
@@ -704,7 +390,7 @@ class CoordFunction(SageObject):
OUTPUT:
- - the inverse of the coordinate function ``self``
+ - the inverse of ``self``
TESTS:
@@ -714,16 +400,16 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.__invert__()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.__invert__ not implemented
+ NotImplementedError: <abstract method __invert__ at 0x...>
"""
@abstract_method
- def __add__(self, other):
+ def _add_(self, other):
r"""
Addition operator.
@@ -744,16 +430,16 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
- sage: f.__add__(2)
+ sage: f = CoordFunction(X.function_ring())
+ sage: f._add_(2)
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.__add__ not implemented
+ NotImplementedError: <abstract method _add_ at 0x...>
"""
@abstract_method
- def __sub__(self, other):
+ def _sub_(self, other):
r"""
Subtraction operator.
@@ -774,16 +460,16 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
- sage: f.__sub__(2)
+ sage: f = CoordFunction(X.function_ring())
+ sage: f._sub_(2)
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.__sub__ not implemented
+ NotImplementedError: <abstract method _sub_ at 0x...>
"""
@abstract_method
- def __mul__(self, other):
+ def _mul_(self, other):
r"""
Multiplication operator.
@@ -804,16 +490,16 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
- sage: f.__mul__(2)
+ sage: f = CoordFunction(X.function_ring())
+ sage: f._mul_(2)
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.__mul__ not implemented
+ NotImplementedError: <abstract method _mul_ at 0x...>
"""
@abstract_method
- def __div__(self, other):
+ def _div_(self, other):
r"""
Division operator.
@@ -834,18 +520,18 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
- sage: f.__div__(2)
+ sage: f = CoordFunction(X.function_ring())
+ sage: f._div_(2)
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.__div__ not implemented
+ NotImplementedError: <abstract method _div_ at 0x...>
"""
@abstract_method
def exp(self):
r"""
- Exponential of the coordinate function.
+ Exponential of ``self``.
OUTPUT:
@@ -860,18 +546,18 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.exp()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.exp not implemented
+ NotImplementedError: <abstract method exp at 0x...>
"""
@abstract_method
def log(self, base=None):
r"""
- Logarithm of the coordinate function.
+ Logarithm of ``self``.
INPUT:
@@ -891,18 +577,18 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.log()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.log not implemented
+ NotImplementedError: <abstract method log at 0x...>
"""
@abstract_method
def __pow__(self, exponent):
r"""
- Power of the coordinate function.
+ Power of ``self``.
INPUT:
@@ -921,18 +607,18 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.__pow__(2)
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.__pow__ not implemented
+ NotImplementedError: <abstract method __pow__ at 0x...>
"""
@abstract_method
def sqrt(self):
r"""
- Square root of the coordinate function.
+ Square root of ``self``.
OUTPUT:
@@ -947,18 +633,18 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.sqrt()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.sqrt not implemented
+ NotImplementedError: <abstract method sqrt at 0x...>
"""
@abstract_method
def cos(self):
r"""
- Cosine of the coordinate function.
+ Cosine of ``self``.
OUTPUT:
@@ -973,18 +659,18 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.cos()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.cos not implemented
+ NotImplementedError: <abstract method cos at 0x...>
"""
@abstract_method
def sin(self):
r"""
- Sine of the coordinate function.
+ Sine of ``self``.
OUTPUT:
@@ -999,18 +685,18 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.sin()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.sin not implemented
+ NotImplementedError: <abstract method sin at 0x...>
"""
@abstract_method
def tan(self):
r"""
- Tangent of the coordinate function.
+ Tangent of ``self``.
OUTPUT:
@@ -1025,18 +711,18 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.tan()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.tan not implemented
+ NotImplementedError: <abstract method tan at 0x...>
"""
@abstract_method
def arccos(self):
r"""
- Arc cosine of the coordinate function.
+ Arc cosine of ``self``.
OUTPUT:
@@ -1051,18 +737,18 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.arccos()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.arccos not implemented
+ NotImplementedError: <abstract method arccos at 0x...>
"""
@abstract_method
def arcsin(self):
r"""
- Arc sine of the coordinate function.
+ Arc sine of ``self``.
OUTPUT:
@@ -1077,18 +763,18 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.arcsin()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.arcsin not implemented
+ NotImplementedError: <abstract method arcsin at 0x...>
"""
@abstract_method
def arctan(self):
r"""
- Arc tangent of the coordinate function.
+ Arc tangent of ``self``.
OUTPUT:
@@ -1103,18 +789,18 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.arctan()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.arctan not implemented
+ NotImplementedError: <abstract method arctan at 0x...>
"""
@abstract_method
def cosh(self):
r"""
- Hyperbolic cosine of the coordinate function.
+ Hyperbolic cosine of ``self``.
OUTPUT:
@@ -1129,18 +815,18 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.cosh()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.cosh not implemented
+ NotImplementedError: <abstract method cosh at 0x...>
"""
@abstract_method
def sinh(self):
r"""
- Hyperbolic sine of the coordinate function.
+ Hyperbolic sine of ``self``.
OUTPUT:
@@ -1155,18 +841,18 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.sinh()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.sinh not implemented
+ NotImplementedError: <abstract method sinh at 0x...>
"""
@abstract_method
def tanh(self):
r"""
- Hyperbolic tangent of the coordinate function.
+ Hyperbolic tangent of ``self``.
OUTPUT:
@@ -1181,18 +867,18 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.tanh()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.tanh not implemented
+ NotImplementedError: <abstract method tanh at 0x...>
"""
@abstract_method
def arccosh(self):
r"""
- Inverse hyperbolic cosine of the coordinate function.
+ Inverse hyperbolic cosine of ``self``.
OUTPUT:
@@ -1207,18 +893,18 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.arccosh()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.arccosh not implemented
+ NotImplementedError: <abstract method arccosh at 0x...>
"""
@abstract_method
def arcsinh(self):
r"""
- Inverse hyperbolic sine of the coordinate function.
+ Inverse hyperbolic sine of ``self``.
OUTPUT:
@@ -1233,18 +919,18 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.arcsinh()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.arcsinh not implemented
+ NotImplementedError: <abstract method arcsinh at 0x...>
"""
@abstract_method
def arctanh(self):
r"""
- Inverse hyperbolic tangent of the coordinate function.
+ Inverse hyperbolic tangent of ``self``.
OUTPUT:
@@ -1259,11 +945,11 @@ class CoordFunction(SageObject):
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: from sage.manifolds.coord_func import CoordFunction
- sage: f = CoordFunction(X)
+ sage: f = CoordFunction(X.function_ring())
sage: f.arctanh()
Traceback (most recent call last):
...
- NotImplementedError: CoordFunction.arctanh not implemented
+ NotImplementedError: <abstract method arctanh at 0x...>
"""
@@ -1343,7 +1029,7 @@ class MultiCoordFunction(SageObject):
:class:`~sage.manifolds.coord_func_symb.CoordFunctionSymb`::
sage: type(f[0])
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
+ <class 'sage.manifolds.coord_func_symb.CoordFunctionSymbRing_with_category.element_class'>
A class :class:`MultiCoordFunction` can represent a
real-valued function (case `m = 1`), although one should
@@ -1368,7 +1054,7 @@ class MultiCoordFunction(SageObject):
"""
def __init__(self, chart, expressions):
r"""
- Construct a multi-coordinate function.
+ Initialize ``self``.
TESTS::
@@ -1386,13 +1072,10 @@ class MultiCoordFunction(SageObject):
self._nf = len(expressions) # number of functions
self._functions = tuple(chart.function(express)
for express in expressions)
- # Derived quantities:
- self._jacob = None
- self._jacob_det = None
def _repr_(self):
r"""
- String representation of the object.
+ String representation of ``self``.
TESTS::
@@ -1419,15 +1102,16 @@ class MultiCoordFunction(SageObject):
sage: f = X.multifunction(x-y, x*y, cos(x)*exp(y))
sage: f._latex_()
\left(x - y, x y, \cos\left(x\right) e^{y}\right)
- sage: latex(f) # indirect doctest
+ sage: latex(f)
\left(x - y, x y, \cos\left(x\right) e^{y}\right)
"""
+ from sage.misc.latex import latex
return latex(self._functions)
def expr(self):
r"""
- Return a tuple of data, the item no. `i` begin sufficient to
+ Return a tuple of data, the item no.`i` begin sufficient to
reconstruct the coordinate function no. `i`.
In other words, if ``f`` is a multi-coordinate function, then
@@ -1458,8 +1142,7 @@ class MultiCoordFunction(SageObject):
def chart(self):
r"""
- Return the chart with respect to which the multi-coordinate
- function is defined.
+ Return the chart with respect to which ``self`` is defined.
OUTPUT:
@@ -1582,15 +1265,15 @@ class MultiCoordFunction(SageObject):
INPUT:
- - ``*coords`` -- list of coordinates where the functions are to be
- evaluated
- - ``**options`` -- allows to pass some options, like
+ - ``*coords`` -- list of coordinates where the functions are
+ to be evaluated
+ - ``**options`` -- allows to pass some options, e.g.,
``simplify=False`` to disable simplification for symbolic
coordinate functions
OUTPUT:
- - tuple containing the values of the `m` functions.
+ - tuple containing the values of the `m` functions
TESTS::
@@ -1607,21 +1290,23 @@ class MultiCoordFunction(SageObject):
"""
return tuple(func(*coords, **options) for func in self._functions)
+ @cached_method
def jacobian(self):
r"""
Return the Jacobian matrix of the system of coordinate functions.
``jacobian()`` is a 2-dimensional array of size `m \times n`,
- where `m` is the number of functions and `n` the number of coordinates,
- the generic element being `J_{ij} = \frac{\partial f_i}{\partial x^j}`
- with `1 \leq i \leq m` (row index) and `1 \leq j \leq n`
- (column index).
+ where `m` is the number of functions and `n` the number of
+ coordinates, the generic element being
+ `J_{ij} = \frac{\partial f_i}{\partial x^j}` with `1 \leq i \leq m`
+ (row index) and `1 \leq j \leq n` (column index).
OUTPUT:
- - Jacobian matrix as a 2-dimensional array ``J`` of coordinate functions,
- ``J[i-1][j-1]`` being `J_{ij} = \frac{\partial f_i}{\partial x^j}`
- for `1\leq i \leq m` and `1\leq j \leq n`
+ - Jacobian matrix as a 2-dimensional array ``J`` of
+ coordinate functions with ``J[i-1][j-1]`` being
+ `J_{ij} = \frac{\partial f_i}{\partial x^j}`
+ for `1 \leq i \leq m` and `1 \leq j \leq n`
EXAMPLES:
@@ -1631,19 +1316,21 @@ class MultiCoordFunction(SageObject):
sage: X.<x,y> = M.chart()
sage: f = X.multifunction(x-y, x*y, y^3*cos(x))
sage: f.jacobian()
- [[1, -1], [y, x], [-y^3*sin(x), 3*y^2*cos(x)]]
+ [ 1 -1]
+ [ y x]
+ [ -y^3*sin(x) 3*y^2*cos(x)]
Each element of the result is a
:class:`coordinate function <CoordFunction>`::
- sage: type(f.jacobian()[2][0])
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
- sage: f.jacobian()[2][0].display()
+ sage: type(f.jacobian()[2,0])
+ <class 'sage.manifolds.coord_func_symb.CoordFunctionSymbRing_with_category.element_class'>
+ sage: f.jacobian()[2,0].display()
(x, y) |--> -y^3*sin(x)
Test of the computation::
- sage: [[f.jacobian()[i][j] == f[i].diff(j) for j in range(2)] for i in range(3)]
+ sage: [[f.jacobian()[i,j] == f[i].diff(j) for j in range(2)] for i in range(3)]
[[True, True], [True, True], [True, True]]
Test with ``start_index = 1``::
@@ -1652,23 +1339,26 @@ class MultiCoordFunction(SageObject):
sage: X.<x,y> = M.chart()
sage: f = X.multifunction(x-y, x*y, y^3*cos(x))
sage: f.jacobian()
- [[1, -1], [y, x], [-y^3*sin(x), 3*y^2*cos(x)]]
- sage: [[f.jacobian()[i][j] == f[i].diff(j+1) for j in range(2)] # note the j+1
+ [ 1 -1]
+ [ y x]
+ [ -y^3*sin(x) 3*y^2*cos(x)]
+ sage: [[f.jacobian()[i,j] == f[i].diff(j+1) for j in range(2)] # note the j+1
....: for i in range(3)]
[[True, True], [True, True], [True, True]]
"""
- if self._jacob is None:
- xx = self._chart[:] # coordinates x^j
- self._jacob = [[ self._functions[i].diff(xx[j])
- for j in range(self._nc) ] for i in range(self._nf) ]
- return self._jacob
+ from sage.matrix.constructor import matrix
+ mat = matrix([[func.diff(coord) for coord in self._chart[:]]
+ for func in self._functions])
+ mat.set_immutable()
+ return mat
+ @cached_method
def jacobian_det(self):
r"""
Return the Jacobian determinant of the system of functions.
- The number `m` of coordinate functions must equal the number `n` of
- coordinates.
+ The number `m` of coordinate functions must equal the number `n`
+ of coordinates.
OUTPUT:
@@ -1689,7 +1379,7 @@ class MultiCoordFunction(SageObject):
values of the coordinates, e.g. `(x,y) = (1,2)`::
sage: type(f.jacobian_det())
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
+ <class 'sage.manifolds.coord_func_symb.CoordFunctionSymbRing_with_category.element_class'>
sage: f.jacobian_det().display()
(x, y) |--> x + y
sage: f.jacobian_det()(1,2)
@@ -1751,10 +1441,9 @@ class MultiCoordFunction(SageObject):
sign = not sign
return res
- if self._jacob_det is None:
- if (self._nf != self._nc):
- raise ValueError("the Jacobian matrix is not a square matrix")
- self.jacobian() # forces the computation of self._jacob
- self._jacob_det = simple_determinant(self._jacob)
- return self._jacob_det
+ if self._nf != self._nc:
+ raise ValueError("the Jacobian matrix is not a square matrix")
+ J = self.jacobian()
+ J = [[J[i,j] for i in range(self._nc)] for j in range(self._nc)]
+ return simple_determinant(J)
diff --git a/src/sage/manifolds/coord_func_symb.py b/src/sage/manifolds/coord_func_symb.py
index a2c275c..f8ce7f4 100644
--- a/src/sage/manifolds/coord_func_symb.py
+++ b/src/sage/manifolds/coord_func_symb.py
@@ -36,9 +36,12 @@ AUTHORS:
# http://www.gnu.org/licenses/
#*****************************************************************************
+from sage.misc.cachefunc import cached_method
from sage.symbolic.ring import SR
from sage.structure.element import RingElement
-from sage.misc.latex import latex
+from sage.structure.parent import Parent
+from sage.structure.unique_representation import UniqueRepresentation
+from sage.categories.algebras import Algebras
from sage.manifolds.coord_func import CoordFunction, MultiCoordFunction
from sage.manifolds.utilities import (ExpressionNice, simplify_chain_real,
simplify_chain_generic)
@@ -78,7 +81,7 @@ class CoordFunctionSymb(CoordFunction):
sage: X.<x,y> = M.chart()
sage: f = X.function(x^2+3*y+1)
sage: type(f)
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
+ <class 'sage.manifolds.coord_func_symb.CoordFunctionSymbRing_with_category.element_class'>
sage: f.display()
(x, y) |--> x^2 + 3*y + 1
sage: f(x,y)
@@ -264,9 +267,9 @@ class CoordFunctionSymb(CoordFunction):
_omit_fargs = False # static flag to govern whether or not
# the arguments of symbolic functions are printed
- def __init__(self, chart, expression):
+ def __init__(self, parent, expression):
r"""
- Construct a coordinate function.
+ Initialize ``self``.
TESTS:
@@ -277,7 +280,7 @@ class CoordFunctionSymb(CoordFunction):
sage: f = X.function(1+x*y); f
x*y + 1
sage: type(f)
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
+ <class 'sage.manifolds.coord_func_symb.CoordFunctionSymbRing_with_category.element_class'>
sage: TestSuite(f).run()
Coordinate function on a complex manifold::
@@ -289,12 +292,11 @@ class CoordFunctionSymb(CoordFunction):
sage: TestSuite(g).run()
"""
- self._chart = chart
- self._nc = len(chart[:]) # number of coordinates
+ CoordFunction.__init__(self, parent)
self._express = SR(expression) # symbolic expression enforced
# Definition of the simplification chain to be applied in
# symbolic calculus:
- if self._chart.manifold().base_field_type() == 'real':
+ if self.parent()._chart.manifold().base_field_type() == 'real':
self._simplify = simplify_chain_real
else:
self._simplify = simplify_chain_generic
@@ -308,7 +310,7 @@ class CoordFunctionSymb(CoordFunction):
def _repr_(self):
r"""
- String representation of the object.
+ String representation of ``self``.
TESTS::
@@ -330,7 +332,7 @@ class CoordFunctionSymb(CoordFunction):
def _latex_(self):
r"""
- LaTeX representation of the object.
+ LaTeX representation of ``self``.
TESTS::
@@ -343,6 +345,7 @@ class CoordFunctionSymb(CoordFunction):
\cos\left(\frac{1}{2} \, x y\right)
"""
+ from sage.misc.latex import latex
if CoordFunctionSymb._nice_output:
return latex(ExpressionNice(self._express))
else:
@@ -350,7 +353,7 @@ class CoordFunctionSymb(CoordFunction):
def display(self):
r"""
- Display the function in arrow notation.
+ Display ``self`` in arrow notation.
The output is either text-formatted (console mode) or
LaTeX-formatted (notebook mode).
@@ -379,9 +382,10 @@ class CoordFunctionSymb(CoordFunction):
"""
from sage.tensor.modules.format_utilities import FormattedExpansion
- resu_txt = str((self._chart)[:]) + ' |--> ' + \
+ from sage.misc.latex import latex
+ resu_txt = str(self.parent()._chart[:]) + ' |--> ' + \
str(ExpressionNice(self._express))
- resu_latex = latex(self._chart[:]) + r' \mapsto' + \
+ resu_latex = latex(self.parent()._chart[:]) + r' \mapsto' + \
latex(ExpressionNice(self._express))
return FormattedExpansion(resu_txt, resu_latex)
@@ -389,8 +393,7 @@ class CoordFunctionSymb(CoordFunction):
def expr(self):
r"""
- Return the symbolic expression representing the image of
- the coordinate function.
+ Return the symbolic expression representing the image of ``self``.
OUTPUT:
@@ -476,7 +479,7 @@ class CoordFunctionSymb(CoordFunction):
"""
if len(coords) != self._nc:
raise ValueError("bad number of coordinates")
- substitutions = dict(zip(self._chart._xx, coords))
+ substitutions = dict(zip(self.parent()._chart._xx, coords))
resu = self._express.subs(substitutions)
if 'simplify' in options:
if options['simplify']:
@@ -543,7 +546,7 @@ class CoordFunctionSymb(CoordFunction):
False
"""
- return CoordFunctionSymb(self._chart, self._express)
+ return type(self)(self.parent(), self._express)
def diff(self, coord):
r"""
@@ -578,7 +581,7 @@ class CoordFunctionSymb(CoordFunction):
Each partial derivatives is itself a coordinate function::
sage: type(f.diff(x))
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
+ <class 'sage.manifolds.coord_func_symb.CoordFunctionSymbRing_with_category.element_class'>
An index can be used instead of the coordinate symbol::
@@ -606,20 +609,19 @@ class CoordFunctionSymb(CoordFunction):
from sage.rings.integer import Integer
if self._der is None:
# the list of partial derivatives has to be updated
- self._der = [CoordFunctionSymb(self._chart,
- self._simplify(diff(self._express,
- xx)))
- for xx in self._chart[:]]
+ self._der = [type(self)(self.parent(),
+ self._simplify(diff(self._express, xx)))
+ for xx in self.parent()._chart[:]]
if isinstance(coord, (int, Integer)):
# NB: for efficiency, we access directly to the "private" attributes
# of other classes. A more conventional OOP writing would be
- # coordsi = coord - self._chart.domain().start_index()
- coordsi = coord - self._chart._domain._sindex
+ # coordsi = coord - self.parent()._chart.domain().start_index()
+ coordsi = coord - self.parent()._chart._domain._sindex
if coordsi < 0 or coordsi >= self._nc:
raise ValueError("coordinate index out of range")
return self._der[coordsi]
else:
- return self._der[self._chart[:].index(coord)]
+ return self._der[self.parent()._chart[:].index(coord)]
def __eq__(self, other):
r"""
@@ -661,7 +663,7 @@ class CoordFunctionSymb(CoordFunction):
if other is self:
return True
if isinstance(other, CoordFunctionSymb):
- if other._chart != self._chart:
+ if other.parent() != self.parent():
return False
else:
return bool(other._express == self._express)
@@ -674,7 +676,7 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - the opposite of the coordinate function ``self``
+ - the opposite of ``self``
TESTS:
@@ -686,12 +688,12 @@ class CoordFunctionSymb(CoordFunction):
sage: g = -f; g
-y^2 - x
sage: type(g)
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
+ <class 'sage.manifolds.coord_func_symb.CoordFunctionSymbRing_with_category.element_class'>
sage: -g == f
True
"""
- return CoordFunctionSymb(self._chart, self._simplify(-self._express))
+ return type(self)(self.parent(), self._simplify(-self._express))
def __invert__(self):
r"""
@@ -704,7 +706,7 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - the inverse of the coordinate function ``self``
+ - the inverse of ``self``
TESTS:
@@ -716,20 +718,20 @@ class CoordFunctionSymb(CoordFunction):
sage: g = f.__invert__(); g
1/(x^2 + y^2 + 1)
sage: type(g)
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
+ <class 'sage.manifolds.coord_func_symb.CoordFunctionSymbRing_with_category.element_class'>
sage: g == ~f
True
sage: g.__invert__() == f
True
"""
- return CoordFunctionSymb(self._chart,
- self._simplify(SR(1) / self._express))
+ return type(self)(self.parent(),
+ self._simplify(SR.one() / self._express))
# NB: self._express.__invert__() would return 1/self._express
# (cf. the code of __invert__ in src/sage/symbolic/expression.pyx)
# Here we prefer SR(1)/self._express
- def __add__(self, other):
+ def _add_(self, other):
r"""
Addition operator.
@@ -748,42 +750,31 @@ class CoordFunctionSymb(CoordFunction):
sage: X.<x,y> = M.chart()
sage: f = X.function(x+y^2)
sage: g = X.function(x+1)
- sage: s = f.__add__(g); s.display()
+ sage: s = f + g; s.display()
(x, y) |--> y^2 + 2*x + 1
sage: type(s)
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
- sage: f.__add__(0).display()
+ <class 'sage.manifolds.coord_func_symb.CoordFunctionSymbRing_with_category.element_class'>
+ sage: (f + 0).display()
(x, y) |--> y^2 + x
- sage: f.__add__(X.zero_function()).display()
+ sage: (f + X.zero_function()).display()
(x, y) |--> y^2 + x
- sage: f.__add__(1).display()
+ sage: (f + 1).display()
(x, y) |--> y^2 + x + 1
- sage: f.__add__(pi).display()
+ sage: (f + pi).display()
(x, y) |--> pi + y^2 + x
- sage: f.__add__(x).display()
+ sage: (f + x).display()
(x, y) |--> y^2 + 2*x
- sage: f.__add__(-f).display()
+ sage: (f + -f).display()
(x, y) |--> 0
- sage: f.__radd__(g) == g.__add__(f)
- True
"""
- if isinstance(other, CoordFunctionSymb):
- if other._chart != self._chart:
- raise ValueError("two coordinate functions not defined on " +
- "the same chart cannot be added")
- res = self._simplify(self._express + other._express)
- elif isinstance(other, (int, RingElement)):
- res = self._simplify(self._express + SR(other))
- else:
- # addition to a numerical coord. function shall fall into this case
- return other.__radd__(self)
+ res = self._simplify(self._express + other._express)
if res == 0:
- return self._chart._zero_function
+ return self.parent().zero()
else:
- return CoordFunctionSymb(self._chart, res)
+ return type(self)(self.parent(), res)
- def __sub__(self, other):
+ def _sub_(self, other):
r"""
Subtraction operator.
@@ -802,47 +793,34 @@ class CoordFunctionSymb(CoordFunction):
sage: X.<x,y> = M.chart()
sage: f = X.function(x+y^2)
sage: g = X.function(x+1)
- sage: s = f.__sub__(g); s.display()
+ sage: s = f - g; s.display()
(x, y) |--> y^2 - 1
sage: type(s)
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
- sage: f.__sub__(0).display()
+ <class 'sage.manifolds.coord_func_symb.CoordFunctionSymbRing_with_category.element_class'>
+ sage: (f - 0).display()
(x, y) |--> y^2 + x
- sage: f.__sub__(X.zero_function()).display()
+ sage: (f - X.zero_function()).display()
(x, y) |--> y^2 + x
- sage: f.__sub__(1).display()
+ sage: (f - 1).display()
(x, y) |--> y^2 + x - 1
- sage: f.__sub__(x).display()
+ sage: (f - x).display()
(x, y) |--> y^2
- sage: f.__sub__(pi).display()
+ sage: (f - pi).display()
(x, y) |--> -pi + y^2 + x
- sage: f.__sub__(f).display()
+ sage: (f - f).display()
(x, y) |--> 0
- sage: f.__sub__(g) == - (g.__sub__(f))
+ sage: (f - g) == -(g - f)
True
- sage: f.__rsub__(g) == g.__sub__(f)
- True
-
"""
- if isinstance(other, CoordFunctionSymb):
- if other._chart != self._chart:
- raise ValueError("two coordinate functions not defined on " +
- "the same chart cannot be subtracted")
- res = self._simplify(self._express - other._express)
- elif isinstance(other, (int, RingElement)):
- res = self._simplify(self._express - SR(other))
- else:
- # subtraction of a numerical coord. function shall fall into this
- # case
- return other.__rsub__(self)
+ res = self._simplify(self._express - other._express)
if res == 0:
- return self._chart._zero_function
+ return self.parent().zero()
else:
- return CoordFunctionSymb(self._chart, res)
+ return type(self)(self.parent(), res)
- def __mul__(self, other):
+ def _mul_(self, other):
r"""
- Multiplication operator.
+ Multiplication operator.
INPUT:
@@ -859,45 +837,73 @@ class CoordFunctionSymb(CoordFunction):
sage: X.<x,y> = M.chart()
sage: f = X.function(x+y)
sage: g = X.function(x-y)
- sage: s = f.__mul__(g); s.display()
+ sage: s = f._mul_(g); s.display()
(x, y) |--> x^2 - y^2
sage: type(s)
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
- sage: f.__mul__(0).display()
+ <class 'sage.manifolds.coord_func_symb.CoordFunctionSymbRing_with_category.element_class'>
+ sage: (f * 0).display()
(x, y) |--> 0
- sage: f.__mul__(X.zero_function()).display()
+ sage: (f * X.zero_function()).display()
(x, y) |--> 0
- sage: f.__mul__(2).display()
- (x, y) |--> 2*x + 2*y
- sage: f.__mul__(pi).display()
- (x, y) |--> pi*x + pi*y
- sage: f.__mul__(x).display()
- (x, y) |--> x^2 + x*y
- sage: f.__mul__(1/f).display()
+ sage: (f * (1/f)).display()
(x, y) |--> 1
- sage: f.__rmul__(g) == g.__mul__(f)
- True
"""
- if isinstance(other, CoordFunctionSymb):
- if other._chart != self._chart:
- raise ValueError("two coordinate functions not defined on " +
- "the same chart cannot be multiplied")
- res = self._simplify(self._express * other._express)
- elif isinstance(other, (int, RingElement)):
- res = self._simplify(self._express * SR(other))
- else:
- # multiplication by a numerical coord. function shall fall into
- # this case
- return other.__rmul__(self)
+ res = self._simplify(self._express * other._express)
if res == 0:
- return self._chart._zero_function
+ return self.parent().zero()
else:
- return CoordFunctionSymb(self._chart, res)
+ return type(self)(self.parent(), res)
+
+ def _rmul_(self, other):
+ """
+ Return ``other * self``.
+
+ EXAMPLES::
+
+ sage: M = Manifold(2, 'M', structure='topological')
+ sage: X.<x,y> = M.chart()
+ sage: one = X.function_ring().one()
+ sage: 2 * one
+ 2
+ sage: f = X.function(x+y)
+ sage: (f * pi).display()
+ (x, y) |--> pi*(x + y)
+ sage: (x * f).display()
+ (x, y) |--> (x + y)*x
+ """
+ try:
+ other = SR(other)
+ except (TypeError, ValueError):
+ return
+ return type(self)(self.parent(), other * self._express)
+
+ def _lmul_(self, other):
+ """
+ Return ``self * other``.
+
+ EXAMPLES::
- def __div__(self, other):
+ sage: M = Manifold(2, 'M', structure='topological')
+ sage: X.<x,y> = M.chart()
+ sage: one = X.function_ring().one()
+ sage: one * 2
+ 2
+ sage: f = X.function(x+y)
+ sage: (f * 2).display()
+ (x, y) |--> 2*x + 2*y
+ sage: (f * pi).display()
+ (x, y) |--> pi*(x + y)
+ """
+ try:
+ other = SR(other)
+ except (TypeError, ValueError):
+ return
+ return type(self)(self.parent(), self._express * other)
+
+ def _div_(self, other):
r"""
- Division operator.
+ Division operator.
INPUT:
@@ -914,52 +920,39 @@ class CoordFunctionSymb(CoordFunction):
sage: X.<x,y> = M.chart()
sage: f = X.function(x+y)
sage: g = X.function(1+x^2+y^2)
- sage: s = f.__div__(g); s.display()
+ sage: s = f._div_(g); s.display()
(x, y) |--> (x + y)/(x^2 + y^2 + 1)
sage: type(s)
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
- sage: f.__div__(X.zero_function())
+ <class 'sage.manifolds.coord_func_symb.CoordFunctionSymbRing_with_category.element_class'>
+ sage: f / X.zero_function()
Traceback (most recent call last):
...
- ZeroDivisionError: Division of a coordinate function by zero
- sage: f.__div__(1).display()
+ ZeroDivisionError: division of a coordinate function by zero
+ sage: (f / 1).display()
(x, y) |--> x + y
- sage: f.__div__(2).display()
+ sage: (f / 2).display()
(x, y) |--> 1/2*x + 1/2*y
- sage: f.__div__(pi).display()
+ sage: (f / pi).display()
(x, y) |--> (x + y)/pi
- sage: f.__div__(1+x^2).display()
+ sage: (f / (1+x^2)).display()
(x, y) |--> (x + y)/(x^2 + 1)
- sage: f.__div__(1+x^2).display()
+ sage: (f / (1+x^2)).display()
(x, y) |--> (x + y)/(x^2 + 1)
- sage: f.__div__(g) == ~(g.__div__(f))
- True
- sage: f.__rdiv__(g) == g.__div__(f)
+ sage: (f / g) == ~(g / f)
True
"""
- if isinstance(other, CoordFunctionSymb):
- if other._chart != self._chart:
- raise ValueError("two coordinate functions not defined on " +
- "the same chart cannot be divided")
- if other._express.is_zero():
- raise ZeroDivisionError("Division of a coordinate function " +
- "by zero")
- res = self._simplify(self._express / other._express)
- elif isinstance(other, (int, RingElement)):
- res = self._simplify(self._express / SR(other))
- else:
- # division by a numerical coord. function shall fall into this
- # case
- return other.__rdiv__(self)
+ if other._express.is_zero():
+ raise ZeroDivisionError("division of a coordinate function by zero")
+ res = self._simplify(self._express / SR(other))
if res == 0:
- return self._chart._zero_function
+ return self.parent().zero()
else:
- return CoordFunctionSymb(self._chart, res)
+ return type(self)(self.parent(), res)
def exp(self):
r"""
- Exponential of the coordinate function.
+ Exponential of ``self``.
OUTPUT:
@@ -981,12 +974,11 @@ class CoordFunctionSymb(CoordFunction):
1
"""
- return CoordFunctionSymb(self._chart,
- self._simplify(self._express.exp()))
+ return type(self)(self.parent(), self._simplify(self._express.exp()))
def log(self, base=None):
r"""
- Logarithm of the coordinate function.
+ Logarithm of ``self``.
INPUT:
@@ -1015,12 +1007,11 @@ class CoordFunctionSymb(CoordFunction):
log(x + y)/log(2)
"""
- return CoordFunctionSymb(self._chart,
- self._simplify(self._express.log(base)))
+ return type(self)(self.parent(), self._simplify(self._express.log(base)))
def __pow__(self, exponent):
r"""
- Power of the coordinate function.
+ Power of ``self``.
INPUT:
@@ -1050,12 +1041,12 @@ class CoordFunctionSymb(CoordFunction):
(x, y) |--> 0
"""
- return CoordFunctionSymb(self._chart,
- self._simplify(pow(self._express, exponent)))
+ return type(self)(self.parent(),
+ self._simplify(pow(self._express, exponent)))
def sqrt(self):
r"""
- Square root of the coordinate function.
+ Square root of ``self``.
OUTPUT:
@@ -1077,12 +1068,12 @@ class CoordFunctionSymb(CoordFunction):
(x, y) |--> 0
"""
- return CoordFunctionSymb(self._chart,
- self._simplify(self._express.sqrt()))
+ return type(self)(self.parent(),
+ self._simplify(self._express.sqrt()))
def cos(self):
r"""
- Cosine of the coordinate function.
+ Cosine of ``self``.
OUTPUT:
@@ -1104,12 +1095,12 @@ class CoordFunctionSymb(CoordFunction):
(x, y) |--> 1
"""
- return CoordFunctionSymb(self._chart,
- self._simplify(self._express.cos()))
+ return type(self)(self.parent(),
+ self._simplify(self._express.cos()))
def sin(self):
r"""
- Sine of the coordinate function.
+ Sine of ``self``.
OUTPUT:
@@ -1131,12 +1122,12 @@ class CoordFunctionSymb(CoordFunction):
True
"""
- return CoordFunctionSymb(self._chart,
- self._simplify(self._express.sin()))
+ return type(self)(self.parent(),
+ self._simplify(self._express.sin()))
def tan(self):
r"""
- Tangent of the coordinate function.
+ Tangent of ``self``.
OUTPUT:
@@ -1158,12 +1149,12 @@ class CoordFunctionSymb(CoordFunction):
True
"""
- return CoordFunctionSymb(self._chart,
- self._simplify(self._express.tan()))
+ return type(self)(self.parent(),
+ self._simplify(self._express.tan()))
def arccos(self):
r"""
- Arc cosine of the coordinate function.
+ Arc cosine of ``self``.
OUTPUT:
@@ -1187,12 +1178,12 @@ class CoordFunctionSymb(CoordFunction):
(x, y) |--> 1/2*pi
"""
- return CoordFunctionSymb(self._chart,
- self._simplify(self._express.arccos()))
+ return type(self)(self.parent(),
+ self._simplify(self._express.arccos()))
def arcsin(self):
r"""
- Arc sine of the coordinate function.
+ Arc sine of ``self``.
OUTPUT:
@@ -1216,12 +1207,12 @@ class CoordFunctionSymb(CoordFunction):
True
"""
- return CoordFunctionSymb(self._chart,
- self._simplify(self._express.arcsin()))
+ return type(self)(self.parent(),
+ self._simplify(self._express.arcsin()))
def arctan(self):
r"""
- Arc tangent of the coordinate function.
+ Arc tangent of ``self``.
OUTPUT:
@@ -1245,12 +1236,12 @@ class CoordFunctionSymb(CoordFunction):
True
"""
- return CoordFunctionSymb(self._chart,
- self._simplify(self._express.arctan()))
+ return type(self)(self.parent(),
+ self._simplify(self._express.arctan()))
def cosh(self):
r"""
- Hyperbolic cosine of the coordinate function.
+ Hyperbolic cosine of ``self``.
OUTPUT:
@@ -1272,12 +1263,12 @@ class CoordFunctionSymb(CoordFunction):
(x, y) |--> 1
"""
- return CoordFunctionSymb(self._chart,
- self._simplify(self._express.cosh()))
+ return type(self)(self.parent(),
+ self._simplify(self._express.cosh()))
def sinh(self):
r"""
- Hyperbolic sine of the coordinate function.
+ Hyperbolic sine of ``self``.
OUTPUT:
@@ -1299,12 +1290,12 @@ class CoordFunctionSymb(CoordFunction):
True
"""
- return CoordFunctionSymb(self._chart,
- self._simplify(self._express.sinh()))
+ return type(self)(self.parent(),
+ self._simplify(self._express.sinh()))
def tanh(self):
r"""
- Hyperbolic tangent of the coordinate function.
+ Hyperbolic tangent of ``self``.
OUTPUT:
@@ -1326,12 +1317,12 @@ class CoordFunctionSymb(CoordFunction):
True
"""
- return CoordFunctionSymb(self._chart,
- self._simplify(self._express.tanh()))
+ return type(self)(self.parent(),
+ self._simplify(self._express.tanh()))
def arccosh(self):
r"""
- Inverse hyperbolic cosine of the coordinate function.
+ Inverse hyperbolic cosine of ``self``.
OUTPUT:
@@ -1355,12 +1346,12 @@ class CoordFunctionSymb(CoordFunction):
True
"""
- return CoordFunctionSymb(self._chart,
- self._simplify(self._express.arccosh()))
+ return type(self)(self.parent(),
+ self._simplify(self._express.arccosh()))
def arcsinh(self):
r"""
- Inverse hyperbolic sine of the coordinate function.
+ Inverse hyperbolic sine of ``self``.
OUTPUT:
@@ -1384,12 +1375,12 @@ class CoordFunctionSymb(CoordFunction):
True
"""
- return CoordFunctionSymb(self._chart,
- self._simplify(self._express.arcsinh()))
+ return type(self)(self.parent(),
+ self._simplify(self._express.arcsinh()))
def arctanh(self):
r"""
- Inverse hyperbolic tangent of the coordinate function.
+ Inverse hyperbolic tangent of ``self``.
OUTPUT:
@@ -1413,8 +1404,8 @@ class CoordFunctionSymb(CoordFunction):
True
"""
- return CoordFunctionSymb(self._chart,
- self._simplify(self._express.arctanh()))
+ return type(self)(self.parent(),
+ self._simplify(self._express.arctanh()))
# -------------------------------------
# Methods specific to CoordFunctionSymb
@@ -1442,7 +1433,7 @@ class CoordFunctionSymb(CoordFunction):
def simplify(self):
r"""
- Simplify the coordinate expression of the function.
+ Simplify the coordinate expression of ``self``.
For details about the employed chain of simplifications, see
:func:`~sage.manifolds.utilities.simplify_chain_real` for coordinate
@@ -1452,7 +1443,7 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - the coordinate function, with its expression simplified
+ - ``self`` with its expression simplified
EXAMPLES:
@@ -1507,11 +1498,11 @@ class CoordFunctionSymb(CoordFunction):
def factor(self):
r"""
- Factorize the coordinate expression of the function.
+ Factorize the coordinate expression of ``self``.
OUTPUT:
- - the coordinate function, with its expression factorized
+ - ``self`` with its expression factorized
EXAMPLES:
@@ -1537,11 +1528,11 @@ class CoordFunctionSymb(CoordFunction):
def expand(self):
r"""
- Expand the coordinate expression of the function.
+ Expand the coordinate expression of ``self``.
OUTPUT:
- - the coordinate function, with its expression expanded
+ - ``self`` with its expression expanded
EXAMPLES:
@@ -1567,16 +1558,16 @@ class CoordFunctionSymb(CoordFunction):
def collect(self, s):
r"""
- Collect the coefficients of `s` in the expression of the coordinate
- function into a group.
+ Collect the coefficients of `s` in the expression of ``self``
+ into a group.
INPUT:
- - ``s`` -- the symbol whose coefficients will be collected.
+ - ``s`` -- the symbol whose coefficients will be collected
OUTPUT:
- - the coordinate function, with the coefficients of ``s`` grouped in
+ - ``self`` with the coefficients of ``s`` grouped in
its expression
EXAMPLES:
@@ -1603,15 +1594,14 @@ class CoordFunctionSymb(CoordFunction):
def collect_common_factors(self):
r"""
- Collect common factors in the expression of the coordinate
- function.
+ Collect common factors in the expression of ``self``.
This method does not perform a full factorization but only looks
for factors which are already explicitly present.
OUTPUT:
- - the coordinate function, with the common factors collected in
+ - ``self`` with the common factors collected in
its expression
EXAMPLES:
@@ -1638,3 +1628,113 @@ class CoordFunctionSymb(CoordFunction):
self._del_derived()
return self
+
+class CoordFunctionSymbRing(Parent, UniqueRepresentation):
+ """
+ Ring of all symbolic coordinate functions on a chart.
+ """
+ def __init__(self, chart):
+ """
+ Initialize ``self``.
+
+ EXAMPLES::
+
+ sage: M = Manifold(2, 'M', structure='topological')
+ sage: X.<x,y> = M.chart()
+ sage: FR = X.function_ring()
+ sage: TestSuite(FR).run()
+ """
+ self._chart = chart
+ Parent.__init__(self, base=SR, category=Algebras(SR))
+
+ def _repr_(self):
+ """
+ Return a string representation of ``self``.
+
+ EXAMPLES::
+
+ sage: M = Manifold(2, 'M', structure='topological')
+ sage: X.<x,y> = M.chart()
+ sage: X.function_ring()
+ Ring of coordinate functions on Chart (M, (x, y))
+ """
+ return "Ring of coordinate functions on {}".format(self._chart)
+
+ @cached_method
+ def zero(self):
+ """
+ Return the constant function `0` in ``self``.
+
+ EXAMPLES::
+
+ sage: M = Manifold(2, 'M', structure='topological')
+ sage: X.<x,y> = M.chart()
+ sage: FR = X.function_ring()
+ sage: FR.zero()
+ 0
+
+ sage: M = Manifold(2, 'M', structure='topological', field=Qp(5))
+ sage: X.<x,y> = M.chart()
+ sage: X.function_ring().zero()
+ 0
+ """
+ if self._chart.manifold().base_field_type() in ['real', 'complex']:
+ elt = SR.zero()
+ else:
+ elt = self._chart.manifold().base_field().zero()
+ return self.element_class(self, elt)
+
+ @cached_method
+ def one(self):
+ """
+ Return the constant function `1` in ``self``.
+
+ EXAMPLES::
+
+ sage: M = Manifold(2, 'M', structure='topological')
+ sage: X.<x,y> = M.chart()
+ sage: FR = X.function_ring()
+ sage: FR.one()
+ 1
+
+ sage: M = Manifold(2, 'M', structure='topological', field=Qp(5))
+ sage: X.<x,y> = M.chart()
+ sage: X.function_ring().one()
+ 1 + O(5^20)
+ """
+ if self._chart.manifold().base_field_type() in ['real', 'complex']:
+ elt = SR.one()
+ else:
+ elt = self._chart.manifold().base_field().one()
+ return self.element_class(self, elt)
+
+ def from_base_ring(self, r):
+ """
+ Return the canonical embedding of ``r`` into ``self``.
+
+ INPUT:
+
+ - ``r`` -- an element of ``self.base_ring()``
+
+ EXAMPLES::
+ """
+ return self.element_class(self, r)
+
+ def is_integral_domain(self):
+ """
+ Return ``False`` as ``self`` is not an integral domain.
+
+ EXAMPLES::
+
+ sage: M = Manifold(2, 'M', structure='topological')
+ sage: X.<x,y> = M.chart()
+ sage: FR = X.function_ring()
+ sage: FR.is_field()
+ False
+ """
+ return False
+
+ is_commutative = is_field = is_integral_domain
+
+ Element = CoordFunctionSymb
+
diff --git a/src/sage/manifolds/scalarfield.py b/src/sage/manifolds/scalarfield.py
index b48974d..a784571 100644
--- a/src/sage/manifolds/scalarfield.py
+++ b/src/sage/manifolds/scalarfield.py
@@ -2,8 +2,8 @@ r"""
Scalar Fields
Given a topological manifold `M` over a topological field `K` (in most
-applications, `K = \RR` or `K = \CC`), a *scalar field* on `M` is a continuous
-map
+applications, `K = \RR` or `K = \CC`), a *scalar field* on `M` is a
+continuous map
.. MATH::
@@ -213,7 +213,7 @@ class ScalarField(CommutativeAlgebraElement):
sage: f.coord_function(c_uv)
(u^2 + v^2)/(u^2 + v^2 + 1)
sage: type(f.coord_function(c_uv))
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
+ <class 'sage.manifolds.coord_func_symb.CoordFunctionSymbRing_with_category.element_class'>
sage: f.coord_function(c_uv).display()
(u, v) |--> (u^2 + v^2)/(u^2 + v^2 + 1)
@@ -470,7 +470,7 @@ class ScalarField(CommutativeAlgebraElement):
sage: s.display()
M --> R
on U: (x, y) |--> a/(x^2 + y^2 + 1)
- on V: (u, v) |--> (a*u^2 + a*v^2)/(u^2 + v^2 + 1)
+ on V: (u, v) |--> (u^2 + v^2)*a/(u^2 + v^2 + 1)
However, if the symbolic variable is a chart coordinate, the
multiplication is performed only in the corresponding chart::
@@ -484,7 +484,7 @@ class ScalarField(CommutativeAlgebraElement):
Scalar field on the 2-dimensional topological manifold M
sage: s.display()
M --> R
- on V: (u, v) |--> (u^3 + u*v^2)/(u^2 + v^2 + 1)
+ on V: (u, v) |--> (u^2 + v^2)*u/(u^2 + v^2 + 1)
Some tests::
@@ -991,7 +991,7 @@ class ScalarField(CommutativeAlgebraElement):
sage: f.coord_function(c_xy) # equivalent form (since c_xy is the default chart)
x*y^2
sage: type(f.coord_function())
- <class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
+ <class 'sage.manifolds.coord_func_symb.CoordFunctionSymbRing_with_category.element_class'>
Expression via a change of coordinates::
@@ -1981,7 +1981,7 @@ class ScalarField(CommutativeAlgebraElement):
OUPUT:
- - the scalar field ``number*self``
+ - the scalar field ``number * self``
TESTS::
@@ -1997,7 +1997,7 @@ class ScalarField(CommutativeAlgebraElement):
True
sage: f._rmul_(pi).display()
M --> R
- (x, y) |--> pi*x + pi*y
+ (x, y) |--> pi*(x + y)
sage: f._rmul_(pi) == pi*f
True
sage: f._rmul_(0) == M.zero_scalar_field()
@@ -2068,7 +2068,7 @@ class ScalarField(CommutativeAlgebraElement):
OUPUT:
- - the scalar field ``self*number``
+ - the scalar field ``self * number``
TESTS::
diff --git a/src/sage/manifolds/scalarfield_algebra.py b/src/sage/manifolds/scalarfield_algebra.py
index 1ecbee6..5231cbb 100644
--- a/src/sage/manifolds/scalarfield_algebra.py
+++ b/src/sage/manifolds/scalarfield_algebra.py
@@ -44,7 +44,7 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
If `M` is a topological manifold over a topological field `K`, the
commutative algebra of scalar fields on `M` is the set `C^0(M)` of all
- continuous maps `M\rightarrow K`. The set `C^0(M)` is an algebra over `K`,
+ continuous maps `M \to K`. The set `C^0(M)` is an algebra over `K`,
whose ring product is the pointwise multiplication of `K`-valued
functions, which is clearly commutative.
@@ -302,7 +302,7 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
sage: s.display()
M --> R
on U: (x, y) |--> 1/2*sqrt(2)*arctan(x^2 + y^2)/pi
- on V: (u, v) |--> 1/4*sqrt(2)*(pi - 2*arctan(u^2 + v^2))/pi
+ on V: (u, v) |--> 1/4*(sqrt(2)*pi - 2*sqrt(2)*arctan(u^2 + v^2))/pi
::