summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Gourgoulhon <eric.gourgoulhon@obspm.fr>2015-06-15 17:50:26 +0200
committerEric Gourgoulhon <eric.gourgoulhon@obspm.fr>2015-06-15 17:50:26 +0200
commit0e2c5fa2e64f4ea9bee2bf97e7afa76fa0c977f8 (patch)
treebc59ace6a30bf62b3c86484c125e322f946b6ceb
parentAdd doctests in ScalarField (diff)
Add doctests in ScalarFieldAlgebra and CoordFunction
-rw-r--r--src/sage/manifolds/coord_func.py578
-rw-r--r--src/sage/manifolds/scalarfield_algebra.py173
2 files changed, 747 insertions, 4 deletions
diff --git a/src/sage/manifolds/coord_func.py b/src/sage/manifolds/coord_func.py
index c96e863..872912b 100644
--- a/src/sage/manifolds/coord_func.py
+++ b/src/sage/manifolds/coord_func.py
@@ -66,6 +66,14 @@ class CoordFunction(SageObject):
def __init__(self, chart):
r"""
Base constructor for derived classes.
+
+ TEST::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+
"""
self._chart = chart
self._nc = len(chart[:]) # number of coordinates
@@ -147,6 +155,18 @@ class CoordFunction(SageObject):
- ``True`` if ``self`` is different from ``other``, or ``False``
otherwise
+ TESTS::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: f = X.function(x+y)
+ sage: g = X.function(x*y)
+ sage: f.__ne__(g)
+ True
+ sage: h = X.function(x+y)
+ sage: f.__ne__(h)
+ False
+
"""
return not self.__eq__(other)
@@ -163,6 +183,19 @@ class CoordFunction(SageObject):
- coordinate function resulting from the addition of ``self`` and
``other``
+ TESTS::
+
+ sage: M = TopManifold(2, 'M')
+ 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)
@@ -179,6 +212,19 @@ class CoordFunction(SageObject):
- coordinate function resulting from the addition of ``self`` and
``other``
+ TESTS::
+
+ sage: M = TopManifold(2, 'M')
+ 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)
@@ -195,6 +241,19 @@ class CoordFunction(SageObject):
- coordinate function resulting from the subtraction of ``self`` from
``other``
+ TESTS::
+
+ sage: M = TopManifold(2, 'M')
+ 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)
@@ -211,6 +270,19 @@ class CoordFunction(SageObject):
- coordinate function resulting from the subtraction of ``other`` from
``self``
+ TESTS::
+
+ sage: M = TopManifold(2, 'M')
+ 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)
@@ -227,6 +299,21 @@ class CoordFunction(SageObject):
- coordinate function resulting from the multiplication of ``other``
by ``self``
+ TESTS::
+
+ sage: M = TopManifold(2, 'M')
+ 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)
@@ -243,6 +330,19 @@ class CoordFunction(SageObject):
- coordinate function resulting from the multiplication of ``self``
by ``other``
+ TESTS::
+
+ sage: M = TopManifold(2, 'M')
+ 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)
@@ -259,6 +359,19 @@ class CoordFunction(SageObject):
- coordinate function resulting from the division of ``other`` by
``self``
+ TESTS::
+
+ sage: M = TopManifold(2, 'M')
+ 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)
@@ -275,6 +388,19 @@ class CoordFunction(SageObject):
- coordinate function resulting from the division of ``self`` by
``other``
+ TESTS::
+
+ sage: M = TopManifold(2, 'M')
+ 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)
@@ -285,18 +411,63 @@ class CoordFunction(SageObject):
def _repr_(self):
r"""
String representation of the object.
+
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f._repr_()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction._repr_ not implemented
+
"""
raise NotImplementedError("CoordFunction._repr_ not implemented")
def _latex_(self):
r"""
LaTeX representation of the object.
+
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f._latex_()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction._latex_ not implemented
+
"""
raise NotImplementedError("CoordFunction._latex_ not implemented")
def display(self):
r"""
Display the function in arrow notation.
+
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.display()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.display not implemented
+
"""
raise NotImplementedError("CoordFunction.display not implemented")
@@ -312,6 +483,20 @@ class CoordFunction(SageObject):
(see
:meth:`sage.manifolds.coord_func_symb.CoordFunctionSymb.expr`)
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.expr()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.expr not implemented
+
"""
raise NotImplementedError("CoordFunction.expr not implemented")
@@ -331,6 +516,20 @@ class CoordFunction(SageObject):
- the value `f(x^1,...,x^n)`, where `f` is the current coordinate
function.
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.__call__(2,-3)
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.__call__ not implemented
+
"""
raise NotImplementedError("CoordFunction.__call__ not implemented")
@@ -338,6 +537,20 @@ class CoordFunction(SageObject):
r"""
Return ``True`` if the function is zero and ``False`` otherwise.
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.is_zero()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.is_zero not implemented
+
"""
raise NotImplementedError("CoordFunction.is_zero not implemented")
@@ -349,6 +562,20 @@ class CoordFunction(SageObject):
- an instance of :class:`CoordFunction`
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.copy()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.copy not implemented
+
"""
raise NotImplementedError("CoordFunction.copy not implemented")
@@ -369,6 +596,20 @@ class CoordFunction(SageObject):
- instance of :class:`CoordFunction` representing the partial
derivative `\frac{\partial f}{\partial x^i}`
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.diff(x)
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.diff not implemented
+
"""
raise NotImplementedError("CoordFunction.diff not implemented")
@@ -384,6 +625,21 @@ class CoordFunction(SageObject):
- ``True`` if ``self`` is equal to ``other``, or ``False`` otherwise
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: g = CoordFunction(X)
+ sage: f.__eq__(g)
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.__eq__ not implemented
+
"""
raise NotImplementedError("CoordFunction.__eq__ not implemented")
@@ -395,6 +651,20 @@ class CoordFunction(SageObject):
- an exact copy of ``self``
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.__pos__()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.__pos__ not implemented
+
"""
raise NotImplementedError("CoordFunction.__pos__ not implemented")
@@ -406,6 +676,20 @@ class CoordFunction(SageObject):
- the opposite of the coordinate function ``self``
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ 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
+
"""
raise NotImplementedError("CoordFunction.__neg__ not implemented")
@@ -422,6 +706,20 @@ class CoordFunction(SageObject):
- the inverse of the coordinate function ``self``
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.__invert__()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.__invert__ not implemented
+
"""
raise NotImplementedError("CoordFunction.__invert__ not implemented")
@@ -438,6 +736,20 @@ class CoordFunction(SageObject):
- coordinate function resulting from the addition of ``self`` and
``other``
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.__add__(2)
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.__add__ not implemented
+
"""
raise NotImplementedError("CoordFunction.__add__ not implemented")
@@ -454,6 +766,20 @@ class CoordFunction(SageObject):
- coordinate function resulting from the subtraction of ``other`` from
``self``
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.__sub__(2)
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.__sub__ not implemented
+
"""
raise NotImplementedError("CoordFunction.__sub__ not implemented")
@@ -470,6 +796,20 @@ class CoordFunction(SageObject):
- coordinate function resulting from the multiplication of ``self`` by
``other``
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.__mul__(2)
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.__mul__ not implemented
+
"""
raise NotImplementedError("CoordFunction.__mul__ not implemented")
@@ -486,6 +826,20 @@ class CoordFunction(SageObject):
- coordinate function resulting from the division of ``self`` by
``other``
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.__div__(2)
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.__div__ not implemented
+
"""
raise NotImplementedError("CoordFunction.__div__ not implemented")
@@ -498,6 +852,20 @@ class CoordFunction(SageObject):
- coordinate function `\exp(f)`, where `f` is the current coordinate
function.
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.exp()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.exp not implemented
+
"""
raise NotImplementedError("CoordFunction.exp not implemented")
@@ -516,6 +884,20 @@ class CoordFunction(SageObject):
- coordinate function `\log_a(f)`, where `f` is the current coordinate
function and `a` is the base
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.log()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.log not implemented
+
"""
raise NotImplementedError("CoordFunction.log not implemented")
@@ -533,6 +915,20 @@ class CoordFunction(SageObject):
- coordinate function `f^a`, where `f` is the current coordinate
function and `a` is the exponent
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.__pow__(2)
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.__pow__ not implemented
+
"""
raise NotImplementedError("CoordFunction.__pow__ not implemented")
@@ -546,6 +942,20 @@ class CoordFunction(SageObject):
- coordinate function `\sqrt{f}`, where `f` is the current coordinate
function.
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.sqrt()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.sqrt not implemented
+
"""
raise NotImplementedError("CoordFunction.sqrt not implemented")
@@ -558,6 +968,20 @@ class CoordFunction(SageObject):
- coordinate function `\cos(f)`, where `f` is the current coordinate
function.
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.cos()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.cos not implemented
+
"""
raise NotImplementedError("CoordFunction.cos not implemented")
@@ -570,6 +994,20 @@ class CoordFunction(SageObject):
- coordinate function `\sin(f)`, where `f` is the current coordinate
function.
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.sin()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.sin not implemented
+
"""
raise NotImplementedError("CoordFunction.sin not implemented")
@@ -582,6 +1020,20 @@ class CoordFunction(SageObject):
- coordinate function `\tan(f)`, where `f` is the current coordinate
function.
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.tan()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.tan not implemented
+
"""
raise NotImplementedError("CoordFunction.tan not implemented")
@@ -594,6 +1046,20 @@ class CoordFunction(SageObject):
- coordinate function `\arccos(f)`, where `f` is the current coordinate
function.
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.arccos()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.arccos not implemented
+
"""
raise NotImplementedError("CoordFunction.arccos not implemented")
@@ -606,6 +1072,20 @@ class CoordFunction(SageObject):
- coordinate function `\arcsin(f)`, where `f` is the current coordinate
function.
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.arcsin()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.arcsin not implemented
+
"""
raise NotImplementedError("CoordFunction.arcsin not implemented")
@@ -618,6 +1098,20 @@ class CoordFunction(SageObject):
- coordinate function `\arctan(f)`, where `f` is the current coordinate
function.
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.arctan()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.arctan not implemented
+
"""
raise NotImplementedError("CoordFunction.arctan not implemented")
@@ -630,6 +1124,20 @@ class CoordFunction(SageObject):
- coordinate function `\cosh(f)`, where `f` is the current coordinate
function.
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.cosh()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.cosh not implemented
+
"""
raise NotImplementedError("CoordFunction.cosh not implemented")
@@ -642,6 +1150,20 @@ class CoordFunction(SageObject):
- coordinate function `\sinh(f)`, where `f` is the current coordinate
function.
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.sinh()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.sinh not implemented
+
"""
raise NotImplementedError("CoordFunction.sinh not implemented")
@@ -654,6 +1176,20 @@ class CoordFunction(SageObject):
- coordinate function `\tanh(f)`, where `f` is the current coordinate
function.
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.tanh()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.tanh not implemented
+
"""
raise NotImplementedError("CoordFunction.tanh not implemented")
@@ -666,6 +1202,20 @@ class CoordFunction(SageObject):
- coordinate function `\mathrm{arcosh}(f)`, where `f` is the current
coordinate function.
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.arccosh()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.arccosh not implemented
+
"""
raise NotImplementedError("CoordFunction.arccosh not implemented")
@@ -678,6 +1228,20 @@ class CoordFunction(SageObject):
- coordinate function `\mathrm{arsinh}(f)`, where `f` is the current
coordinate function.
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.arcsinh()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.arcsinh not implemented
+
"""
raise NotImplementedError("CoordFunction.arcsinh not implemented")
@@ -690,6 +1254,20 @@ class CoordFunction(SageObject):
- coordinate function `\mathrm{artanh}(f)`, where `f` is the current
coordinate function.
+ TEST:
+
+ This method must be implemented by derived classes; it is not
+ implemented here::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.coord_func import CoordFunction
+ sage: f = CoordFunction(X)
+ sage: f.arctanh()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: CoordFunction.arctanh not implemented
+
"""
raise NotImplementedError("CoordFunction.arctanh not implemented")
diff --git a/src/sage/manifolds/scalarfield_algebra.py b/src/sage/manifolds/scalarfield_algebra.py
index 1156931..eb3a50a 100644
--- a/src/sage/manifolds/scalarfield_algebra.py
+++ b/src/sage/manifolds/scalarfield_algebra.py
@@ -359,6 +359,20 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
Element = ScalarField
def __init__(self, domain):
+ r"""
+ Construct an algebra of scalar fields.
+
+ TESTS::
+
+ sage: TopManifold._clear_cache_() # for doctests only
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: from sage.manifolds.scalarfield_algebra import ScalarFieldAlgebra
+ sage: CM = ScalarFieldAlgebra(M); CM
+ Algebra of scalar fields on the 2-dimensional topological manifold M
+ sage: TestSuite(CM).run()
+
+ """
base_field = domain.base_field()
if base_field in ['real', 'complex']:
base_field = SR
@@ -370,10 +384,74 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
self._one = None # unit element (to be set by method one())
#### Methods required for any Parent
- def _element_constructor_(self, coord_expression=None, name=None,
- latex_name=None, chart=None):
+ def _element_constructor_(self, coord_expression=None, chart=None,
+ name=None, latex_name=None):
r"""
- Construct a scalarfield
+ Construct a scalar field.
+
+ INPUT:
+
+ - ``coord_expression`` -- (default: ``None``) element(s) to construct
+ the scalar field; this can be either
+
+ - a scalar field defined on a domain that encompass ``self._domain``;
+ then ``_element_constructor_`` return the restriction of
+ the scalar field to ``self._domain``
+ - a dictionary of coordinate expressions in various charts on the
+ domain, with the charts as keys;
+ - a single coordinate expression; if the argument ``chart`` is
+ ``'all'``, this expression is set to all the charts defined
+ on the open set; otherwise, the expression is set in the
+ specific chart provided by the argument ``chart``
+
+ NB: If ``coord_expression`` is ``None`` or incomplete, coordinate
+ expressions can be added after the creation of the object, by means
+ of the methods :meth:`add_expr`, :meth:`add_expr_by_continuation` and
+ :meth:`set_expr`
+ - ``chart`` -- (default: ``None``) chart defining the coordinates used
+ in ``coord_expression`` when the latter is a single coordinate
+ expression; if none is provided (default), the default chart of the
+ open set is assumed. If ``chart=='all'``, ``coord_expression`` is
+ assumed to be independent of the chart (constant scalar field).
+ - ``name`` -- (default: ``None``) string; name (symbol) given to the
+ scalar field
+ - ``latex_name`` -- (default: ``None``) string; LaTeX symbol to denote
+ the scalar field; if none is provided, the LaTeX symbol is set to
+ ``name``
+
+ TESTS::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: CM = M.scalar_field_algebra()
+ sage: f = CM._element_constructor_(); f
+ Scalar field on the 2-dimensional topological manifold M
+ sage: f = CM._element_constructor_(coord_expression={X: x+y^2}); f
+ Scalar field on the 2-dimensional topological manifold M
+ sage: f.display()
+ M --> R
+ (x, y) |--> y^2 + x
+ sage: f = CM._element_constructor_(coord_expression={X: x+y^2}, name='f'); f
+ Scalar field f on the 2-dimensional topological manifold M
+ sage: f.display()
+ f: M --> R
+ (x, y) |--> y^2 + x
+ sage: f1 = CM._element_constructor_(coord_expression=x+y^2, chart=X, name='f'); f1
+ Scalar field f on the 2-dimensional topological manifold M
+ sage: f1 == f
+ True
+ sage: g = CM._element_constructor_(f); g
+ Scalar field on the 2-dimensional topological manifold M
+ sage: g == f
+ True
+ sage: U = M.open_subset('U', coord_def={X: x>0})
+ sage: CU = U.scalar_field_algebra()
+ sage: fU = CU._element_constructor_(f); fU
+ Scalar field on the Open subset U of the 2-dimensional topological manifold M
+ sage: fU.display()
+ U --> R
+ (x, y) |--> y^2 + x
+
"""
if isinstance(coord_expression, ScalarField):
if self._domain.is_subset(coord_expression._domain):
@@ -400,6 +478,18 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
def _an_element_(self):
r"""
Construct some element of the algebra
+
+ TESTS::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: CM = M.scalar_field_algebra()
+ sage: f = CM._an_element_(); f
+ Scalar field on the 2-dimensional topological manifold M
+ sage: f.display()
+ M --> R
+ (x, y) |--> 2
+
"""
return self.element_class(self._domain, coord_expression=2,
chart='all')
@@ -408,6 +498,21 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
def _coerce_map_from_(self, other):
r"""
Determine whether coercion to self exists from other parent
+
+ TESTS::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: CM = M.scalar_field_algebra()
+ sage: CM._coerce_map_from_(SR)
+ True
+ sage: U = M.open_subset('U', coord_def={X: x>0})
+ sage: CU = U.scalar_field_algebra()
+ sage: CM._coerce_map_from_(CU)
+ False
+ sage: CU._coerce_map_from_(CM)
+ True
+
"""
if other is SR:
return True # coercion from the base ring (multiplication by the
@@ -424,18 +529,58 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
def _repr_(self):
r"""
String representation of the object.
+
+ TESTS::
+
+ sage: M = TopManifold(2, 'M')
+ sage: CM = M.scalar_field_algebra()
+ sage: CM._repr_()
+ 'Algebra of scalar fields on the 2-dimensional topological manifold M'
+ sage: repr(CM) # indirect doctest
+ 'Algebra of scalar fields on the 2-dimensional topological manifold M'
+
"""
return "Algebra of scalar fields on the {}".format(self._domain)
def _latex_(self):
r"""
LaTeX representation of the object.
- """
+
+ TESTS::
+
+ sage: M = TopManifold(2, 'M')
+ sage: CM = M.scalar_field_algebra()
+ sage: CM._latex_()
+ 'C^0 \\left(M\\right)'
+ sage: latex(CM) # indirect doctest
+ C^0 \left(M\right)
+
+ """
return r"C^0 \left(" + self._domain._latex_() + r"\right)"
def zero(self):
r"""
Return the zero element of the algebra.
+
+ This is nothing but the constant scalar field `0` on the manifold,
+ where `0` is the zero element of the base field.
+
+ EXAMPLE::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: CM = M.scalar_field_algebra()
+ sage: z = CM.zero(); z
+ Scalar field zero on the 2-dimensional topological manifold M
+ sage: z.display()
+ zero: M --> R
+ (x, y) |--> 0
+
+ The result is cached::
+
+ sage: CM.zero() is z
+ True
+
"""
if self._zero is None:
coord_express = dict([(chart, chart.zero_function()) for chart
@@ -449,6 +594,26 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
def one(self):
r"""
Return the unit element of the algebra.
+
+ This is nothing but the constant scalar field `1` on the manifold,
+ where `1` is the unit element of the base field.
+
+ EXAMPLE::
+
+ sage: M = TopManifold(2, 'M')
+ sage: X.<x,y> = M.chart()
+ sage: CM = M.scalar_field_algebra()
+ sage: h = CM.one(); h
+ Scalar field 1 on the 2-dimensional topological manifold M
+ sage: h.display()
+ 1: M --> R
+ (x, y) |--> 1
+
+ The result is cached::
+
+ sage: CM.one() is h
+ True
+
"""
if self._one is None:
coord_express = dict([(chart, chart.one_function()) for chart