summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTravis Scrimshaw <tscrimsh at umn.edu>2016-04-28 08:44:41 -0500
committerTravis Scrimshaw <tscrimsh at umn.edu>2016-04-28 08:44:41 -0500
commit3b92a85394e8fc6f7572c58d0a6ce8b1bebacce2 (patch)
tree25ff22e3b7da1f29151e4774ed6c45c61058ad1a
parentMerge branch 'public/manifolds/top_manif_scalar_fields' of trac.sagemath.org:... (diff)
Some formatting and small reviewer changes.
-rw-r--r--src/sage/manifolds/coord_func.py366
-rw-r--r--src/sage/manifolds/coord_func_symb.py204
-rw-r--r--src/sage/manifolds/manifold.py49
-rw-r--r--src/sage/manifolds/scalarfield.py183
-rw-r--r--src/sage/manifolds/scalarfield_algebra.py164
-rw-r--r--src/sage/manifolds/utilities.py90
6 files changed, 499 insertions, 557 deletions
diff --git a/src/sage/manifolds/coord_func.py b/src/sage/manifolds/coord_func.py
index 9ae3324..84a65ca 100644
--- a/src/sage/manifolds/coord_func.py
+++ b/src/sage/manifolds/coord_func.py
@@ -6,23 +6,23 @@ a *coordinate function* is a function from a chart codomain
to `K`. In other words, a coordinate function is a `K`-valued function of
the coordinates associated to some chart.
-More precisely, let `(U,\varphi)` be a chart on `M`, i.e. `U` is an open
-subset of `M` and `\varphi: U \rightarrow V \subset K^n` is a homeomorphism
+More precisely, let `(U, \varphi)` be a chart on `M`, i.e. `U` is an open
+subset of `M` and `\varphi: U \to V \subset K^n` is a homeomorphism
from `U` to an open subset `V` of `K^n`. A *coordinate function associated
-to the chart* `(U,\varphi)` is a function
+to the chart* `(U, \varphi)` is a function
.. MATH::
\begin{array}{cccc}
f:& V\subset K^n & \longrightarrow & K \\
- & (x^1,\ldots, x^n) & \longmapsto & f(x^1,\ldots, x^n)
+ & (x^1, \ldots, x^n) & \longmapsto & f(x^1, \ldots, x^n)
\end{array}
Coordinate functions are implemented by derived classes of the abstract base
class :class:`CoordFunction`.
-The class :class:`MultiCoordFunction` implements `K^m`-valued functions of the
-coordinates of a chart, with $m$ a positive integer.
+The class :class:`MultiCoordFunction` implements `K^m`-valued functions of
+the coordinates of a chart, with `m` a positive integer.
AUTHORS:
@@ -39,6 +39,7 @@ AUTHORS:
# http://www.gnu.org/licenses/
#*****************************************************************************
+from sage.misc.abstract_method import abstract_method
from sage.structure.sage_object import SageObject
from sage.misc.latex import latex
@@ -46,21 +47,21 @@ class CoordFunction(SageObject):
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 \rightarrow 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)`.
+ 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
+ `V` is the codomain of `\varphi`. In other words, `f` is a `K`-valued
+ function of the coordinates associated to the chart `(U, \varphi)`.
- The class :class:`CoordFunction` is an abstract one. Specific coordinate
- functions must be implemented by derived classes, like
+ The class :class:`CoordFunction` is an abstract one. Specific
+ coordinate functions must be implemented by derived classes, like
:class:`~sage.manifolds.coord_func_symb.CoordFunctionSymb` for
symbolic coordinate functions.
INPUT:
- - ``chart`` -- the chart `(U, \varphi)`, as an instance of class
- :class:`~sage.manifolds.chart.Chart`
+ - ``chart`` -- :class:`~sage.manifolds.chart.Chart`;
+ the chart `(U, \varphi)`
"""
def __init__(self, chart):
@@ -84,11 +85,12 @@ class CoordFunction(SageObject):
def chart(self):
r"""
- Return the chart w.r.t. which the coordinate function is defined.
+ Return the chart with respect to which the coordinate function
+ is defined.
OUTPUT:
- - an instance of :class:`~sage.manifolds.chart.Chart`
+ - a :class:`~sage.manifolds.chart.Chart`
EXAMPLE::
@@ -108,19 +110,18 @@ class CoordFunction(SageObject):
Construct the scalar field that has the coordinate function as
coordinate expression.
- The domain of the scalar field is the open subset covered by the chart
- on which the coordinate function is defined
+ The domain of the scalar field is the open subset covered by the
+ chart on which the coordinate function is defined.
INPUT:
- ``name`` -- (default: ``None``) name given to the scalar field
- ``latex_name`` -- (default: ``None``) LaTeX symbol to denote the
- scalar field; if none is provided, the LaTeX symbol is set to ``name``
+ scalar field; if ``None``, the LaTeX symbol is set to ``name``
OUTPUT:
- - instance of class
- :class:`~sage.manifolds.scalarfield.ScalarField`
+ - a :class:`~sage.manifolds.scalarfield.ScalarField`
EXAMPLES:
@@ -148,7 +149,7 @@ class CoordFunction(SageObject):
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
@@ -176,7 +177,7 @@ class CoordFunction(SageObject):
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
@@ -205,7 +206,7 @@ class CoordFunction(SageObject):
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
@@ -234,12 +235,12 @@ class CoordFunction(SageObject):
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
- - coordinate function resulting from the subtraction of ``self`` from
- ``other``
+ - coordinate function resulting from the subtraction of ``self``
+ from ``other``
TESTS::
@@ -263,12 +264,12 @@ class CoordFunction(SageObject):
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
- - coordinate function resulting from the subtraction of ``other`` from
- ``self``
+ - coordinate function resulting from the subtraction of ``other``
+ from ``self``
TESTS::
@@ -292,7 +293,7 @@ class CoordFunction(SageObject):
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
@@ -323,7 +324,7 @@ class CoordFunction(SageObject):
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
@@ -352,12 +353,12 @@ class CoordFunction(SageObject):
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
- - coordinate function resulting from the division of ``other`` by
- ``self``
+ - coordinate function resulting from the division of ``other``
+ by ``self``
TESTS::
@@ -381,7 +382,7 @@ class CoordFunction(SageObject):
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
@@ -408,11 +409,12 @@ class CoordFunction(SageObject):
# Methods to be implemented by derived classes
# --------------------------------------------
+ @abstract_method
def _repr_(self):
r"""
String representation of the object.
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -425,15 +427,14 @@ class CoordFunction(SageObject):
Traceback (most recent call last):
...
NotImplementedError: CoordFunction._repr_ not implemented
-
"""
- raise NotImplementedError("CoordFunction._repr_ not implemented")
+ @abstract_method
def _latex_(self):
r"""
LaTeX representation of the object.
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -446,15 +447,14 @@ class CoordFunction(SageObject):
Traceback (most recent call last):
...
NotImplementedError: CoordFunction._latex_ not implemented
-
"""
- raise NotImplementedError("CoordFunction._latex_ not implemented")
+ @abstract_method
def display(self):
r"""
Display the function in arrow notation.
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -467,23 +467,21 @@ class CoordFunction(SageObject):
Traceback (most recent call last):
...
NotImplementedError: CoordFunction.display not implemented
-
"""
- raise NotImplementedError("CoordFunction.display not implemented")
disp = display
+ @abstract_method
def expr(self):
r"""
Return some data that, along with the chart, is sufficient to
reconstruct the object.
For a symbolic coordinate function, this returns the symbol
- expression representing the function
- (see
+ expression representing the function (see
:meth:`sage.manifolds.coord_func_symb.CoordFunctionSymb.expr`)
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -498,25 +496,25 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.expr not implemented
"""
- raise NotImplementedError("CoordFunction.expr not implemented")
+ @abstract_method
def __call__(self, *coords, **options):
r"""
Compute the value of the function at specified coordinates.
INPUT:
- - ``*coords`` -- list of coordinates `(x^1,...,x^n)` where the
- function `f` is to be evaluated
+ - ``*coords`` -- list of coordinates `(x^1, \ldots ,x^n)`,
+ where the function `f` is to be evaluated
- ``**options`` -- options to control the computation (e.g.
simplification options)
OUTPUT:
- - the value `f(x^1,...,x^n)`, where `f` is the current coordinate
- function.
+ - the value `f(x^1, \ldots, x^n)`, where `f` is the current
+ coordinate function
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -531,13 +529,13 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.__call__ not implemented
"""
- raise NotImplementedError("CoordFunction.__call__ not implemented")
+ @abstract_method
def is_zero(self):
r"""
Return ``True`` if the function is zero and ``False`` otherwise.
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -552,8 +550,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.is_zero not implemented
"""
- raise NotImplementedError("CoordFunction.is_zero not implemented")
+ @abstract_method
def copy(self):
r"""
Return an exact copy of the object.
@@ -562,7 +560,7 @@ class CoordFunction(SageObject):
- an instance of :class:`CoordFunction`
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -577,8 +575,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.copy not implemented
"""
- raise NotImplementedError("CoordFunction.copy not implemented")
+ @abstract_method
def diff(self, coord):
r"""
Partial derivative with respect to a coordinate.
@@ -596,7 +594,7 @@ class CoordFunction(SageObject):
- instance of :class:`CoordFunction` representing the partial
derivative `\frac{\partial f}{\partial x^i}`
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -611,21 +609,21 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.diff not implemented
"""
- raise NotImplementedError("CoordFunction.diff not implemented")
+ @abstract_method
def __eq__(self, other):
r"""
Comparison (equality) operator.
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
- ``True`` if ``self`` is equal to ``other``, or ``False`` otherwise
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -641,7 +639,6 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.__eq__ not implemented
"""
- raise NotImplementedError("CoordFunction.__eq__ not implemented")
def __pos__(self):
r"""
@@ -649,25 +646,28 @@ class CoordFunction(SageObject):
OUTPUT:
- - an exact copy of ``self``
+ - ``self``
- TEST:
+ TESTS:
- This method must be implemented by derived classes; it is not
- implemented here::
+ Coordinate functions associated to a 2-dimensional chart::
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.__pos__()
- Traceback (most recent call last):
- ...
- NotImplementedError: CoordFunction.__pos__ not implemented
+ 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
"""
- raise NotImplementedError("CoordFunction.__pos__ not implemented")
+ return self
+ @abstract_method
def __neg__(self):
r"""
Unary minus operator.
@@ -676,7 +676,7 @@ class CoordFunction(SageObject):
- the opposite of the coordinate function ``self``
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -691,22 +691,22 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.__neg__ not implemented
"""
- raise NotImplementedError("CoordFunction.__neg__ not implemented")
+ @abstract_method
def __invert__(self):
r"""
Inverse operator.
If `f` denotes the current coordinate function and `K` the topological
field over which the manifold is defined, the *inverse* of `f` is the
- coordinate function `1/f`, where `1` of the multiplicative identity
+ coordinate function `1 / f`, where `1` of the multiplicative identity
of `K`.
OUTPUT:
- the inverse of the coordinate function ``self``
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -721,22 +721,22 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.__invert__ not implemented
"""
- raise NotImplementedError("CoordFunction.__invert__ not implemented")
+ @abstract_method
def __add__(self, other):
r"""
Addition operator.
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
- coordinate function resulting from the addition of ``self`` and
``other``
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -751,22 +751,22 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.__add__ not implemented
"""
- raise NotImplementedError("CoordFunction.__add__ not implemented")
+ @abstract_method
def __sub__(self, other):
r"""
Subtraction operator.
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
- coordinate function resulting from the subtraction of ``other`` from
``self``
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -781,22 +781,22 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.__sub__ not implemented
"""
- raise NotImplementedError("CoordFunction.__sub__ not implemented")
+ @abstract_method
def __mul__(self, other):
r"""
Multiplication operator.
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
- coordinate function resulting from the multiplication of ``self`` by
``other``
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -811,22 +811,22 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.__mul__ not implemented
"""
- raise NotImplementedError("CoordFunction.__mul__ not implemented")
+ @abstract_method
def __div__(self, other):
r"""
Division operator.
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
- coordinate function resulting from the division of ``self`` by
``other``
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -841,8 +841,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.__div__ not implemented
"""
- raise NotImplementedError("CoordFunction.__div__ not implemented")
+ @abstract_method
def exp(self):
r"""
Exponential of the coordinate function.
@@ -852,7 +852,7 @@ class CoordFunction(SageObject):
- coordinate function `\exp(f)`, where `f` is the current coordinate
function.
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -867,9 +867,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.exp not implemented
"""
- raise NotImplementedError("CoordFunction.exp not implemented")
-
+ @abstract_method
def log(self, base=None):
r"""
Logarithm of the coordinate function.
@@ -884,7 +883,7 @@ class CoordFunction(SageObject):
- coordinate function `\log_a(f)`, where `f` is the current coordinate
function and `a` is the base
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -899,9 +898,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.log not implemented
"""
- raise NotImplementedError("CoordFunction.log not implemented")
-
+ @abstract_method
def __pow__(self, exponent):
r"""
Power of the coordinate function.
@@ -915,7 +913,7 @@ class CoordFunction(SageObject):
- coordinate function `f^a`, where `f` is the current coordinate
function and `a` is the exponent
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -930,9 +928,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.__pow__ not implemented
"""
- raise NotImplementedError("CoordFunction.__pow__ not implemented")
-
+ @abstract_method
def sqrt(self):
r"""
Square root of the coordinate function.
@@ -940,9 +937,9 @@ class CoordFunction(SageObject):
OUTPUT:
- coordinate function `\sqrt{f}`, where `f` is the current coordinate
- function.
+ function
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -957,8 +954,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.sqrt not implemented
"""
- raise NotImplementedError("CoordFunction.sqrt not implemented")
+ @abstract_method
def cos(self):
r"""
Cosine of the coordinate function.
@@ -966,9 +963,9 @@ class CoordFunction(SageObject):
OUTPUT:
- coordinate function `\cos(f)`, where `f` is the current coordinate
- function.
+ function
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -983,8 +980,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.cos not implemented
"""
- raise NotImplementedError("CoordFunction.cos not implemented")
+ @abstract_method
def sin(self):
r"""
Sine of the coordinate function.
@@ -992,9 +989,9 @@ class CoordFunction(SageObject):
OUTPUT:
- coordinate function `\sin(f)`, where `f` is the current coordinate
- function.
+ function
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -1009,8 +1006,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.sin not implemented
"""
- raise NotImplementedError("CoordFunction.sin not implemented")
+ @abstract_method
def tan(self):
r"""
Tangent of the coordinate function.
@@ -1018,9 +1015,9 @@ class CoordFunction(SageObject):
OUTPUT:
- coordinate function `\tan(f)`, where `f` is the current coordinate
- function.
+ function
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -1035,8 +1032,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.tan not implemented
"""
- raise NotImplementedError("CoordFunction.tan not implemented")
+ @abstract_method
def arccos(self):
r"""
Arc cosine of the coordinate function.
@@ -1044,9 +1041,9 @@ class CoordFunction(SageObject):
OUTPUT:
- coordinate function `\arccos(f)`, where `f` is the current coordinate
- function.
+ function
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -1061,8 +1058,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.arccos not implemented
"""
- raise NotImplementedError("CoordFunction.arccos not implemented")
+ @abstract_method
def arcsin(self):
r"""
Arc sine of the coordinate function.
@@ -1070,9 +1067,9 @@ class CoordFunction(SageObject):
OUTPUT:
- coordinate function `\arcsin(f)`, where `f` is the current coordinate
- function.
+ function
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -1087,8 +1084,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.arcsin not implemented
"""
- raise NotImplementedError("CoordFunction.arcsin not implemented")
+ @abstract_method
def arctan(self):
r"""
Arc tangent of the coordinate function.
@@ -1096,9 +1093,9 @@ class CoordFunction(SageObject):
OUTPUT:
- coordinate function `\arctan(f)`, where `f` is the current coordinate
- function.
+ function
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -1113,8 +1110,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.arctan not implemented
"""
- raise NotImplementedError("CoordFunction.arctan not implemented")
+ @abstract_method
def cosh(self):
r"""
Hyperbolic cosine of the coordinate function.
@@ -1122,9 +1119,9 @@ class CoordFunction(SageObject):
OUTPUT:
- coordinate function `\cosh(f)`, where `f` is the current coordinate
- function.
+ function
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -1139,8 +1136,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.cosh not implemented
"""
- raise NotImplementedError("CoordFunction.cosh not implemented")
+ @abstract_method
def sinh(self):
r"""
Hyperbolic sine of the coordinate function.
@@ -1148,9 +1145,9 @@ class CoordFunction(SageObject):
OUTPUT:
- coordinate function `\sinh(f)`, where `f` is the current coordinate
- function.
+ function
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -1165,8 +1162,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.sinh not implemented
"""
- raise NotImplementedError("CoordFunction.sinh not implemented")
+ @abstract_method
def tanh(self):
r"""
Hyperbolic tangent of the coordinate function.
@@ -1174,9 +1171,9 @@ class CoordFunction(SageObject):
OUTPUT:
- coordinate function `\tanh(f)`, where `f` is the current coordinate
- function.
+ function
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -1191,8 +1188,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.tanh not implemented
"""
- raise NotImplementedError("CoordFunction.tanh not implemented")
+ @abstract_method
def arccosh(self):
r"""
Inverse hyperbolic cosine of the coordinate function.
@@ -1200,9 +1197,9 @@ class CoordFunction(SageObject):
OUTPUT:
- coordinate function `\mathrm{arcosh}(f)`, where `f` is the current
- coordinate function.
+ coordinate function
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -1217,8 +1214,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.arccosh not implemented
"""
- raise NotImplementedError("CoordFunction.arccosh not implemented")
+ @abstract_method
def arcsinh(self):
r"""
Inverse hyperbolic sine of the coordinate function.
@@ -1226,9 +1223,9 @@ class CoordFunction(SageObject):
OUTPUT:
- coordinate function `\mathrm{arsinh}(f)`, where `f` is the current
- coordinate function.
+ coordinate function
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -1243,8 +1240,8 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.arcsinh not implemented
"""
- raise NotImplementedError("CoordFunction.arcsinh not implemented")
+ @abstract_method
def arctanh(self):
r"""
Inverse hyperbolic tangent of the coordinate function.
@@ -1252,9 +1249,9 @@ class CoordFunction(SageObject):
OUTPUT:
- coordinate function `\mathrm{artanh}(f)`, where `f` is the current
- coordinate function.
+ coordinate function
- TEST:
+ TESTS:
This method must be implemented by derived classes; it is not
implemented here::
@@ -1269,45 +1266,45 @@ class CoordFunction(SageObject):
NotImplementedError: CoordFunction.arctanh not implemented
"""
- raise NotImplementedError("CoordFunction.arctanh not implemented")
#*****************************************************************************
+# TODO: Make this and CoordFunction have a common ABC
class MultiCoordFunction(SageObject):
r"""
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
+ 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
+ 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
`K^m`-valued function of the coordinates associated to the chart
- `(U,\varphi)`. Each component `f_i` (`1\leq i \leq m`) is a coordinate
- function and is therefore stored as an instance of
+ `(U, \varphi)`. Each component `f_i` (`1 \leq i \leq m`) is a coordinate
+ function and is therefore stored as a
:class:`~sage.manifolds.coord_func.CoordFunction`.
INPUT:
- ``chart`` -- the chart `(U, \varphi)`
- ``expressions`` -- list (or tuple) of length `m` of elements to
- construct the coordinate functions `f_i` (`1\leq i \leq m`); for
+ construct the coordinate functions `f_i` (`1 \leq i \leq m`); for
symbolic coordinate functions, this must be symbolic expressions
- involving the chart coordinates, while for numerical coordinate functions,
- this must be data file names
+ involving the chart coordinates, while for numerical coordinate
+ functions, this must be data file names
EXAMPLES:
- A function `f: V\subset \RR^2 \longrightarrow \RR^3`::
+ A function `f: V \subset \RR^2 \longrightarrow \RR^3`::
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
@@ -1320,8 +1317,8 @@ class MultiCoordFunction(SageObject):
sage: latex(f)
\left(x - y, x y, \cos\left(x\right) e^{y}\right)
- Each real-valued function `f_i` (`1\leq i \leq m`) composing `f` can be
- accessed via the square-bracket operator, by providing `i-1` as an
+ Each real-valued function `f_i` (`1 \leq i \leq m`) composing `f` can
+ be accessed via the square-bracket operator, by providing `i-1` as an
argument::
sage: f[0]
@@ -1331,26 +1328,28 @@ class MultiCoordFunction(SageObject):
sage: f[2]
cos(x)*e^y
+ We can give a more verbose explanation of each function::
+
+ sage: f[0].display()
+ (x, y) |--> x - y
+
Each ``f[i-1]`` is an instance of
:class:`~sage.manifolds.coord_func.CoordFunction`::
sage: isinstance(f[0], sage.manifolds.coord_func.CoordFunction)
True
- In the present case, ``f[i-1]`` belongs to the subclass
+ In the present case, ``f[i-1]`` is an instance of the subclass
:class:`~sage.manifolds.coord_func_symb.CoordFunctionSymb`::
sage: type(f[0])
<class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
- sage: f[0].display()
- (x, y) |--> x - y
- An instance of class :class:`MultiCoordFunction` can represent a
- real-valued function (case `m=1`), although one should
+ A class :class:`MultiCoordFunction` can represent a
+ real-valued function (case `m = 1`), although one should
rather employ the class :class:`~sage.manifolds.coord_func.CoordFunction`
for this purpose::
-
sage: g = X.multifunction(x*y^2)
sage: g(x,y)
(x*y^2,)
@@ -1402,8 +1401,8 @@ class MultiCoordFunction(SageObject):
sage: f = X.multifunction(x-y, x*y, cos(x)*exp(y))
sage: f._repr_()
'Coordinate functions (x - y, x*y, cos(x)*e^y) on the Chart (M, (x, y))'
- sage: repr(f) # indirect doctest
- 'Coordinate functions (x - y, x*y, cos(x)*e^y) on the Chart (M, (x, y))'
+ sage: f
+ Coordinate functions (x - y, x*y, cos(x)*e^y) on the Chart (M, (x, y))
"""
return "Coordinate functions {} on the {}".format(self._functions,
@@ -1439,7 +1438,7 @@ class MultiCoordFunction(SageObject):
tuple of the symbolic expressions of the coordinate functions
composing the object.
- EXAMPLE::
+ EXAMPLES::
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
@@ -1459,13 +1458,14 @@ class MultiCoordFunction(SageObject):
def chart(self):
r"""
- Return the chart w.r.t. which the multi-coordinate function is defined.
+ Return the chart with respect to which the multi-coordinate
+ function is defined.
OUTPUT:
- - an instance of :class:`~sage.manifolds.chart.Chart`
+ - a :class:`~sage.manifolds.chart.Chart`
- EXAMPLE::
+ EXAMPLES::
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
@@ -1478,20 +1478,18 @@ class MultiCoordFunction(SageObject):
"""
return self._chart
-
def __eq__(self, other):
r"""
Comparison (equality) operator.
INPUT:
- - ``other`` -- another instance of :class:`MultiCoordFunction`
+ - ``other`` -- a :class:`MultiCoordFunction`
OUTPUT:
- ``True`` if ``self`` is equal to ``other``, ``False`` otherwise
-
TESTS::
sage: M = Manifold(2, 'M', structure='topological')
@@ -1527,7 +1525,7 @@ class MultiCoordFunction(SageObject):
INPUT:
- - ``other`` -- another instance of :class:`MultiCoordFunction`
+ - ``other`` -- a :class:`MultiCoordFunction`
OUTPUT:
@@ -1555,11 +1553,11 @@ class MultiCoordFunction(SageObject):
INPUT:
- -- ``index`` -- index `i` of the function (`0\leq i \leq m-1`)
+ - ``index`` -- index `i` of the function (`0 \leq i \leq m-1`)
OUTPUT
- -- instance of :class:`CoordFunction` representing the function
+ -- a :class:`CoordFunction` representing the function
TESTS::
@@ -1613,12 +1611,11 @@ class MultiCoordFunction(SageObject):
r"""
Return the Jacobian matrix of the system of coordinate functions.
- ``jacobian()`` is a 2-dimensional array of size `m\times n`
+ ``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).
-
- Each `J_{ij}` is an instance of :class:`CoordFunction`.
+ with `1 \leq i \leq m` (row index) and `1 \leq j \leq n`
+ (column index).
OUTPUT:
@@ -1636,7 +1633,8 @@ class MultiCoordFunction(SageObject):
sage: f.jacobian()
[[1, -1], [y, x], [-y^3*sin(x), 3*y^2*cos(x)]]
- Each element of the result is a coordinate function::
+ Each element of the result is a
+ :class:`coordinate function <CoordFunction>`::
sage: type(f.jacobian()[2][0])
<class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
@@ -1648,7 +1646,7 @@ class MultiCoordFunction(SageObject):
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``::
+ Test with ``start_index = 1``::
sage: M = Manifold(2, 'M', structure='topological', start_index=1)
sage: X.<x,y> = M.chart()
@@ -1658,7 +1656,6 @@ class MultiCoordFunction(SageObject):
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
@@ -1675,9 +1672,9 @@ class MultiCoordFunction(SageObject):
OUTPUT:
- - instance of :class:`CoordFunction` representing the determinant
+ - a :class:`CoordFunction` representing the determinant
- EXAMPLE:
+ EXAMPLES:
Jacobian determinant of a set of 2 functions of 2 coordinates::
@@ -1688,8 +1685,8 @@ class MultiCoordFunction(SageObject):
x + y
The output of :meth:`jacobian_det` is an instance of
- :class:`CoordFunction` and can therefore be called on specific values
- of the coordinates, e.g. (x,y)=(1,2)::
+ :class:`CoordFunction` and can therefore be called on specific
+ values of the coordinates, e.g. `(x,y) = (1,2)`::
sage: type(f.jacobian_det())
<class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
@@ -1703,7 +1700,7 @@ class MultiCoordFunction(SageObject):
sage: f.jacobian_det() is f.jacobian_det()
True
- Test::
+ We verify the determinant of the Jacobian::
sage: f.jacobian_det() == det(matrix([[f[i].diff(j).expr() for j in range(2)]
....: for i in range(2)]))
@@ -1717,7 +1714,7 @@ class MultiCoordFunction(SageObject):
sage: f.jacobian_det().display()
(x, y, z) |--> 6*x^3*y^5*z^3 - 3*x^4*y^3*z^4 - 12*x^2*y^4*z^5 + 6*x^3*y^2*z^6
- Test::
+ We verify the determinant of the Jacobian::
sage: f.jacobian_det() == det(matrix([[f[i].diff(j).expr() for j in range(3)]
....: for i in range(3)]))
@@ -1760,3 +1757,4 @@ class MultiCoordFunction(SageObject):
self.jacobian() # forces the computation of self._jacob
self._jacob_det = simple_determinant(self._jacob)
return self._jacob_det
+
diff --git a/src/sage/manifolds/coord_func_symb.py b/src/sage/manifolds/coord_func_symb.py
index 4c45741..a2c275c 100644
--- a/src/sage/manifolds/coord_func_symb.py
+++ b/src/sage/manifolds/coord_func_symb.py
@@ -6,16 +6,16 @@ a *coordinate function* is a function from a chart codomain
to `K`. In other words, a coordinate function is a `K`-valued function of
the coordinates associated to some chart.
-More precisely, let `(U,\varphi)` be a chart on `M`, i.e. `U` is an open
-subset of `M` and `\varphi: U \rightarrow V \subset K^n` is a homeomorphism
+More precisely, let `(U, \varphi)` be a chart on `M`, i.e. `U` is an open
+subset of `M` and `\varphi: U \to V \subset K^n` is a homeomorphism
from `U` to an open subset `V` of `K^n`. A *coordinate function associated
-to the chart* `(U,\varphi)` is a function
+to the chart* `(U, \varphi)` is a function
.. MATH::
\begin{array}{cccc}
- f:& V\subset K^n & \longrightarrow & K \\
- & (x^1,\ldots, x^n) & \longmapsto & f(x^1,\ldots, x^n)
+ f:& V \subset K^n & \longrightarrow & K \\
+ & (x^1, \ldots, x^n) & \longmapsto & f(x^1, \ldots, x^n)
\end{array}
This module implements symbolic coordinate functions via the class
@@ -40,34 +40,35 @@ from sage.symbolic.ring import SR
from sage.structure.element import RingElement
from sage.misc.latex import latex
from sage.manifolds.coord_func import CoordFunction, MultiCoordFunction
-from sage.manifolds.utilities import ExpressionNice, simplify_chain_real, \
- simplify_chain_generic
+from sage.manifolds.utilities import (ExpressionNice, simplify_chain_real,
+ simplify_chain_generic)
class CoordFunctionSymb(CoordFunction):
r"""
Coordinate function with symbolic representation.
- 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
+ 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
.. MATH::
\begin{array}{llcl}
f:& V \subset K^n & \longrightarrow & K \\
- & (x^1,\ldots,x^n) & \longmapsto & f(x^1,\ldots,x^n),
+ & (x^1, \ldots, x^n) & \longmapsto & f(x^1, \ldots, x^n),
\end{array}
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)`.
+ coordinates associated to the chart `(U, \varphi)`.
INPUT:
- - ``chart`` -- the chart `(U, \varphi)`, as an instance of class
- :class:`~sage.manifolds.chart.Chart`
- - ``expression`` -- a symbolic expression representing `f(x^1,\ldots,x^n)`,
- where `(x^1,\ldots,x^n)` are the coordinates of the chart `(U, \varphi)`
+ - ``chart`` -- :class:`~sage.manifolds.chart.Chart`;
+ the chart `(U, \varphi)`
+ - ``expression`` -- a symbolic expression representing
+ `f(x^1, \ldots, x^n)`, where `(x^1, \ldots, x^n)` are the
+ coordinates of the chart `(U, \varphi)`
EXAMPLES:
@@ -132,8 +133,8 @@ class CoordFunctionSymb(CoordFunction):
sage: f == h
True
- .. RUBRIC:: Differences between ``CoordFunctionSymb`` and callable symbolic
- expressions
+ .. RUBRIC:: Differences between ``CoordFunctionSymb`` and callable
+ symbolic expressions
Callable symbolic expressions are defined directly from symbolic
expressions of the coordinates::
@@ -175,15 +176,16 @@ class CoordFunctionSymb(CoordFunction):
On the contrary, the sum of the corresponding :class:`CoordFunctionSymb`
instances is automatically simplified (see
- :func:`~sage.manifolds.utilities.simplify_chain_real`
- and :func:`~sage.manifolds.utilities.simplify_chain_generic` for details)::
+ :func:`~sage.manifolds.utilities.simplify_chain_real` and
+ :func:`~sage.manifolds.utilities.simplify_chain_generic` for details)::
sage: f = X.function(cos(x)^2) ; g = X.function(sin(x)^2)
sage: f + g
1
- Another difference regards the display of partial derivatives: for callable
- symbolic functions, it relies on Pynac notation ``D[0]``, ``D[1]``, etc.::
+ Another difference regards the display of partial derivatives:
+ for callable symbolic functions, it relies on Pynac notation
+ ``D[0]``, ``D[1]``, etc.::
sage: g = function('g')(x, y)
sage: f0(x,y) = diff(g, x) + diff(g, y)
@@ -199,13 +201,14 @@ class CoordFunctionSymb(CoordFunction):
The difference is even more dramatic on LaTeX outputs::
sage: latex(f0)
- \left( x, y \right) \ {\mapsto} \ D[0]\left(g\right)\left(x, y\right) + D[1]\left(g\right)\left(x, y\right)
+ \left( x, y \right) \ {\mapsto} \ D[0]\left(g\right)\left(x, y\right)
+ + D[1]\left(g\right)\left(x, y\right)
sage: latex(f)
\frac{\partial\,g}{\partial x} + \frac{\partial\,g}{\partial y}
Note that this regards only the display of coordinate functions:
internally, the Pynac notation is still used, as we can check by asking
- for the symbolic expression stored in `f`::
+ for the symbolic expression stored in ``f``::
sage: f.expr()
D[0](g)(x, y) + D[1](g)(x, y)
@@ -349,8 +352,8 @@ class CoordFunctionSymb(CoordFunction):
r"""
Display the function in arrow notation.
- The output is either text-formatted (console mode) or LaTeX-formatted
- (notebook mode).
+ The output is either text-formatted (console mode) or
+ LaTeX-formatted (notebook mode).
EXAMPLES:
@@ -386,13 +389,13 @@ 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
+ the coordinate function.
OUTPUT:
- - symbolic expression, involving the chart coordinates (instance of
- :class:`sage.symbolic.expression.Expression`)
+ - :class:`symbolic expression <sage.symbolic.expression.Expression>`
+ involving the chart coordinates
EXAMPLES:
@@ -423,8 +426,8 @@ class CoordFunctionSymb(CoordFunction):
sage: f.expr().subs(a=2)
2*x*y
- Note that for substituting the value of a coordinate, the function call
- can be used as well::
+ Note that for substituting the value of a coordinate, the function
+ call can be used as well::
sage: f(x,3)
3*a*x
@@ -440,15 +443,15 @@ class CoordFunctionSymb(CoordFunction):
INPUT:
- - ``*coords`` -- list of coordinates `(x^1,...,x^n)` where the
- function `f` is to be evaluated
+ - ``*coords`` -- list of coordinates `(x^1, \ldots, x^n)`,
+ where the function `f` is to be evaluated
- ``**options`` -- allows to pass ``simplify=False`` to disable the
call of the simplification chain on the result
OUTPUT:
- - the value `f(x^1,...,x^n)`, where `f` is the current coordinate
- function.
+ - the value `f(x^1, \ldots, x^n)`, where `f` is the current
+ coordinate function
TESTS::
@@ -517,9 +520,9 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - an instance of :class:`CoordFunctionSymb`
+ - a :class:`CoordFunctionSymb`
- EXAMPLE::
+ EXAMPLES::
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
@@ -542,7 +545,6 @@ class CoordFunctionSymb(CoordFunction):
"""
return CoordFunctionSymb(self._chart, self._express)
-
def diff(self, coord):
r"""
Partial derivative with respect to a coordinate.
@@ -557,7 +559,7 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - instance of :class:`CoordFunctionSymb` representing the partial
+ - a :class:`CoordFunctionSymb` representing the partial
derivative `\frac{\partial f}{\partial x^i}`
EXAMPLES:
@@ -625,7 +627,7 @@ class CoordFunctionSymb(CoordFunction):
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
@@ -666,33 +668,6 @@ class CoordFunctionSymb(CoordFunction):
else:
return bool(self._express == other)
- def __pos__(self):
- r"""
- Unary plus operator.
-
- This method is identical to :meth:`copy`.
-
- OUTPUT:
-
- - an exact copy of ``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
-
- """
- return CoordFunctionSymb(self._chart, self._express)
-
def __neg__(self):
r"""
Unary minus operator.
@@ -760,12 +735,12 @@ class CoordFunctionSymb(CoordFunction):
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
- - coordinate function resulting from the addition of ``self`` and
- ``other``
+ - coordinate function resulting from the addition of ``self``
+ and ``other``
TESTS::
@@ -814,12 +789,12 @@ class CoordFunctionSymb(CoordFunction):
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
- - coordinate function resulting from the subtraction of ``other`` from
- ``self``
+ - coordinate function resulting from the subtraction of ``other``
+ from ``self``
TESTS::
@@ -871,12 +846,12 @@ class CoordFunctionSymb(CoordFunction):
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
- - coordinate function resulting from the multiplication of ``self`` by
- ``other``
+ - coordinate function resulting from the multiplication of ``self``
+ by ``other``
TESTS::
@@ -926,12 +901,12 @@ class CoordFunctionSymb(CoordFunction):
INPUT:
- - ``other`` -- another instance of :class:`CoordFunction` or a value
+ - ``other`` -- a :class:`CoordFunction` or a value
OUTPUT:
- - coordinate function resulting from the division of ``self`` by
- ``other``
+ - coordinate function resulting from the division of ``self``
+ by ``other``
TESTS::
@@ -988,8 +963,8 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - coordinate function `\exp(f)`, where `f` is the current coordinate
- function.
+ - coordinate function `\exp(f)`, where `f` is the current
+ coordinate function
EXAMPLES::
@@ -1015,8 +990,8 @@ class CoordFunctionSymb(CoordFunction):
INPUT:
- - ``base`` -- (default: ``None``) base of the logarithm; if None, the
- natural logarithm (i.e. logarithm to base e) is returned
+ - ``base`` -- (default: ``None``) base of the logarithm; if ``None``,
+ the natural logarithm (i.e. logarithm to base `e`) is returned
OUTPUT:
@@ -1084,8 +1059,8 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - coordinate function `\sqrt{f}`, where `f` is the current coordinate
- function.
+ - coordinate function `\sqrt{f}`, where `f` is the current
+ coordinate function
EXAMPLES::
@@ -1111,8 +1086,8 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - coordinate function `\cos(f)`, where `f` is the current coordinate
- function.
+ - coordinate function `\cos(f)`, where `f` is the current
+ coordinate function
EXAMPLES::
@@ -1138,8 +1113,8 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - coordinate function `\sin(f)`, where `f` is the current coordinate
- function.
+ - coordinate function `\sin(f)`, where `f` is the current
+ coordinate function
EXAMPLES::
@@ -1165,8 +1140,8 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - coordinate function `\tan(f)`, where `f` is the current coordinate
- function.
+ - coordinate function `\tan(f)`, where `f` is the current
+ coordinate function
EXAMPLES::
@@ -1192,8 +1167,8 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - coordinate function `\arccos(f)`, where `f` is the current coordinate
- function.
+ - coordinate function `\arccos(f)`, where `f` is the current
+ coordinate function
EXAMPLES::
@@ -1221,8 +1196,8 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - coordinate function `\arcsin(f)`, where `f` is the current coordinate
- function.
+ - coordinate function `\arcsin(f)`, where `f` is the current
+ coordinate function
EXAMPLES::
@@ -1250,8 +1225,8 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - coordinate function `\arctan(f)`, where `f` is the current coordinate
- function.
+ - coordinate function `\arctan(f)`, where `f` is the current
+ coordinate function
EXAMPLES::
@@ -1279,8 +1254,8 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - coordinate function `\cosh(f)`, where `f` is the current coordinate
- function.
+ - coordinate function `\cosh(f)`, where `f` is the current
+ coordinate function
EXAMPLES::
@@ -1306,8 +1281,8 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - coordinate function `\sinh(f)`, where `f` is the current coordinate
- function.
+ - coordinate function `\sinh(f)`, where `f` is the current
+ coordinate function
EXAMPLES::
@@ -1333,8 +1308,8 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - coordinate function `\tanh(f)`, where `f` is the current coordinate
- function.
+ - coordinate function `\tanh(f)`, where `f` is the current
+ coordinate function
EXAMPLES::
@@ -1361,7 +1336,7 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- coordinate function `\mathrm{arcosh}(f)`, where `f` is the current
- coordinate function.
+ coordinate function
EXAMPLES::
@@ -1390,7 +1365,7 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- coordinate function `\mathrm{arsinh}(f)`, where `f` is the current
- coordinate function.
+ coordinate function
EXAMPLES::
@@ -1418,8 +1393,8 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - coordinate function `\mathrm{artanh}(f)`, where `f` is the current
- coordinate function.
+ - coordinate function `\mathrm{artanh}(f)`, where `f` is the
+ current coordinate function
EXAMPLES::
@@ -1447,7 +1422,7 @@ class CoordFunctionSymb(CoordFunction):
def _del_derived(self):
r"""
- Delete the derived quantities
+ Delete the derived quantities.
TESTS::
@@ -1477,7 +1452,7 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - the coordinate function, with its expression simplified.
+ - the coordinate function, with its expression simplified
EXAMPLES:
@@ -1536,7 +1511,7 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - the coordinate function, with its expression factorized.
+ - the coordinate function, with its expression factorized
EXAMPLES:
@@ -1566,7 +1541,7 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- - the coordinate function, with its expression expanded.
+ - the coordinate function, with its expression expanded
EXAMPLES:
@@ -1602,7 +1577,7 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- the coordinate function, with the coefficients of ``s`` grouped in
- its expression.
+ its expression
EXAMPLES:
@@ -1637,7 +1612,7 @@ class CoordFunctionSymb(CoordFunction):
OUTPUT:
- the coordinate function, with the common factors collected in
- its expression.
+ its expression
EXAMPLES:
@@ -1662,3 +1637,4 @@ class CoordFunctionSymb(CoordFunction):
self._express = self._express.collect_common_factors()
self._del_derived()
return self
+
diff --git a/src/sage/manifolds/manifold.py b/src/sage/manifolds/manifold.py
index 28cc60c..7c6a8ce 100644
--- a/src/sage/manifolds/manifold.py
+++ b/src/sage/manifolds/manifold.py
@@ -169,7 +169,7 @@ Similarly::
sage: stereoN(S)
(0, 0)
-A continuous map `S^2\rightarrow \RR` (scalar field)::
+A continuous map `S^2 \to \RR` (scalar field)::
sage: f = M.scalar_field({stereoN: atan(x^2+y^2), stereoS: pi/2-atan(u^2+v^2)},
....: name='f')
@@ -1546,9 +1546,9 @@ class TopologicalManifold(ManifoldSubset):
- instance of
:class:`~sage.manifolds.scalarfield_algebra.ScalarFieldAlgebra`
representing the algebra `C^0(U)` of all scalar fields defined
- on `U` = ``self``.
+ on `U` = ``self``
- EXAMPLE:
+ EXAMPLES:
Scalar algebra of a 3-dimensional open subset::
@@ -1582,31 +1582,34 @@ class TopologicalManifold(ManifoldSubset):
- ``coord_expression`` -- (default: ``None``) coordinate expression(s)
of the scalar field; this can be either
- - a single coordinate expression; if the argument ``chart`` is
+ * 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``
- - a dictionary of coordinate expressions, with the charts as keys.
-
- If ``coord_expression`` is ``None`` or does not fully specified the
- scalar field, other coordinate expressions can be added subsequently
- by means of the methods
- :meth:`~sage.manifolds.scalarfield.ScalarField.add_expr`,
- :meth:`~sage.manifolds.scalarfield.ScalarField.add_expr_by_continuation`,
- or :meth:`~sage.manifolds.scalarfield.ScalarField.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).
+ * a dictionary of coordinate expressions, with the charts as keys
+
+ - ``chart`` -- (default: ``None``) chart defining the coordinates
+ used in ``coord_expression`` when the latter is a single
+ coordinate expression; if ``None``, 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``) name given to the scalar field
- - ``latex_name`` -- (default: ``None``) LaTeX symbol to denote the scalar
- field; if none is provided, the LaTeX symbol is set to ``name``
+
+ - ``latex_name`` -- (default: ``None``) LaTeX symbol to denote the
+ scalar field; if ``None``, the LaTeX symbol is set to ``name``
+
+ If ``coord_expression`` is ``None`` or does not fully specified the
+ scalar field, other coordinate expressions can be added subsequently
+ by means of the methods
+ :meth:`~sage.manifolds.scalarfield.ScalarField.add_expr`,
+ :meth:`~sage.manifolds.scalarfield.ScalarField.add_expr_by_continuation`,
+ or :meth:`~sage.manifolds.scalarfield.ScalarField.set_expr`
OUTPUT:
- instance of :class:`~sage.manifolds.scalarfield.ScalarField`
- representing the defined scalar field.
+ representing the defined scalar field
EXAMPLES:
@@ -1670,7 +1673,7 @@ class TopologicalManifold(ManifoldSubset):
value or a symbolic expression not involving any chart coordinates
- ``name`` -- (default: ``None``) name given to the scalar field
- ``latex_name`` -- (default: ``None``) LaTeX symbol to denote the
- scalar field; if none is provided, the LaTeX symbol is set to ``name``
+ scalar field; if ``None``, the LaTeX symbol is set to ``name``
OUTPUT:
@@ -1723,7 +1726,7 @@ class TopologicalManifold(ManifoldSubset):
OUTPUT:
- instance of :class:`~sage.manifolds.scalarfield.ScalarField`
- representing the constant scalar field with value 0.
+ representing the constant scalar field with value 0
EXAMPLE::
@@ -1751,7 +1754,7 @@ class TopologicalManifold(ManifoldSubset):
- instance of :class:`~sage.manifolds.scalarfield.ScalarField`
representing the constant scalar field with value the unit element
- of the manifold's base field.
+ of the manifold's base field
EXAMPLE::
diff --git a/src/sage/manifolds/scalarfield.py b/src/sage/manifolds/scalarfield.py
index 7ce1b31..b48974d 100644
--- a/src/sage/manifolds/scalarfield.py
+++ b/src/sage/manifolds/scalarfield.py
@@ -17,9 +17,9 @@ AUTHORS:
REFERENCES:
-- J.M. Lee : *Introduction to Topological Manifolds*, 2nd ed., Springer (New
+- [Lee11]_ : *Introduction to Topological Manifolds*, 2nd ed., Springer (New
York) (2011)
-- S. Kobayashi & K. Nomizu : *Foundations of Differential Geometry*, vol. 1,
+- [KN63]_ : *Foundations of Differential Geometry*, vol. 1,
Interscience Publishers (New York) (1963)
"""
@@ -49,10 +49,10 @@ class ScalarField(CommutativeAlgebraElement):
.. MATH::
- f: M \longrightarrow K .
+ f: M \longrightarrow K.
- The class :class:`ScalarField` inherits from the class :class:`~sage.structure.element.CommutativeAlgebraElement`, a scalar field
- on `M` being an element of the commutative algebra `C^0(M)` (see
+ A scalar field on `M` is an element of the commutative algebra
+ `C^0(M)` (see
:class:`~sage.manifolds.scalarfield_algebra.ScalarFieldAlgebra`).
INPUT:
@@ -60,30 +60,34 @@ class ScalarField(CommutativeAlgebraElement):
- ``parent`` -- the algebra of scalar fields containing the scalar field
(must be an instance of class
:class:`~sage.manifolds.scalarfield_algebra.ScalarFieldAlgebra`)
+
- ``coord_expression`` -- (default: ``None``) coordinate expression(s) of
the scalar field; this can be either
- - 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
+ * 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``
+ 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`.
+
EXAMPLES:
A scalar field on the 2-sphere::
@@ -468,8 +472,8 @@ class ScalarField(CommutativeAlgebraElement):
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)
- However, if the symbolic variable is a chart coordinate, the multiplication
- is performed only in the corresponding chart::
+ However, if the symbolic variable is a chart coordinate, the
+ multiplication is performed only in the corresponding chart::
sage: s = x*f; s
Scalar field on the 2-dimensional topological manifold M
@@ -511,10 +515,10 @@ class ScalarField(CommutativeAlgebraElement):
(x, y) |--> x*y*H(x, y)
on W: (u, v) |--> u*v*H(u/(u^2 + v^2), v/(u^2 + v^2))/(u^4 + 2*u^2*v^2 + v^4)
- Thanks to the coercion `C^0(M)\rightarrow C^0(U)` mentionned
- above, it is possible to multiply a scalar field defined on `M` by a
- scalar field defined on `U`, the result being a scalar field defined on
- `U`::
+ Thanks to the coercion `C^0(M) \to C^0(U)` mentioned above,
+ it is possible to multiply a scalar field defined on `M` by a
+ scalar field defined on `U`, the result being a scalar field
+ defined on `U`::
sage: f.domain(), g.domain()
(2-dimensional topological manifold M,
@@ -603,7 +607,7 @@ class ScalarField(CommutativeAlgebraElement):
r"""
Construct a scalar field.
- TEST::
+ TESTS::
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
@@ -656,9 +660,9 @@ class ScalarField(CommutativeAlgebraElement):
def __nonzero__(self):
r"""
- Return True if ``self`` is nonzero and False otherwise.
+ Return ``True`` if ``self`` is nonzero and ``False`` otherwise.
- This method is called by self.is_zero().
+ This method is called by :meth:`is_zero()`.
EXAMPLES:
@@ -773,31 +777,6 @@ class ScalarField(CommutativeAlgebraElement):
"""
return not (self == other)
- def __cmp__(self, other):
- r"""
- Old-style (Python 2) comparison operator.
-
- This is provisory, until migration to Python 3 is achieved.
-
- TESTS::
-
- sage: M = Manifold(2, 'M', structure='topological')
- sage: X.<x,y> = M.chart()
- sage: f = M.scalar_field({X: x+y})
- sage: f.__cmp__(1)
- -1
- sage: f.__cmp__(M.zero_scalar_field())
- -1
- sage: g = M.scalar_field({X: x+y})
- sage: f.__cmp__(g)
- 0
-
- """
- if self == other:
- return 0
- else:
- return -1
-
####### End of required methods for an algebra element (beside arithmetic) #######
def _init_derived(self):
@@ -853,8 +832,8 @@ class ScalarField(CommutativeAlgebraElement):
sage: f = M.scalar_field({X: x+y}, name='f')
sage: f._repr_()
'Scalar field f on the 2-dimensional topological manifold M'
- sage: repr(f) # indirect doctest
- 'Scalar field f on the 2-dimensional topological manifold M'
+ sage: f
+ Scalar field f on the 2-dimensional topological manifold M
"""
description = "Scalar field"
@@ -880,7 +859,7 @@ class ScalarField(CommutativeAlgebraElement):
sage: f = M.scalar_field({X: x+y}, name='f', latex_name=r'\Phi')
sage: f._latex_()
'\\Phi'
- sage: latex(f) # indirect doctest
+ sage: latex(f)
\Phi
"""
@@ -899,7 +878,7 @@ class ScalarField(CommutativeAlgebraElement):
field
- ``latex_name`` -- (string; default: ``None``) LaTeX symbol to denote
the scalar field; if ``None`` while ``name`` is provided, the LaTeX
- symbol is set to ``name``.
+ symbol is set to ``name``
EXAMPLES::
@@ -931,9 +910,10 @@ class ScalarField(CommutativeAlgebraElement):
OUTPUT:
- - instance of class :class:`~sage.manifolds.manifold.TopologicalManifold`
- representing the manifold's open subset on which the scalar field
- is defined.
+ - instance of class
+ :class:`~sage.manifolds.manifold.TopologicalManifold`
+ representing the manifold's open subset on which the
+ scalar field is defined
EXAMPLES::
@@ -991,13 +971,13 @@ class ScalarField(CommutativeAlgebraElement):
- ``from_chart`` -- (default: ``None``) chart from which the
required expression is computed if it is not known already in the
chart ``chart``; if ``None``, a chart is picked in the known
- expressions.
+ expressions
OUTPUT:
- instance of :class:`~sage.manifolds.coord_func.CoordFunction`
representing the coordinate function of the scalar field in the
- given chart.
+ given chart
EXAMPLES:
@@ -1028,7 +1008,8 @@ class ScalarField(CommutativeAlgebraElement):
{Chart (M, (x, y)): x*y^2, Chart (M, (u, v)): u^3 - u^2*v - u*v^2 + v^3}
Usage in a physical context (simple Lorentz transformation - boost in
- x direction, with relative velocity v between o1 and o2 frames)::
+ ``x`` direction, with relative velocity ``v`` between ``o1``
+ and ``o2`` frames)::
sage: M = Manifold(2, 'M', structure='topological')
sage: o1.<t,x> = M.chart()
@@ -1078,7 +1059,7 @@ class ScalarField(CommutativeAlgebraElement):
break
if not found:
raise ValueError("no starting chart could be found to " +
- "compute the expression in the {}".format(chart))
+ "compute the expression in the {}".format(chart))
change = self._domain._coord_changes[(chart, from_chart)]
# old coordinates expressed in terms of the new ones:
coords = [ change._transf._functions[i]._express
@@ -1263,7 +1244,7 @@ class ScalarField(CommutativeAlgebraElement):
in terms of the restriction of the coordinate chart `(U,(x^i))` to
`V` is already known or can be evaluated by a change of coordinates.
- EXAMPLE:
+ EXAMPLES:
Scalar field on the sphere `S^2`::
@@ -1279,13 +1260,13 @@ class ScalarField(CommutativeAlgebraElement):
sage: f = M.scalar_field(atan(x^2+y^2), chart=c_xy, name='f')
The scalar field has been defined only on the domain covered by the
- chart c_xy, i.e. `U`::
+ chart ``c_xy``, i.e. `U`::
sage: f.display()
f: S^2 --> R
on U: (x, y) |--> arctan(x^2 + y^2)
- We note that on `W = U\cap V`, the expression of `f` in terms of
+ We note that on `W = U \cap V`, the expression of `f` in terms of
coordinates `(u,v)` can be deduced from that in the coordinates
`(x,y)` thanks to the transition map between the two charts::
@@ -1293,8 +1274,8 @@ class ScalarField(CommutativeAlgebraElement):
f: S^2 --> R
on W: (u, v) |--> arctan(1/(u^2 + v^2))
- We use this fact to extend the definition of `f` to the open subset `V`,
- covered by the chart c_uv::
+ We use this fact to extend the definition of `f` to the open
+ subset `V`, covered by the chart ``c_uv``::
sage: f.add_expr_by_continuation(c_uv, W)
@@ -1325,10 +1306,10 @@ class ScalarField(CommutativeAlgebraElement):
INPUT:
- - ``chart`` -- (default: ``None``) chart with respect to which the
- coordinate expression is to be displayed; if ``None``, the display is
- performed in all the top charts in which the coordinate expression is
- known.
+ - ``chart`` -- (default: ``None``) chart with respect to which
+ the coordinate expression is to be displayed; if ``None``, the
+ display is performed in all the top charts in which the
+ coordinate expression is known
The output is either text-formatted (console mode) or LaTeX-formatted
(notebook mode).
@@ -1429,18 +1410,17 @@ class ScalarField(CommutativeAlgebraElement):
INPUT:
- - ``subdomain`` -- an open subset of the scalar field's domain (must
- be an instance of :class:`~sage.manifolds.manifold.TopologicalManifold`)
+ - ``subdomain`` -- an open subset of the scalar field's domain
OUTPUT:
- instance of :class:`ScalarField` representing the restriction of
- the scalar field to ``subdomain``.
+ the scalar field to ``subdomain``
- EXAMPLE:
+ EXAMPLES:
- Restriction of a scalar field defined on `\RR^2` to the unit open
- disc::
+ Restriction of a scalar field defined on `\RR^2` to the
+ unit open disc::
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart() # Cartesian coordinates
@@ -1508,8 +1488,8 @@ class ScalarField(CommutativeAlgebraElement):
OUPUT:
- - list of common charts; if no common chart is found, None is
- returned (instead of an empty list).
+ - list of common charts; if no common chart is found, ``None`` is
+ returned (instead of an empty list)
EXAMPLES:
@@ -1638,16 +1618,16 @@ class ScalarField(CommutativeAlgebraElement):
INPUT:
- - ``p`` -- point in the scalar field's domain (type:
- :class:`~sage.manifolds.point.TopologicalManifoldPoint`)
- - ``chart`` -- (default: ``None``) chart in which the coordinates of p
- are to be considered; if none is provided, a chart in which both p's
- coordinates and the expression of the scalar field are known is
- searched, starting from the default chart of self._domain
+ - ``p`` -- point in the scalar field's domain
+ - ``chart`` -- (default: ``None``) chart in which the coordinates
+ of ``p`` are to be considered; if ``None``, a chart in which
+ both ``p``'s coordinates and the expression of the scalar field
+ are known is searched, starting from the default chart
+ of ``self._domain``
OUTPUT:
- - value at p
+ - value at ``p``
EXAMPLES::
@@ -1786,7 +1766,7 @@ class ScalarField(CommutativeAlgebraElement):
INPUT:
- - ``other`` -- a scalar field (in the same algebra as self)
+ - ``other`` -- a scalar field (in the same algebra as ``self``)
OUPUT:
@@ -1837,7 +1817,7 @@ class ScalarField(CommutativeAlgebraElement):
INPUT:
- - ``other`` -- a scalar field (in the same algebra as self)
+ - ``other`` -- a scalar field (in the same algebra as ``self``)
OUPUT:
@@ -1889,7 +1869,7 @@ class ScalarField(CommutativeAlgebraElement):
INPUT:
- - ``other`` -- a scalar field (in the same algebra as self)
+ - ``other`` -- a scalar field (in the same algebra as ``self``)
OUPUT:
@@ -1987,7 +1967,7 @@ class ScalarField(CommutativeAlgebraElement):
def _rmul_(self, number):
r"""
- Reflected multiplication operator: performs ``number * self``
+ Reflected multiplication operator: performs ``number * self``.
This implements the multiplication of a scalar field on the left
by a number.
@@ -2077,7 +2057,7 @@ class ScalarField(CommutativeAlgebraElement):
is not assumed to be a scalar field defined on the same domain as
``self``, contrary to ``other`` in ``_mul_(self, other)``. In
practice, ``number`` is a an element of the field on which the
- scalar field algebra is defined
+ scalar field algebra is defined.
INPUT:
@@ -2148,7 +2128,7 @@ class ScalarField(CommutativeAlgebraElement):
OUTPUT:
- - the scalar field `\exp f`, where `f` is the current scalar field.
+ - the scalar field `\exp f`, where `f` is the current scalar field
EXAMPLES::
@@ -2191,7 +2171,7 @@ class ScalarField(CommutativeAlgebraElement):
def log(self):
r"""
- Natural logarithm of the scalar field
+ Natural logarithm of the scalar field.
OUTPUT:
@@ -2287,7 +2267,7 @@ class ScalarField(CommutativeAlgebraElement):
OUTPUT:
- - the scalar field `\sqrt f`, where `f` is the current scalar field.
+ - the scalar field `\sqrt f`, where `f` is the current scalar field
EXAMPLES::
@@ -2324,7 +2304,7 @@ class ScalarField(CommutativeAlgebraElement):
OUTPUT:
- - the scalar field `\cos f`, where `f` is the current scalar field.
+ - the scalar field `\cos f`, where `f` is the current scalar field
EXAMPLES::
@@ -2359,7 +2339,7 @@ class ScalarField(CommutativeAlgebraElement):
OUTPUT:
- - the scalar field `\sin f`, where `f` is the current scalar field.
+ - the scalar field `\sin f`, where `f` is the current scalar field
EXAMPLES::
@@ -2394,7 +2374,7 @@ class ScalarField(CommutativeAlgebraElement):
OUTPUT:
- - the scalar field `\tan f`, where `f` is the current scalar field.
+ - the scalar field `\tan f`, where `f` is the current scalar field
EXAMPLES::
@@ -2431,7 +2411,7 @@ class ScalarField(CommutativeAlgebraElement):
OUTPUT:
- - the scalar field `\arccos f`, where `f` is the current scalar field.
+ - the scalar field `\arccos f`, where `f` is the current scalar field
EXAMPLES::
@@ -2475,7 +2455,7 @@ class ScalarField(CommutativeAlgebraElement):
OUTPUT:
- - the scalar field `\arcsin f`, where `f` is the current scalar field.
+ - the scalar field `\arcsin f`, where `f` is the current scalar field
EXAMPLES::
@@ -2519,7 +2499,7 @@ class ScalarField(CommutativeAlgebraElement):
OUTPUT:
- - the scalar field `\arctan f`, where `f` is the current scalar field.
+ - the scalar field `\arctan f`, where `f` is the current scalar field
EXAMPLES::
@@ -2563,7 +2543,7 @@ class ScalarField(CommutativeAlgebraElement):
OUTPUT:
- - the scalar field `\cosh f`, where `f` is the current scalar field.
+ - the scalar field `\cosh f`, where `f` is the current scalar field
EXAMPLES::
@@ -2596,7 +2576,7 @@ class ScalarField(CommutativeAlgebraElement):
OUTPUT:
- - the scalar field `\sinh f`, where `f` is the current scalar field.
+ - the scalar field `\sinh f`, where `f` is the current scalar field
EXAMPLES::
@@ -2629,7 +2609,7 @@ class ScalarField(CommutativeAlgebraElement):
OUTPUT:
- - the scalar field `\tanh f`, where `f` is the current scalar field.
+ - the scalar field `\tanh f`, where `f` is the current scalar field
EXAMPLES::
@@ -2665,7 +2645,7 @@ class ScalarField(CommutativeAlgebraElement):
OUTPUT:
- the scalar field `\mathrm{arcosh}\, f`, where `f` is the current
- scalar field.
+ scalar field
EXAMPLES::
@@ -2708,7 +2688,7 @@ class ScalarField(CommutativeAlgebraElement):
OUTPUT:
- the scalar field `\mathrm{arsinh}\, f`, where `f` is the current
- scalar field.
+ scalar field
EXAMPLES::
@@ -2751,7 +2731,7 @@ class ScalarField(CommutativeAlgebraElement):
OUTPUT:
- the scalar field `\mathrm{artanh}\, f`, where `f` is the current
- scalar field.
+ scalar field
EXAMPLES::
@@ -2788,3 +2768,4 @@ class ScalarField(CommutativeAlgebraElement):
for chart, func in self._express.iteritems():
resu._express[chart] = func.arctanh()
return resu
+
diff --git a/src/sage/manifolds/scalarfield_algebra.py b/src/sage/manifolds/scalarfield_algebra.py
index 37cbb37..1ecbee6 100644
--- a/src/sage/manifolds/scalarfield_algebra.py
+++ b/src/sage/manifolds/scalarfield_algebra.py
@@ -4,7 +4,7 @@ Algebra of Scalar Fields
The class :class:`ScalarFieldAlgebra` implements the commutative algebra
`C^0(M)` of scalar fields on a topological manifold `M` over a topological
field `K`. By *scalar field*, it
-is meant a continuous function `M\rightarrow K`. The set
+is meant a continuous function `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.
@@ -14,9 +14,9 @@ AUTHORS:
REFERENCES:
-- J.M. Lee : *Introduction to Topological Manifolds*, 2nd ed., Springer (New
+- [Lee11]_ : *Introduction to Topological Manifolds*, 2nd ed., Springer (New
York) (2011)
-- S. Kobayashi & K. Nomizu : *Foundations of Differential Geometry*, vol. 1,
+- [KN63]_ : *Foundations of Differential Geometry*, vol. 1,
Interscience Publishers (New York) (1963)
"""
@@ -33,6 +33,7 @@ REFERENCES:
from sage.structure.parent import Parent
from sage.structure.unique_representation import UniqueRepresentation
+from sage.misc.cachefunc import cached_method
from sage.categories.commutative_algebras import CommutativeAlgebras
from sage.symbolic.ring import SR
from sage.manifolds.scalarfield import ScalarField
@@ -44,49 +45,44 @@ 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`,
- whose ring product is the pointwise multiplication of `K`-valued functions,
- which is clearly commutative.
+ whose ring product is the pointwise multiplication of `K`-valued
+ functions, which is clearly commutative.
If `K = \RR` or `K = \CC`, the field `K` over which the
- algebra `C^0(M)` is constructed is represented by Sage's Symbolic Ring
- ``SR``, since there is no exact representation of `\RR` nor `\CC` in Sage.
-
- The class :class:`ScalarFieldAlgebra` inherits from
- :class:`~sage.structure.parent.Parent`, with the category set to
- :class:`~sage.categories.commutative_algebras.CommutativeAlgebras`.
- The corresponding *element* class is
- :class:`~sage.manifolds.scalarfield.ScalarField`.
+ algebra `C^0(M)` is constructed is represented by the :class:`Symbolic
+ Ring <sage.symbolic.ring.SymbolicRing>` ``SR``, since there is no exact
+ representation of `\RR` nor `\CC`.
INPUT:
- - ``domain`` -- the topological manifold `M` on which the scalar fields are
- defined (must be an instance of class
- :class:`~sage.manifolds.manifold.TopologicalManifold`)
+ - ``domain`` -- the topological manifold `M` on which the scalar fields
+ are defined
EXAMPLES:
- Algebras of scalar fields on the sphere `S^2` and on some open subsets of
- it::
+ Algebras of scalar fields on the sphere `S^2` and on some open
+ subsets of it::
sage: M = Manifold(2, 'M', structure='topological') # the 2-dimensional sphere S^2
- sage: U = M.open_subset('U') # complement of the North pole
- sage: c_xy.<x,y> = U.chart() # stereographic coordinates from the North pole
- sage: V = M.open_subset('V') # complement of the South pole
- sage: c_uv.<u,v> = V.chart() # stereographic coordinates from the South pole
- sage: M.declare_union(U,V) # S^2 is the union of U and V
+ sage: U = M.open_subset('U') # complement of the North pole
+ sage: c_xy.<x,y> = U.chart() # stereographic coordinates from the North pole
+ sage: V = M.open_subset('V') # complement of the South pole
+ sage: c_uv.<u,v> = V.chart() # stereographic coordinates from the South pole
+ sage: M.declare_union(U,V) # S^2 is the union of U and V
sage: xy_to_uv = c_xy.transition_map(c_uv, (x/(x^2+y^2), y/(x^2+y^2)),
- ....: intersection_name='W', restrictions1= x^2+y^2!=0,
- ....: restrictions2= u^2+v^2!=0)
+ ....: intersection_name='W',
+ ....: restrictions1= x^2+y^2!=0,
+ ....: restrictions2= u^2+v^2!=0)
sage: uv_to_xy = xy_to_uv.inverse()
- sage: CM = M.scalar_field_algebra() ; CM
+ sage: CM = M.scalar_field_algebra(); CM
Algebra of scalar fields on the 2-dimensional topological manifold M
sage: W = U.intersection(V) # S^2 minus the two poles
- sage: CW = W.scalar_field_algebra() ; CW
- Algebra of scalar fields on the Open subset W of the 2-dimensional
- topological manifold M
+ sage: CW = W.scalar_field_algebra(); CW
+ Algebra of scalar fields on the Open subset W of the
+ 2-dimensional topological manifold M
`C^0(M)` and `C^0(W)` belong to the category of commutative
- algebras over `\RR` (represented here by Sage's
+ algebras over `\RR` (represented here by
:class:`~sage.symbolic.ring.SymbolicRing`)::
sage: CM.category()
@@ -152,12 +148,11 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
manifold M
sage: CW.one().display()
1: W --> R
- (x, y) |--> 1
- (u, v) |--> 1
+ (x, y) |--> 1
+ (u, v) |--> 1
- A generic element can be constructed as for any parent in Sage, namely
- by means of the ``__call__`` operator on the parent (here with the
- dictionary of the coordinate expressions defining the scalar field)::
+ A generic element can be constructed by using a dictionary of
+ the coordinate expressions defining the scalar field::
sage: f = CM({c_xy: atan(x^2+y^2), c_uv: pi/2 - atan(u^2+v^2)}); f
Scalar field on the 2-dimensional topological manifold M
@@ -181,8 +176,8 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
True
Elements can also be constructed by means of the method
- :meth:`~sage.manifolds.manifold.TopologicalManifold.scalar_field` acting on
- the domain (this allows one to set the name of the scalar field at the
+ :meth:`~sage.manifolds.manifold.TopologicalManifold.scalar_field` acting
+ on the domain (this allows one to set the name of the scalar field at the
construction)::
sage: f1 = M.scalar_field({c_xy: atan(x^2+y^2), c_uv: pi/2 - atan(u^2+v^2)},
@@ -209,12 +204,12 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
on `M`::
sage: fW = CW(f) ; fW
- Scalar field on the Open subset W of the 2-dimensional topological
- manifold M
+ Scalar field on the Open subset W of the
+ 2-dimensional topological manifold M
sage: fW.display()
W --> R
- (x, y) |--> arctan(x^2 + y^2)
- (u, v) |--> 1/2*pi - arctan(u^2 + v^2)
+ (x, y) |--> arctan(x^2 + y^2)
+ (u, v) |--> 1/2*pi - arctan(u^2 + v^2)
::
@@ -227,21 +222,19 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
sage: s = fW + f
sage: s.parent()
- Algebra of scalar fields on the Open subset W of the 2-dimensional
- topological manifold M
+ Algebra of scalar fields on the Open subset W of the
+ 2-dimensional topological manifold M
sage: s.display()
W --> R
- (x, y) |--> 2*arctan(x^2 + y^2)
- (u, v) |--> pi - 2*arctan(u^2 + v^2)
+ (x, y) |--> 2*arctan(x^2 + y^2)
+ (u, v) |--> pi - 2*arctan(u^2 + v^2)
- Another coercion is that from the Symbolic Ring, the parent of all
- symbolic expressions (cf. :class:`~sage.symbolic.ring.SymbolicRing`).
+ Another coercion is that from the Symbolic Ring.
Since the Symbolic Ring is the base ring for the algebra ``CM``, the
coercion of a symbolic expression ``s`` is performed by the operation
- ``s*CM.one()``, which invokes the reflected multiplication operator
- :meth:`sage.manifolds.scalarfield.ScalarField._rmul_`. If the symbolic
- expression does not involve any chart coordinate, the outcome is a
- constant scalar field::
+ ``s*CM.one()``, which invokes the (reflected) multiplication operator.
+ If the symbolic expression does not involve any chart coordinate,
+ the outcome is a constant scalar field::
sage: h = CM(pi*sqrt(2)) ; h
Scalar field on the 2-dimensional topological manifold M
@@ -272,7 +265,7 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
sage: h = CM(x+u); h.display()
M --> R
- .. RUBRIC:: TESTS OF THE ALGEBRA LAWS:
+ TESTS:
Ring laws::
@@ -391,8 +384,6 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
category=CommutativeAlgebras(base_field))
self._domain = domain
self._populate_coercion_lists_()
- self._zero = None # zero element (to be set by method zero())
- self._one = None # unit element (to be set by method one())
#### Methods required for any Parent
def _element_constructor_(self, coord_expression=None, chart=None,
@@ -409,27 +400,30 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
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;
+ 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``
+ 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`
+
TESTS::
sage: M = Manifold(2, 'M', structure='topological')
@@ -448,8 +442,8 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
sage: U = M.open_subset('U', coord_def={X: x>0})
sage: CU = U.scalar_field_algebra()
sage: fU = CU(f); fU
- Scalar field on the Open subset U of the 2-dimensional topological
- manifold M
+ Scalar field on the Open subset U of the
+ 2-dimensional topological manifold M
sage: fU.display()
U --> R
(x, y) |--> y^2 + x
@@ -467,9 +461,9 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
coord_expression=sexpress, name=name,
latex_name=latex_name)
else:
- raise TypeError("cannot convert the " +
+ raise TypeError("cannot convert " +
"{} to a scalar ".format(coord_expression) +
- "field on the {}".format(self._domain))
+ "field on {}".format(self._domain))
else:
# generic constructor:
resu = self.element_class(self,
@@ -498,7 +492,7 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
def _coerce_map_from_(self, other):
r"""
- Determine whether coercion to self exists from other parent
+ Determine whether coercion to ``self`` exists from ``other``.
TESTS::
@@ -529,7 +523,7 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
def _repr_(self):
r"""
- String representation of the object.
+ String representation of ``self``.
TESTS::
@@ -537,8 +531,8 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
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'
+ sage: CM
+ Algebra of scalar fields on the 2-dimensional topological manifold M
"""
return "Algebra of scalar fields on the {}".format(self._domain)
@@ -553,12 +547,13 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
sage: CM = M.scalar_field_algebra()
sage: CM._latex_()
'C^0 \\left(M\\right)'
- sage: latex(CM) # indirect doctest
+ sage: latex(CM)
C^0 \left(M\right)
"""
return r"C^0 \left(" + self._domain._latex_() + r"\right)"
+ @cached_method
def zero(self):
r"""
Return the zero element of the algebra.
@@ -583,15 +578,15 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
True
"""
- if self._zero is None:
- coord_express = dict([(chart, chart.zero_function()) for chart
- in self._domain.atlas()])
- self._zero = self.element_class(self,
- coord_expression=coord_express,
- name='zero', latex_name='0')
- self._zero._is_zero = True
- return self._zero
-
+ coord_express = {chart: chart.zero_function()
+ for chart in self._domain.atlas()}
+ zero = self.element_class(self,
+ coord_expression=coord_express,
+ name='zero', latex_name='0')
+ zero._is_zero = True
+ return zero
+
+ @cached_method
def one(self):
r"""
Return the unit element of the algebra.
@@ -599,7 +594,7 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
This is nothing but the constant scalar field `1` on the manifold,
where `1` is the unit element of the base field.
- EXAMPLE::
+ EXAMPLES::
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
@@ -616,10 +611,9 @@ class ScalarFieldAlgebra(UniqueRepresentation, Parent):
True
"""
- if self._one is None:
- coord_express = dict([(chart, chart.one_function()) for chart
- in self._domain.atlas()])
- self._one = self.element_class(self,
- coord_expression=coord_express,
- name='1', latex_name='1')
- return self._one
+ coord_express = {chart: chart.one_function()
+ for chart in self._domain.atlas()}
+ return self.element_class(self,
+ coord_expression=coord_express,
+ name='1', latex_name='1')
+
diff --git a/src/sage/manifolds/utilities.py b/src/sage/manifolds/utilities.py
index 09f1f46..375c7a8 100644
--- a/src/sage/manifolds/utilities.py
+++ b/src/sage/manifolds/utilities.py
@@ -26,7 +26,7 @@ from sage.symbolic.expression import Expression
def simplify_sqrt_real(expr):
r"""
- Simplify sqrt in symbolic expressions in the real domain.
+ Simplify ``sqrt`` in symbolic expressions in the real domain.
EXAMPLES:
@@ -44,8 +44,8 @@ def simplify_sqrt_real(expr):
-2*x + 1
This improves over Sage's
- :meth:`~sage.symbolic.expression.Expression.canonicalize_radical` which yields
- incorrect results when x<0::
+ :meth:`~sage.symbolic.expression.Expression.canonicalize_radical`,
+ which yields incorrect results when ``x < 0``::
sage: forget() # removes the assumption x<0
sage: sqrt(x^2).canonicalize_radical()
@@ -58,7 +58,7 @@ def simplify_sqrt_real(expr):
sage: ( sqrt(x^2) + sqrt(x^2-2*x+1) ).canonicalize_radical() # wrong output
2*x - 1
- Simplification of nested sqrt's::
+ Simplification of nested ``sqrt``'s::
sage: forget() # removes the assumption x<0
sage: simplify_sqrt_real( sqrt(1 + sqrt(x^2)) )
@@ -148,7 +148,7 @@ def simplify_sqrt_real(expr):
def simplify_abs_trig(expr):
r"""
- Simplify abs(sin(...)) in symbolic expressions.
+ Simplify ``abs(sin(...))`` in symbolic expressions.
EXAMPLES::
@@ -417,7 +417,7 @@ def simplify_chain_generic(expr):
class ExpressionNice(Expression):
r"""
Subclass of :class:`~sage.symbolic.expression.Expression` for a
- ''human-friendly'' display of partial derivatives and the possibility to
+ "human-friendly" display of partial derivatives and the possibility to
shorten the display by skipping the arguments of symbolic functions.
INPUT:
@@ -464,7 +464,10 @@ class ExpressionNice(Expression):
sage: ExpressionNice(fun)
-x^2*d^2(f)/dxdy + (d(f)/dx*d(g)/d(f(x, y)) + d(g)/dx)*x
sage: latex(ExpressionNice(fun))
- -x^{2} \frac{\partial^2\,f}{\partial x\partial y} + {\left(\frac{\partial\,f}{\partial x} \frac{\partial\,g}{\partial \left( f\left(x, y\right) \right)} + \frac{\partial\,g}{\partial x}\right)} x
+ -x^{2} \frac{\partial^2\,f}{\partial x\partial y}
+ + {\left(\frac{\partial\,f}{\partial x}
+ \frac{\partial\,g}{\partial \left( f\left(x, y\right) \right)}
+ + \frac{\partial\,g}{\partial x}\right)} x
Note that ``D[1](g)(x, f(x,y))`` is rendered as ``d(g)/d(f(x, y))``.
@@ -507,10 +510,9 @@ class ExpressionNice(Expression):
f\left(x, y\right) \left(\frac{\partial\,f}{\partial y}\right)^{2}
"""
-
def __init__(self, ex):
r"""
- Construct an instance of ExpressionNice using expression.
+ Initialize ``self``.
TESTS::
@@ -532,7 +534,7 @@ class ExpressionNice(Expression):
r"""
String representation of the object.
- EXAMPLE::
+ EXAMPLES::
sage: var('x y z')
(x, y, z)
@@ -548,13 +550,9 @@ class ExpressionNice(Expression):
y*(z - d(h)/dz)^2 + x*d^2(f)/dxdy
"""
-
d = self._parent._repr_element_(self)
import re
- # Fix for proper coercion of types:
- # http://www.sagemath.org/doc/faq/faq-usage.html#i-have-type-issues-using-scipy-cvxopt-or-numpy-from-sage
- Integer = int
# find all occurences of diff
list_d = []
@@ -562,7 +560,6 @@ class ExpressionNice(Expression):
# process the list
for m in list_d:
-
funcname = m[1]
diffargs = m[3]
numargs = len(diffargs)
@@ -602,7 +599,6 @@ class ExpressionNice(Expression):
from sage.manifolds.coord_func_symb import CoordFunctionSymb
if CoordFunctionSymb._omit_fargs:
-
list_f = []
_list_functions(self, list_f)
@@ -611,7 +607,6 @@ class ExpressionNice(Expression):
return d
-
def _latex_(self):
r"""
LaTeX representation of the object.
@@ -648,21 +643,16 @@ class ExpressionNice(Expression):
\frac{\partial\,{\cal F}}{\partial y}
"""
-
d = self._parent._latex_element_(self)
import re
- # Fix for proper coercion of types:
- # http://www.sagemath.org/doc/faq/faq-usage.html#i-have-type-issues-using-scipy-cvxopt-or-numpy-from-sage
- Integer = int
# find all occurences of diff
list_d = []
_list_derivatives(self, list_d)
for m in list_d:
-
- if str(m[1])==str(m[2]):
+ if str(m[1]) == str(m[2]):
funcname = str(m[1])
else:
funcname = str(m[2])
@@ -678,21 +668,21 @@ class ExpressionNice(Expression):
variables = m[4]
from sage.misc.latex import latex
- strv = list(str(v) for v in variables)
- latv = list(latex(v) for v in variables)
+ strv = [str(v) for v in variables]
+ latv = [latex(v) for v in variables]
# checking if the variable is composite
- for i in range(len(strv)):
- if bool(re.search(r'[+|-|/|*|^|(|)]', strv[i])):
+ for i, val in enumerate(strv):
+ if bool(re.search(r'[+|-|/|*|^|(|)]', val)):
latv[i] = "\left(" + latv[i] + "\\right)"
# dictionary to group multiple occurences of differentiation: d/dxdx -> d/dx^2 etc.
- occ = dict((i, latv[i] + "^" + latex(diffargs.count(i))
- if (diffargs.count(i)>1) else latv[i])
- for i in diffargs)
+ occ = {i: (latv[i] + "^" + latex(diffargs.count(i))
+ if diffargs.count(i) > 1 else latv[i])
+ for i in diffargs}
res = "\\frac{\partial" + numargs + "\," + funcname + \
- "}{\partial " + "\partial ".join([i for i in occ.values()]) + "}"
+ "}{\partial " + "\partial ".join(i for i in occ.values()) + "}"
# representation of the operator
s = self._parent._latex_element_(m[0])
@@ -709,7 +699,6 @@ class ExpressionNice(Expression):
# if omit_function_args(True):
from sage.manifolds.coord_func_symb import CoordFunctionSymb
if CoordFunctionSymb._omit_fargs:
-
list_f = []
_list_functions(self, list_f)
@@ -721,19 +710,20 @@ class ExpressionNice(Expression):
def _list_derivatives(ex, list_d, exponent=0):
r"""
- Function to find the occurrences of FDerivativeOperator in a symbolic
- expression; inspired by http://ask.sagemath.org/question/10256/how-can-extract-different-terms-from-a-symbolic-expression/?answer=26136#post-id-26136
+ Function to find the occurrences of ``FDerivativeOperator`` in a symbolic
+ expression; inspired by
+ http://ask.sagemath.org/question/10256/how-can-extract-different-terms-from-a-symbolic-expression/?answer=26136#post-id-26136
INPUT:
- ``ex`` -- symbolic expression to be analyzed
- - ``exponent`` -- (optional) exponent of FDerivativeOperator, passed to a
- next level in the expression tree
+ - ``exponent`` -- (optional) exponent of ``FDerivativeOperator``,
+ passed to a next level in the expression tree
OUTPUT:
- - ``list_d`` -- tuple containing the details of FDerivativeOperator found,
- in the following order:
+ - ``list_d`` -- tuple containing the details of ``FDerivativeOperator``
+ found, in the following order:
1. operator
2. function name
@@ -751,8 +741,8 @@ def _list_derivatives(ex, list_d, exponent=0):
sage: _list_derivatives(df, list_d)
sage: list_d
[(D[0](f_x)(x), 'f_x', {\cal F}, [0], [x], 2)]
- """
+ """
op = ex.operator()
operands = ex.operands()
@@ -761,13 +751,11 @@ def _list_derivatives(ex, list_d, exponent=0):
from sage.symbolic.operators import FDerivativeOperator
if op:
-
if op is operator.pow:
if isinstance(operands[0].operator(), FDerivativeOperator):
exponent = operands[1]
if isinstance(op, FDerivativeOperator):
-
parameter_set = op.parameter_set()
function = repr(op.function())
latex_function = latex(op.function())
@@ -814,17 +802,18 @@ def _list_functions(ex, list_f):
sage: list_f = []
sage: _list_functions(d, list_f)
sage: list_f
- [(f, 'f', '(x, y)', {\cal F}, \left(x, y\right)), (g_x, 'g_x', '(x, y)', 'g_{x}', \left(x, y\right))]
-
- """
+ [(f, 'f', '(x, y)', {\cal F}, \left(x, y\right)),
+ (g_x, 'g_x', '(x, y)', 'g_{x}', \left(x, y\right))]
+ """
op = ex.operator()
operands = ex.operands()
from sage.misc.latex import latex, latex_variable_name
if op:
-
+ # FIXME: This hack is needed because the NewSymbolicFunction is
+ # a class defined inside of the *function* function_factory().
if str(type(op)) == "<class 'sage.symbolic.function_factory.NewSymbolicFunction'>":
repr_function = repr(op)
latex_function = latex(op)
@@ -835,7 +824,7 @@ def _list_functions(ex, list_f):
repr_args = repr(ex.arguments())
# remove comma in case of singleton
- if len(ex.arguments())==1:
+ if len(ex.arguments()) == 1:
repr_args = repr_args.replace(",","")
latex_args = latex(ex.arguments())
@@ -854,8 +843,8 @@ def nice_derivatives(status):
- ``status`` -- boolean specifying the type of display:
- - ``True``: nice (textbook) display
- - ``False``: standard Pynac notation
+ * ``True`` - nice (textbook) display
+ * ``False`` - standard Pynac notation
EXAMPLES::
@@ -899,8 +888,8 @@ def omit_function_args(status):
- ``status`` -- boolean specifying the type of display:
- - ``True``: arguments are not printed
- - ``False``: standard Pynac notation
+ * ``True`` - arguments are not printed
+ * ``False`` - standard Pynac notation
TESTS::
@@ -924,3 +913,4 @@ def omit_function_args(status):
if not isinstance(status, bool):
raise TypeError("the argument must be a boolean")
CoordFunctionSymb._omit_fargs = status
+