summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTravis Scrimshaw <tscrimsh at umn.edu>2016-05-03 00:12:44 -0500
committerTravis Scrimshaw <tscrimsh at umn.edu>2016-05-03 00:12:44 -0500
commit57b7b7b90110d1e4cc6d7e612f43cab49efc80c8 (patch)
treef91e824a3638946ce7865c409b6a3ac5fb937fbc
parentMarking known bugs in utilities.py. (diff)
Implementing global_options for display formatting.
-rw-r--r--src/sage/manifolds/all.py3
-rw-r--r--src/sage/manifolds/coord_func_symb.py24
-rw-r--r--src/sage/manifolds/manifold.py69
-rw-r--r--src/sage/manifolds/utilities.py93
4 files changed, 82 insertions, 107 deletions
diff --git a/src/sage/manifolds/all.py b/src/sage/manifolds/all.py
index 01834c1..990657e 100644
--- a/src/sage/manifolds/all.py
+++ b/src/sage/manifolds/all.py
@@ -1,4 +1,3 @@
from sage.misc.lazy_import import lazy_import
lazy_import('sage.manifolds.manifold', 'Manifold')
-lazy_import('sage.manifolds.utilities', 'nice_derivatives')
-lazy_import('sage.manifolds.utilities', 'omit_function_args')
+
diff --git a/src/sage/manifolds/coord_func_symb.py b/src/sage/manifolds/coord_func_symb.py
index f8ce7f4..ffc1e75 100644
--- a/src/sage/manifolds/coord_func_symb.py
+++ b/src/sage/manifolds/coord_func_symb.py
@@ -171,7 +171,7 @@ class CoordFunctionSymb(CoordFunction):
sage: f0 + g0
(x, y, z) |--> cos(x)^2 + sin(x)^2
- To get 1, one has to call
+ To get `1`, one has to call
:meth:`~sage.symbolic.expression.Expression.simplify_trig`::
sage: (f0 + g0).simplify_trig()
@@ -216,13 +216,12 @@ class CoordFunctionSymb(CoordFunction):
sage: f.expr()
D[0](g)(x, y) + D[1](g)(x, y)
- One can switch to Pynac notation via the command
- :func:`~sage.manifolds.utilities.nice_derivatives`::
+ One can switch to Pynac notation by changing the global options::
- sage: nice_derivatives(False)
+ sage: Manifold.global_options(textbook_output=False)
sage: latex(f)
D[0]\left(g\right)\left(x, y\right) + D[1]\left(g\right)\left(x, y\right)
- sage: nice_derivatives(True)
+ sage: Manifold.global_options.reset()
sage: latex(f)
\frac{\partial\,g}{\partial x} + \frac{\partial\,g}{\partial y}
@@ -241,7 +240,7 @@ class CoordFunctionSymb(CoordFunction):
`(x,y)`, the explicit mention of the latter can be cumbersome in lengthy
tensor expressions. We can switch it off by::
- sage: omit_function_args(True)
+ sage: Manifold.global_options(omit_function_arguments=True)
sage: f
u*v
@@ -255,18 +254,11 @@ class CoordFunctionSymb(CoordFunction):
We revert to the default behavior by::
- sage: omit_function_args(False)
+ sage: Manifold.global_options.reset()
sage: f
u(x, y)*v(x, y)
"""
-
- _nice_output = True # static flag for textbook-like output instead of the
- # Pynac output for derivatives
-
- _omit_fargs = False # static flag to govern whether or not
- # the arguments of symbolic functions are printed
-
def __init__(self, parent, expression):
r"""
Initialize ``self``.
@@ -325,7 +317,7 @@ class CoordFunctionSymb(CoordFunction):
x*y + 1
"""
- if CoordFunctionSymb._nice_output:
+ if self.parent()._chart.manifold().global_options('textbook_output'):
return str(ExpressionNice(self._express))
else:
return str(self._express)
@@ -346,7 +338,7 @@ class CoordFunctionSymb(CoordFunction):
"""
from sage.misc.latex import latex
- if CoordFunctionSymb._nice_output:
+ if self.parent()._chart.manifold().global_options('textbook_output'):
return latex(ExpressionNice(self._express))
else:
return latex(self._express)
diff --git a/src/sage/manifolds/manifold.py b/src/sage/manifolds/manifold.py
index 8c0bc55..81c4e1b 100644
--- a/src/sage/manifolds/manifold.py
+++ b/src/sage/manifolds/manifold.py
@@ -335,9 +335,70 @@ from sage.rings.real_mpfr import RR, RealField_class
from sage.rings.complex_field import ComplexField_class
from sage.misc.prandom import getrandbits
from sage.rings.integer import Integer
+from sage.structure.global_options import GlobalOptions
from sage.manifolds.subset import ManifoldSubset
-from sage.manifolds.structure import TopologicalStructure, \
- RealTopologicalStructure
+from sage.manifolds.structure import (TopologicalStructure,
+ RealTopologicalStructure)
+
+#############################################################################
+## Global options
+
+ManifoldOptions=GlobalOptions(name='manifolds',
+ doc=r"""
+ Sets and displays the global options for manifolds. If no parameters
+ are set, then the function returns a copy of the options dictionary.
+
+ The ``options`` to manifolds can be accessed as the method
+ :obj:`TopologicalManifolds.global_options`.
+ """,
+ end_doc=r"""
+ EXAMPLES::
+
+ sage: M = Manifold(2, 'M', structure='topological')
+ sage: X.<x,y> = M.chart()
+ sage: g = function('g')(x, y)
+
+ For coordinate functions, the display is more "textbook" like::
+
+ sage: f = X.function(diff(g, x) + diff(g, y))
+ sage: f
+ d(g)/dx + d(g)/dy
+
+ sage: latex(f)
+ \frac{\partial\,g}{\partial x} + \frac{\partial\,g}{\partial y}
+
+ One can switch to Pynac notation by changing ``textbook_output``
+ to ``False``::
+
+ sage: Manifold.global_options(textbook_output=False)
+ sage: f
+ D[0](g)(x, y) + D[1](g)(x, y)
+ sage: latex(f)
+ D[0]\left(g\right)\left(x, y\right) + D[1]\left(g\right)\left(x, y\right)
+ sage: Manifold.global_options.reset()
+
+ If there is a clear understanding that `u` and `v` are functions of
+ `(x,y)`, the explicit mention of the latter can be cumbersome in lengthy
+ tensor expressions::
+
+ sage: f = X.function(function('u')(x, y) * function('v')(x, y))
+ sage: f
+ u(x, y)*v(x, y)
+
+ We can switch it off by::
+
+ sage: M.global_options(omit_function_arguments=True)
+ sage: f
+ u*v
+ sage: M.global_options.reset()
+ """,
+ textbook_output=dict(default=True,
+ description='textbook-like output instead of the Pynac output for derivatives',
+ checker=lambda x: isinstance(x, bool)),
+ omit_function_arguments=dict(default=False,
+ description='Determine if the arguments of symbolic functions are printed',
+ checker=lambda x: isinstance(x, bool)),
+)
#############################################################################
## Class
@@ -1773,6 +1834,8 @@ class TopologicalManifold(ManifoldSubset):
"""
return self._one_scalar_field
+ global_options = ManifoldOptions
+
##############################################################################
## Constructor function
@@ -1942,3 +2005,5 @@ def Manifold(dim, name, latex_name=None, field='real', structure='smooth',
latex_name=latex_name, start_index=start_index,
unique_tag=getrandbits(128)*time())
+Manifold.global_options = ManifoldOptions
+
diff --git a/src/sage/manifolds/utilities.py b/src/sage/manifolds/utilities.py
index a456d66..ed4b99c 100644
--- a/src/sage/manifolds/utilities.py
+++ b/src/sage/manifolds/utilities.py
@@ -498,12 +498,12 @@ class ExpressionNice(Expression):
sage: fun = fun*f
sage: ExpressionNice(fun)
f(x, y)*(d(f)/dy)^2
- sage: omit_function_args(True)
+ sage: Manifold.global_options(omit_function_arguments=True)
sage: ExpressionNice(fun)
f*(d(f)/dy)^2
sage: latex(ExpressionNice(fun))
f \left(\frac{\partial\,f}{\partial y}\right)^{2}
- sage: omit_function_args(False) # revert to standard display
+ sage: Manifold.global_options.reset()
sage: ExpressionNice(fun)
f(x, y)*(d(f)/dy)^2
sage: latex(ExpressionNice(fun))
@@ -597,8 +597,8 @@ class ExpressionNice(Expression):
d = d.replace(o, res)
- from sage.manifolds.coord_func_symb import CoordFunctionSymb
- if CoordFunctionSymb._omit_fargs:
+ from sage.manifolds.manifold import ManifoldOptions
+ if ManifoldOptions('omit_function_arguments'):
list_f = []
_list_functions(self, list_f)
@@ -696,9 +696,8 @@ class ExpressionNice(Expression):
d = d.replace(o, res)
- # if omit_function_args(True):
- from sage.manifolds.coord_func_symb import CoordFunctionSymb
- if CoordFunctionSymb._omit_fargs:
+ from sage.manifolds.manifold import ManifoldOptions
+ if ManifoldOptions('omit_function_arguments'):
list_f = []
_list_functions(self, list_f)
@@ -834,83 +833,3 @@ def _list_functions(ex, list_f):
for operand in operands:
_list_functions(operand, list_f)
-
-def nice_derivatives(status):
- r"""
- Set the display mode of partial derivatives.
-
- INPUT:
-
- - ``status`` -- boolean specifying the type of display:
-
- * ``True`` - nice (textbook) display
- * ``False`` - standard Pynac notation
-
- EXAMPLES::
-
- sage: M = Manifold(2, 'M', structure='topological')
- sage: X.<x,y> = M.chart()
- sage: g = function('g')(x, y)
- sage: f = X.function(diff(g, x) + diff(g, y))
- sage: f
- d(g)/dx + d(g)/dy
- sage: latex(f)
- \frac{\partial\,g}{\partial x} + \frac{\partial\,g}{\partial y}
-
- Standard Pynac display of partial derivatives::
-
- sage: nice_derivatives(False)
- sage: f
- D[0](g)(x, y) + D[1](g)(x, y)
- sage: latex(f)
- D[0]\left(g\right)\left(x, y\right) + D[1]\left(g\right)\left(x, y\right)
-
- Let us revert to nice display::
-
- sage: nice_derivatives(True)
- sage: f
- d(g)/dx + d(g)/dy
- sage: latex(f)
- \frac{\partial\,g}{\partial x} + \frac{\partial\,g}{\partial y}
-
- """
- from sage.manifolds.coord_func_symb import CoordFunctionSymb
- if not isinstance(status, bool):
- raise TypeError("the argument must be a boolean")
- CoordFunctionSymb._nice_output = status
-
-
-def omit_function_args(status):
- r"""
- Set the display mode of expression to omit arguments of symbolic functions.
-
- INPUT:
-
- - ``status`` -- boolean specifying the type of display:
-
- * ``True`` - arguments are not printed
- * ``False`` - standard Pynac notation
-
- TESTS::
-
- sage: from sage.manifolds.utilities import ExpressionNice
- sage: f = function('f_x')(x)
- sage: f = f*(1 + f^2)
- sage: ExpressionNice(f)
- (f_x(x)^2 + 1)*f_x(x)
- sage: omit_function_args(True)
- sage: ExpressionNice(f)
- (f_x^2 + 1)*f_x
- sage: omit_function_args(False)
- sage: latex(ExpressionNice(f))
- {\left(f_{x}\left(x\right)^{2} + 1\right)} f_{x}\left(x\right)
- sage: omit_function_args(True)
- sage: latex(ExpressionNice(f))
- {\left(f_{x}^{2} + 1\right)} f_{x}
-
- """
- from sage.manifolds.coord_func_symb import CoordFunctionSymb
- if not isinstance(status, bool):
- raise TypeError("the argument must be a boolean")
- CoordFunctionSymb._omit_fargs = status
-