passagemath-symbolics 10.6.37__cp314-cp314t-macosx_13_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- passagemath_symbolics/.dylibs/libgmp.10.dylib +0 -0
- passagemath_symbolics/__init__.py +3 -0
- passagemath_symbolics-10.6.37.dist-info/METADATA +187 -0
- passagemath_symbolics-10.6.37.dist-info/RECORD +172 -0
- passagemath_symbolics-10.6.37.dist-info/WHEEL +6 -0
- passagemath_symbolics-10.6.37.dist-info/top_level.txt +3 -0
- sage/all__sagemath_symbolics.py +17 -0
- sage/calculus/all.py +14 -0
- sage/calculus/calculus.py +2826 -0
- sage/calculus/desolvers.py +1866 -0
- sage/calculus/predefined.py +51 -0
- sage/calculus/tests.py +225 -0
- sage/calculus/var.cpython-314t-darwin.so +0 -0
- sage/calculus/var.pyx +401 -0
- sage/dynamics/all__sagemath_symbolics.py +6 -0
- sage/dynamics/complex_dynamics/all.py +5 -0
- sage/dynamics/complex_dynamics/mandel_julia.py +765 -0
- sage/dynamics/complex_dynamics/mandel_julia_helper.cpython-314t-darwin.so +0 -0
- sage/dynamics/complex_dynamics/mandel_julia_helper.pyx +1035 -0
- sage/ext/all__sagemath_symbolics.py +1 -0
- sage/ext_data/kenzo/CP2.txt +45 -0
- sage/ext_data/kenzo/CP3.txt +349 -0
- sage/ext_data/kenzo/CP4.txt +4774 -0
- sage/ext_data/kenzo/README.txt +49 -0
- sage/ext_data/kenzo/S4.txt +20 -0
- sage/ext_data/magma/latex/latex.m +1021 -0
- sage/ext_data/magma/latex/latex.spec +1 -0
- sage/ext_data/magma/sage/basic.m +356 -0
- sage/ext_data/magma/sage/sage.spec +1 -0
- sage/ext_data/magma/spec +9 -0
- sage/geometry/all__sagemath_symbolics.py +8 -0
- sage/geometry/hyperbolic_space/all.py +5 -0
- sage/geometry/hyperbolic_space/hyperbolic_coercion.py +743 -0
- sage/geometry/hyperbolic_space/hyperbolic_constants.py +5 -0
- sage/geometry/hyperbolic_space/hyperbolic_geodesic.py +2409 -0
- sage/geometry/hyperbolic_space/hyperbolic_interface.py +206 -0
- sage/geometry/hyperbolic_space/hyperbolic_isometry.py +1082 -0
- sage/geometry/hyperbolic_space/hyperbolic_model.py +1502 -0
- sage/geometry/hyperbolic_space/hyperbolic_point.py +621 -0
- sage/geometry/riemannian_manifolds/all.py +7 -0
- sage/geometry/riemannian_manifolds/parametrized_surface3d.py +1632 -0
- sage/geometry/riemannian_manifolds/surface3d_generators.py +461 -0
- sage/interfaces/all__sagemath_symbolics.py +1 -0
- sage/interfaces/magma.py +3017 -0
- sage/interfaces/magma_free.py +92 -0
- sage/interfaces/maple.py +1397 -0
- sage/interfaces/mathematica.py +1345 -0
- sage/interfaces/mathics.py +1312 -0
- sage/interfaces/sympy.py +1398 -0
- sage/interfaces/sympy_wrapper.py +197 -0
- sage/interfaces/tides.py +938 -0
- sage/libs/all__sagemath_symbolics.py +6 -0
- sage/manifolds/all.py +7 -0
- sage/manifolds/calculus_method.py +555 -0
- sage/manifolds/catalog.py +437 -0
- sage/manifolds/chart.py +4019 -0
- sage/manifolds/chart_func.py +3419 -0
- sage/manifolds/continuous_map.py +2183 -0
- sage/manifolds/continuous_map_image.py +155 -0
- sage/manifolds/differentiable/affine_connection.py +2475 -0
- sage/manifolds/differentiable/all.py +1 -0
- sage/manifolds/differentiable/automorphismfield.py +1383 -0
- sage/manifolds/differentiable/automorphismfield_group.py +604 -0
- sage/manifolds/differentiable/bundle_connection.py +1445 -0
- sage/manifolds/differentiable/characteristic_cohomology_class.py +1840 -0
- sage/manifolds/differentiable/chart.py +1241 -0
- sage/manifolds/differentiable/curve.py +1028 -0
- sage/manifolds/differentiable/de_rham_cohomology.py +541 -0
- sage/manifolds/differentiable/degenerate.py +559 -0
- sage/manifolds/differentiable/degenerate_submanifold.py +1671 -0
- sage/manifolds/differentiable/diff_form.py +1658 -0
- sage/manifolds/differentiable/diff_form_module.py +1062 -0
- sage/manifolds/differentiable/diff_map.py +1315 -0
- sage/manifolds/differentiable/differentiable_submanifold.py +291 -0
- sage/manifolds/differentiable/examples/all.py +1 -0
- sage/manifolds/differentiable/examples/euclidean.py +2517 -0
- sage/manifolds/differentiable/examples/real_line.py +897 -0
- sage/manifolds/differentiable/examples/sphere.py +1186 -0
- sage/manifolds/differentiable/examples/symplectic_space.py +187 -0
- sage/manifolds/differentiable/examples/symplectic_space_test.py +40 -0
- sage/manifolds/differentiable/integrated_curve.py +4035 -0
- sage/manifolds/differentiable/levi_civita_connection.py +841 -0
- sage/manifolds/differentiable/manifold.py +4254 -0
- sage/manifolds/differentiable/manifold_homset.py +1826 -0
- sage/manifolds/differentiable/metric.py +3032 -0
- sage/manifolds/differentiable/mixed_form.py +1507 -0
- sage/manifolds/differentiable/mixed_form_algebra.py +559 -0
- sage/manifolds/differentiable/multivector_module.py +800 -0
- sage/manifolds/differentiable/multivectorfield.py +1520 -0
- sage/manifolds/differentiable/poisson_tensor.py +268 -0
- sage/manifolds/differentiable/pseudo_riemannian.py +755 -0
- sage/manifolds/differentiable/pseudo_riemannian_submanifold.py +1839 -0
- sage/manifolds/differentiable/scalarfield.py +1343 -0
- sage/manifolds/differentiable/scalarfield_algebra.py +472 -0
- sage/manifolds/differentiable/symplectic_form.py +910 -0
- sage/manifolds/differentiable/symplectic_form_test.py +220 -0
- sage/manifolds/differentiable/tangent_space.py +412 -0
- sage/manifolds/differentiable/tangent_vector.py +616 -0
- sage/manifolds/differentiable/tensorfield.py +4665 -0
- sage/manifolds/differentiable/tensorfield_module.py +963 -0
- sage/manifolds/differentiable/tensorfield_paral.py +2450 -0
- sage/manifolds/differentiable/tensorfield_paral_test.py +16 -0
- sage/manifolds/differentiable/vector_bundle.py +1728 -0
- sage/manifolds/differentiable/vectorfield.py +1717 -0
- sage/manifolds/differentiable/vectorfield_module.py +2445 -0
- sage/manifolds/differentiable/vectorframe.py +1832 -0
- sage/manifolds/family.py +270 -0
- sage/manifolds/local_frame.py +1490 -0
- sage/manifolds/manifold.py +3090 -0
- sage/manifolds/manifold_homset.py +452 -0
- sage/manifolds/operators.py +359 -0
- sage/manifolds/point.py +994 -0
- sage/manifolds/scalarfield.py +3718 -0
- sage/manifolds/scalarfield_algebra.py +629 -0
- sage/manifolds/section.py +3111 -0
- sage/manifolds/section_module.py +831 -0
- sage/manifolds/structure.py +229 -0
- sage/manifolds/subset.py +2764 -0
- sage/manifolds/subsets/all.py +1 -0
- sage/manifolds/subsets/closure.py +131 -0
- sage/manifolds/subsets/pullback.py +885 -0
- sage/manifolds/topological_submanifold.py +891 -0
- sage/manifolds/trivialization.py +733 -0
- sage/manifolds/utilities.py +1348 -0
- sage/manifolds/vector_bundle.py +1342 -0
- sage/manifolds/vector_bundle_fiber.py +332 -0
- sage/manifolds/vector_bundle_fiber_element.py +111 -0
- sage/matrix/all__sagemath_symbolics.py +1 -0
- sage/matrix/matrix_symbolic_dense.cpython-314t-darwin.so +0 -0
- sage/matrix/matrix_symbolic_dense.pxd +6 -0
- sage/matrix/matrix_symbolic_dense.pyx +1022 -0
- sage/matrix/matrix_symbolic_sparse.cpython-314t-darwin.so +0 -0
- sage/matrix/matrix_symbolic_sparse.pxd +6 -0
- sage/matrix/matrix_symbolic_sparse.pyx +1029 -0
- sage/modules/all__sagemath_symbolics.py +1 -0
- sage/modules/vector_callable_symbolic_dense.py +105 -0
- sage/modules/vector_symbolic_dense.py +116 -0
- sage/modules/vector_symbolic_sparse.py +118 -0
- sage/rings/all__sagemath_symbolics.py +4 -0
- sage/rings/asymptotic/all.py +6 -0
- sage/rings/asymptotic/asymptotic_expansion_generators.py +1485 -0
- sage/rings/asymptotic/asymptotic_ring.py +4858 -0
- sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py +4153 -0
- sage/rings/asymptotic/growth_group.py +5373 -0
- sage/rings/asymptotic/growth_group_cartesian.py +1400 -0
- sage/rings/asymptotic/term_monoid.py +5237 -0
- sage/rings/function_field/all__sagemath_symbolics.py +2 -0
- sage/rings/polynomial/all__sagemath_symbolics.py +1 -0
- sage/symbolic/all.py +15 -0
- sage/symbolic/assumptions.py +985 -0
- sage/symbolic/benchmark.py +93 -0
- sage/symbolic/callable.py +459 -0
- sage/symbolic/complexity_measures.py +35 -0
- sage/symbolic/constants.py +1287 -0
- sage/symbolic/expression_conversion_algebraic.py +310 -0
- sage/symbolic/expression_conversion_sympy.py +317 -0
- sage/symbolic/expression_conversions.py +1713 -0
- sage/symbolic/function_factory.py +355 -0
- sage/symbolic/integration/all.py +1 -0
- sage/symbolic/integration/external.py +270 -0
- sage/symbolic/integration/integral.py +1115 -0
- sage/symbolic/maxima_wrapper.py +162 -0
- sage/symbolic/operators.py +267 -0
- sage/symbolic/random_tests.py +462 -0
- sage/symbolic/relation.py +1907 -0
- sage/symbolic/ring.cpython-314t-darwin.so +0 -0
- sage/symbolic/ring.pxd +5 -0
- sage/symbolic/ring.pyx +1396 -0
- sage/symbolic/subring.py +1025 -0
- sage/symbolic/symengine.py +19 -0
- sage/symbolic/tests.py +40 -0
- sage/symbolic/units.py +1470 -0
sage/manifolds/all.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-symbolics
|
|
2
|
+
from sage.misc.lazy_import import lazy_import
|
|
3
|
+
|
|
4
|
+
lazy_import('sage.manifolds.manifold', 'Manifold')
|
|
5
|
+
lazy_import('sage.manifolds.differentiable.examples.euclidean', 'EuclideanSpace')
|
|
6
|
+
lazy_import('sage.manifolds', 'catalog', 'manifolds')
|
|
7
|
+
del lazy_import
|
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-symbolics
|
|
2
|
+
r"""
|
|
3
|
+
Coordinate calculus methods
|
|
4
|
+
|
|
5
|
+
The class :class:`CalculusMethod` governs the calculus methods (symbolic and
|
|
6
|
+
numerical) used for coordinate computations on manifolds.
|
|
7
|
+
|
|
8
|
+
AUTHORS:
|
|
9
|
+
|
|
10
|
+
- Marco Mancini (2017): initial version
|
|
11
|
+
- Eric Gourgoulhon (2019): add :meth:`~CalculusMethod.set_simplify_function`
|
|
12
|
+
and various accessors
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
# *****************************************************************************
|
|
16
|
+
# Copyright (C) 2015 Marco Mancini <marco.mancini@obspm.fr>
|
|
17
|
+
#
|
|
18
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
19
|
+
# as published by the Free Software Foundation; either version 2 of
|
|
20
|
+
# the License, or (at your option) any later version.
|
|
21
|
+
# https://www.gnu.org/licenses/
|
|
22
|
+
# *****************************************************************************
|
|
23
|
+
from sage.manifolds.utilities import (
|
|
24
|
+
simplify_chain_generic,
|
|
25
|
+
simplify_chain_generic_sympy,
|
|
26
|
+
simplify_chain_real,
|
|
27
|
+
simplify_chain_real_sympy,
|
|
28
|
+
)
|
|
29
|
+
from sage.misc.latex import latex
|
|
30
|
+
from sage.structure.sage_object import SageObject
|
|
31
|
+
from sage.symbolic.ring import SR
|
|
32
|
+
|
|
33
|
+
try:
|
|
34
|
+
import sympy
|
|
35
|
+
from sympy import latex as sympy_latex
|
|
36
|
+
except ImportError:
|
|
37
|
+
sympy_latex = None
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# Conversion functions
|
|
41
|
+
def _SR_to_Sympy(expression):
|
|
42
|
+
r"""
|
|
43
|
+
Convert an expression from ``SR`` to ``sympy``.
|
|
44
|
+
|
|
45
|
+
In the case where the expression is already ``sympy``, it is simply
|
|
46
|
+
returned.
|
|
47
|
+
|
|
48
|
+
INPUT:
|
|
49
|
+
|
|
50
|
+
- ``expression`` -- ``SR`` or ``sympy`` symbolic expression
|
|
51
|
+
|
|
52
|
+
OUTPUT: ``expression`` -- ``sympy`` symbolic expression
|
|
53
|
+
|
|
54
|
+
EXAMPLES::
|
|
55
|
+
|
|
56
|
+
sage: from sage.manifolds.calculus_method import _SR_to_Sympy
|
|
57
|
+
sage: a = x^2 + sin(x)^2; a
|
|
58
|
+
x^2 + sin(x)^2
|
|
59
|
+
sage: type(a)
|
|
60
|
+
<class 'sage.symbolic.expression.Expression'>
|
|
61
|
+
sage: b = _SR_to_Sympy(a); b
|
|
62
|
+
x**2 + sin(x)**2
|
|
63
|
+
sage: type(b)
|
|
64
|
+
<class 'sympy.core.add.Add'>
|
|
65
|
+
|
|
66
|
+
An already ``sympy`` expression is unchanged::
|
|
67
|
+
|
|
68
|
+
sage: _SR_to_Sympy(b) is b
|
|
69
|
+
True
|
|
70
|
+
"""
|
|
71
|
+
# Nothing to do if expression is already a SymPy object:
|
|
72
|
+
if isinstance(expression, sympy.Basic):
|
|
73
|
+
return expression
|
|
74
|
+
return SR(expression)._sympy_()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _Sympy_to_SR(expression):
|
|
78
|
+
r"""
|
|
79
|
+
Convert an expression from ``sympy`` to ``SR``.
|
|
80
|
+
|
|
81
|
+
In the case where the expression is already ``SR``, it is simply returned.
|
|
82
|
+
|
|
83
|
+
INPUT:
|
|
84
|
+
|
|
85
|
+
- ``expression`` -- ``sympy`` symbolic expression
|
|
86
|
+
|
|
87
|
+
OUTPUT: ``expression`` -- ``SR`` or ``sympy`` symbolic expression
|
|
88
|
+
|
|
89
|
+
EXAMPLES::
|
|
90
|
+
|
|
91
|
+
sage: from sage.manifolds.calculus_method import _Sympy_to_SR, _SR_to_Sympy
|
|
92
|
+
sage: a = x^2 + sin(x)^2
|
|
93
|
+
sage: type(a)
|
|
94
|
+
<class 'sage.symbolic.expression.Expression'>
|
|
95
|
+
sage: b = _SR_to_Sympy(a); b
|
|
96
|
+
x**2 + sin(x)**2
|
|
97
|
+
sage: type(b)
|
|
98
|
+
<class 'sympy.core.add.Add'>
|
|
99
|
+
sage: _Sympy_to_SR(b) == a
|
|
100
|
+
x^2 + sin(x)^2 == x^2 + sin(x)^2
|
|
101
|
+
sage: bool(_)
|
|
102
|
+
True
|
|
103
|
+
"""
|
|
104
|
+
try:
|
|
105
|
+
return SR(expression)
|
|
106
|
+
except Exception:
|
|
107
|
+
# If SR cannot transform a sympy expression this is because it is a
|
|
108
|
+
# sympy abstract function
|
|
109
|
+
a = expression._sage_()
|
|
110
|
+
# As all sage objects have a ._sage_ operator, they have to be
|
|
111
|
+
# caught
|
|
112
|
+
if type(a) is type(expression):
|
|
113
|
+
raise TypeError
|
|
114
|
+
return a
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class CalculusMethod(SageObject):
|
|
118
|
+
r"""
|
|
119
|
+
Control of calculus backends used on coordinate charts of manifolds.
|
|
120
|
+
|
|
121
|
+
This class stores the possible calculus methods and permits to switch
|
|
122
|
+
between them, as well as to change the simplifying functions associated
|
|
123
|
+
with them.
|
|
124
|
+
For the moment, only two calculus backends are implemented:
|
|
125
|
+
|
|
126
|
+
- Sage's symbolic engine (Pynac + Maxima), implemented via the
|
|
127
|
+
Symbolic Ring ``SR``
|
|
128
|
+
- SymPy engine, denoted ``sympy`` hereafter
|
|
129
|
+
|
|
130
|
+
INPUT:
|
|
131
|
+
|
|
132
|
+
- ``current`` -- (default: ``None``) string defining the calculus method
|
|
133
|
+
that will be considered as the active one, until it is changed by
|
|
134
|
+
:meth:`set`; must be one of
|
|
135
|
+
|
|
136
|
+
- ``'SR'``: Sage's default symbolic engine (Symbolic Ring)
|
|
137
|
+
- ``'sympy'``: SymPy
|
|
138
|
+
- ``None``: the default calculus method (``'SR'``)
|
|
139
|
+
|
|
140
|
+
- ``base_field_type`` -- (default: ``'real'``) base field type of the
|
|
141
|
+
manifold (cf.
|
|
142
|
+
:meth:`~sage.manifolds.manifold.TopologicalManifold.base_field_type`)
|
|
143
|
+
|
|
144
|
+
EXAMPLES::
|
|
145
|
+
|
|
146
|
+
sage: from sage.manifolds.calculus_method import CalculusMethod
|
|
147
|
+
sage: cm = CalculusMethod()
|
|
148
|
+
|
|
149
|
+
In the display, the currently active method is pointed out with a star::
|
|
150
|
+
|
|
151
|
+
sage: cm
|
|
152
|
+
Available calculus methods (* = current):
|
|
153
|
+
- SR (default) (*)
|
|
154
|
+
- sympy
|
|
155
|
+
|
|
156
|
+
It can be changed with :meth:`set`::
|
|
157
|
+
|
|
158
|
+
sage: cm.set('sympy')
|
|
159
|
+
sage: cm
|
|
160
|
+
Available calculus methods (* = current):
|
|
161
|
+
- SR (default)
|
|
162
|
+
- sympy (*)
|
|
163
|
+
|
|
164
|
+
while :meth:`reset` brings back to the default::
|
|
165
|
+
|
|
166
|
+
sage: cm.reset()
|
|
167
|
+
sage: cm
|
|
168
|
+
Available calculus methods (* = current):
|
|
169
|
+
- SR (default) (*)
|
|
170
|
+
- sympy
|
|
171
|
+
|
|
172
|
+
See :meth:`simplify_function` for the default simplification algorithms
|
|
173
|
+
associated with each calculus method and :meth:`set_simplify_function` for
|
|
174
|
+
introducing a new simplification algorithm.
|
|
175
|
+
"""
|
|
176
|
+
|
|
177
|
+
_default = 'SR' # default calculus method
|
|
178
|
+
_methods = ('SR', 'sympy') # implemented methods
|
|
179
|
+
_tranf = {'SR': _Sympy_to_SR, 'sympy': _SR_to_Sympy} # translators
|
|
180
|
+
|
|
181
|
+
def __init__(self, current=None, base_field_type='real'):
|
|
182
|
+
r"""
|
|
183
|
+
Initialize ``self``.
|
|
184
|
+
|
|
185
|
+
TESTS::
|
|
186
|
+
|
|
187
|
+
sage: from sage.manifolds.calculus_method import CalculusMethod
|
|
188
|
+
sage: cm = CalculusMethod(base_field_type='complex')
|
|
189
|
+
sage: cm
|
|
190
|
+
Available calculus methods (* = current):
|
|
191
|
+
- SR (default) (*)
|
|
192
|
+
- sympy
|
|
193
|
+
"""
|
|
194
|
+
self._current = self._default if current is None else current
|
|
195
|
+
# Initialization of the dictionary of simplifying functions:
|
|
196
|
+
self._simplify_dict = {}
|
|
197
|
+
if base_field_type == 'real':
|
|
198
|
+
self._simplify_dict['sympy'] = simplify_chain_real_sympy
|
|
199
|
+
self._simplify_dict['SR'] = simplify_chain_real
|
|
200
|
+
else:
|
|
201
|
+
self._simplify_dict['sympy'] = simplify_chain_generic_sympy
|
|
202
|
+
self._simplify_dict['SR'] = simplify_chain_generic
|
|
203
|
+
# The default simplifying functions are saved:
|
|
204
|
+
self._simplify_dict_default = self._simplify_dict.copy()
|
|
205
|
+
self._latex_dict = {'sympy': sympy_latex, 'SR': latex}
|
|
206
|
+
|
|
207
|
+
def simplify(self, expression, method=None):
|
|
208
|
+
r"""
|
|
209
|
+
Apply the simplifying function associated with a given calculus method
|
|
210
|
+
to a symbolic expression.
|
|
211
|
+
|
|
212
|
+
INPUT:
|
|
213
|
+
|
|
214
|
+
- ``expression`` -- symbolic expression to simplify
|
|
215
|
+
|
|
216
|
+
- ``method`` -- (default: ``None``) string defining the calculus method
|
|
217
|
+
to use; must be one of
|
|
218
|
+
|
|
219
|
+
- ``'SR'``: Sage's default symbolic engine (Symbolic Ring)
|
|
220
|
+
- ``'sympy'``: SymPy
|
|
221
|
+
- ``None``: the current calculus method of ``self`` is used
|
|
222
|
+
|
|
223
|
+
OUTPUT: the simplified version of ``expression``
|
|
224
|
+
|
|
225
|
+
EXAMPLES::
|
|
226
|
+
|
|
227
|
+
sage: M = Manifold(2, 'M', structure='topological')
|
|
228
|
+
sage: X.<x, y> = M.chart()
|
|
229
|
+
sage: f = x^2 + sin(x)^2 + cos(x)^2
|
|
230
|
+
sage: from sage.manifolds.calculus_method import CalculusMethod
|
|
231
|
+
sage: cm = CalculusMethod(base_field_type='real')
|
|
232
|
+
sage: cm.simplify(f)
|
|
233
|
+
x^2 + 1
|
|
234
|
+
|
|
235
|
+
Using a weaker simplifying function, like
|
|
236
|
+
:func:`~sage.calculus.functional.simplify`, does not succeed in this
|
|
237
|
+
case::
|
|
238
|
+
|
|
239
|
+
sage: cm.set_simplify_function(simplify)
|
|
240
|
+
sage: cm.simplify(f)
|
|
241
|
+
x^2 + cos(x)^2 + sin(x)^2
|
|
242
|
+
|
|
243
|
+
Back to the default simplifying function
|
|
244
|
+
(:func:`~sage.manifolds.utilities.simplify_chain_real` in the present
|
|
245
|
+
case)::
|
|
246
|
+
|
|
247
|
+
sage: cm.set_simplify_function('default')
|
|
248
|
+
sage: cm.simplify(f)
|
|
249
|
+
x^2 + 1
|
|
250
|
+
|
|
251
|
+
A ``SR`` expression, such as ``f``, cannot be simplified when the
|
|
252
|
+
current calculus method is ``sympy``::
|
|
253
|
+
|
|
254
|
+
sage: cm.set('sympy')
|
|
255
|
+
sage: cm.simplify(f)
|
|
256
|
+
Traceback (most recent call last):
|
|
257
|
+
...
|
|
258
|
+
AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'combsimp'...
|
|
259
|
+
|
|
260
|
+
In the present case, one should either transform ``f`` to a SymPy
|
|
261
|
+
object::
|
|
262
|
+
|
|
263
|
+
sage: cm.simplify(f._sympy_())
|
|
264
|
+
x**2 + 1
|
|
265
|
+
|
|
266
|
+
or force the calculus method to be ``'SR'``::
|
|
267
|
+
|
|
268
|
+
sage: cm.simplify(f, method='SR')
|
|
269
|
+
x^2 + 1
|
|
270
|
+
"""
|
|
271
|
+
if method is None:
|
|
272
|
+
method = self._current
|
|
273
|
+
return self._simplify_dict[method](expression)
|
|
274
|
+
|
|
275
|
+
def is_trivial_zero(self, expression, method=None):
|
|
276
|
+
r"""
|
|
277
|
+
Check if an expression is trivially equal to zero without any
|
|
278
|
+
simplification.
|
|
279
|
+
|
|
280
|
+
INPUT:
|
|
281
|
+
|
|
282
|
+
- ``expression`` -- expression
|
|
283
|
+
|
|
284
|
+
- ``method`` -- (default: ``None``) string defining the calculus method
|
|
285
|
+
to use; if ``None`` the current calculus method of ``self`` is used
|
|
286
|
+
|
|
287
|
+
OUTPUT: ``True`` is expression is trivially zero, ``False`` elsewhere
|
|
288
|
+
|
|
289
|
+
EXAMPLES::
|
|
290
|
+
|
|
291
|
+
sage: from sage.manifolds.calculus_method import CalculusMethod
|
|
292
|
+
sage: cm = CalculusMethod(base_field_type='real')
|
|
293
|
+
sage: f = sin(x) - sin(x)
|
|
294
|
+
sage: cm.is_trivial_zero(f)
|
|
295
|
+
True
|
|
296
|
+
sage: cm.is_trivial_zero(f._sympy_(), method='sympy')
|
|
297
|
+
True
|
|
298
|
+
|
|
299
|
+
::
|
|
300
|
+
|
|
301
|
+
sage: f = sin(x)^2 + cos(x)^2 - 1
|
|
302
|
+
sage: cm.is_trivial_zero(f)
|
|
303
|
+
False
|
|
304
|
+
sage: cm.is_trivial_zero(f._sympy_(), method='sympy')
|
|
305
|
+
False
|
|
306
|
+
"""
|
|
307
|
+
if method is None:
|
|
308
|
+
method = self._current
|
|
309
|
+
if method == 'SR':
|
|
310
|
+
return expression.is_trivial_zero()
|
|
311
|
+
elif method == 'sympy':
|
|
312
|
+
# we have to test SymPy's is_zero because it could be 'NoneType'
|
|
313
|
+
if expression.is_zero:
|
|
314
|
+
return True
|
|
315
|
+
return False
|
|
316
|
+
|
|
317
|
+
def set(self, method):
|
|
318
|
+
r"""
|
|
319
|
+
Set the currently active calculus method.
|
|
320
|
+
|
|
321
|
+
- ``method`` -- string defining the calculus method
|
|
322
|
+
|
|
323
|
+
EXAMPLES::
|
|
324
|
+
|
|
325
|
+
sage: from sage.manifolds.calculus_method import CalculusMethod
|
|
326
|
+
sage: cm = CalculusMethod(base_field_type='complex')
|
|
327
|
+
sage: cm
|
|
328
|
+
Available calculus methods (* = current):
|
|
329
|
+
- SR (default) (*)
|
|
330
|
+
- sympy
|
|
331
|
+
sage: cm.set('sympy')
|
|
332
|
+
sage: cm
|
|
333
|
+
Available calculus methods (* = current):
|
|
334
|
+
- SR (default)
|
|
335
|
+
- sympy (*)
|
|
336
|
+
sage: cm.set('lala')
|
|
337
|
+
Traceback (most recent call last):
|
|
338
|
+
...
|
|
339
|
+
NotImplementedError: method lala not implemented
|
|
340
|
+
"""
|
|
341
|
+
if method not in self._methods:
|
|
342
|
+
raise NotImplementedError("method {} not ".format(method) + "implemented")
|
|
343
|
+
self._current = method
|
|
344
|
+
|
|
345
|
+
def current(self):
|
|
346
|
+
r"""
|
|
347
|
+
Return the active calculus method as a string.
|
|
348
|
+
|
|
349
|
+
OUTPUT:
|
|
350
|
+
|
|
351
|
+
String defining the calculus method; one of
|
|
352
|
+
|
|
353
|
+
- ``'SR'`` -- Sage's default symbolic engine (Symbolic Ring)
|
|
354
|
+
- ``'sympy'`` -- SymPy
|
|
355
|
+
|
|
356
|
+
EXAMPLES::
|
|
357
|
+
|
|
358
|
+
sage: from sage.manifolds.calculus_method import CalculusMethod
|
|
359
|
+
sage: cm = CalculusMethod(); cm
|
|
360
|
+
Available calculus methods (* = current):
|
|
361
|
+
- SR (default) (*)
|
|
362
|
+
- sympy
|
|
363
|
+
sage: cm.current()
|
|
364
|
+
'SR'
|
|
365
|
+
sage: cm.set('sympy')
|
|
366
|
+
sage: cm.current()
|
|
367
|
+
'sympy'
|
|
368
|
+
"""
|
|
369
|
+
return self._current
|
|
370
|
+
|
|
371
|
+
def set_simplify_function(self, simplifying_func, method=None):
|
|
372
|
+
r"""
|
|
373
|
+
Set the simplifying function associated to a given calculus method.
|
|
374
|
+
|
|
375
|
+
INPUT:
|
|
376
|
+
|
|
377
|
+
- ``simplifying_func`` -- either the string ``'default'`` for restoring
|
|
378
|
+
the default simplifying function or a function ``f`` of a single
|
|
379
|
+
argument ``expr`` such that ``f(expr)`` returns an object of the same
|
|
380
|
+
type as ``expr`` (hopefully the simplified version of ``expr``), this
|
|
381
|
+
type being
|
|
382
|
+
|
|
383
|
+
- :class:`~sage.symbolic.expression.Expression` if ``method`` = ``'SR'``
|
|
384
|
+
- a SymPy type if ``method`` = ``'sympy'``
|
|
385
|
+
|
|
386
|
+
- ``method`` -- (default: ``None``) string defining the calculus method
|
|
387
|
+
for which ``simplifying_func`` is provided; must be one of
|
|
388
|
+
|
|
389
|
+
- ``'SR'``: Sage's default symbolic engine (Symbolic Ring)
|
|
390
|
+
- ``'sympy'``: SymPy
|
|
391
|
+
- ``None``: the currently active calculus method of ``self`` is
|
|
392
|
+
assumed
|
|
393
|
+
|
|
394
|
+
EXAMPLES:
|
|
395
|
+
|
|
396
|
+
On a real manifold, the default simplifying function is
|
|
397
|
+
:func:`~sage.manifolds.utilities.simplify_chain_real` when the
|
|
398
|
+
calculus method is ``SR``::
|
|
399
|
+
|
|
400
|
+
sage: from sage.manifolds.calculus_method import CalculusMethod
|
|
401
|
+
sage: cm = CalculusMethod(base_field_type='real'); cm
|
|
402
|
+
Available calculus methods (* = current):
|
|
403
|
+
- SR (default) (*)
|
|
404
|
+
- sympy
|
|
405
|
+
sage: cm.simplify_function() is \
|
|
406
|
+
....: sage.manifolds.utilities.simplify_chain_real
|
|
407
|
+
True
|
|
408
|
+
|
|
409
|
+
Let us change it to :func:`~sage.calculus.functional.simplify`::
|
|
410
|
+
|
|
411
|
+
sage: cm.set_simplify_function(simplify)
|
|
412
|
+
sage: cm.simplify_function() is simplify
|
|
413
|
+
True
|
|
414
|
+
|
|
415
|
+
Since ``SR`` is the current calculus method, the above is equivalent
|
|
416
|
+
to::
|
|
417
|
+
|
|
418
|
+
sage: cm.set_simplify_function(simplify, method='SR')
|
|
419
|
+
sage: cm.simplify_function(method='SR') is simplify
|
|
420
|
+
True
|
|
421
|
+
|
|
422
|
+
We revert to the default simplifying function by::
|
|
423
|
+
|
|
424
|
+
sage: cm.set_simplify_function('default')
|
|
425
|
+
|
|
426
|
+
Then we are back to::
|
|
427
|
+
|
|
428
|
+
sage: cm.simplify_function() is \
|
|
429
|
+
....: sage.manifolds.utilities.simplify_chain_real
|
|
430
|
+
True
|
|
431
|
+
"""
|
|
432
|
+
if method is None:
|
|
433
|
+
method = self._current
|
|
434
|
+
if simplifying_func == 'default':
|
|
435
|
+
# the default function is restored
|
|
436
|
+
self._simplify_dict[method] = self._simplify_dict_default[method]
|
|
437
|
+
else:
|
|
438
|
+
self._simplify_dict[method] = simplifying_func
|
|
439
|
+
|
|
440
|
+
def simplify_function(self, method=None):
|
|
441
|
+
r"""
|
|
442
|
+
Return the simplifying function associated to a given calculus method.
|
|
443
|
+
|
|
444
|
+
The simplifying function is that used in all computations involved
|
|
445
|
+
with the calculus method.
|
|
446
|
+
|
|
447
|
+
INPUT:
|
|
448
|
+
|
|
449
|
+
- ``method`` -- (default: ``None``) string defining the calculus method
|
|
450
|
+
for which ``simplifying_func`` is provided; must be one of
|
|
451
|
+
|
|
452
|
+
- ``'SR'``: Sage's default symbolic engine (Symbolic Ring)
|
|
453
|
+
- ``'sympy'``: SymPy
|
|
454
|
+
- ``None``: the currently active calculus method of ``self`` is
|
|
455
|
+
assumed
|
|
456
|
+
|
|
457
|
+
OUTPUT: the simplifying function
|
|
458
|
+
|
|
459
|
+
EXAMPLES::
|
|
460
|
+
|
|
461
|
+
sage: from sage.manifolds.calculus_method import CalculusMethod
|
|
462
|
+
sage: cm = CalculusMethod()
|
|
463
|
+
sage: cm
|
|
464
|
+
Available calculus methods (* = current):
|
|
465
|
+
- SR (default) (*)
|
|
466
|
+
- sympy
|
|
467
|
+
sage: cm.simplify_function() # random (memory address)
|
|
468
|
+
<function simplify_chain_real at 0x7f958d5b6758>
|
|
469
|
+
|
|
470
|
+
The output stands for the function
|
|
471
|
+
:func:`~sage.manifolds.utilities.simplify_chain_real`::
|
|
472
|
+
|
|
473
|
+
sage: cm.simplify_function() is \
|
|
474
|
+
....: sage.manifolds.utilities.simplify_chain_real
|
|
475
|
+
True
|
|
476
|
+
|
|
477
|
+
Since ``SR`` is the default calculus method, we have::
|
|
478
|
+
|
|
479
|
+
sage: cm.simplify_function() is cm.simplify_function(method='SR')
|
|
480
|
+
True
|
|
481
|
+
|
|
482
|
+
The simplifying function associated with ``sympy`` is
|
|
483
|
+
:func:`~sage.manifolds.utilities.simplify_chain_real_sympy`::
|
|
484
|
+
|
|
485
|
+
sage: cm.simplify_function(method='sympy') # random (memory address)
|
|
486
|
+
<function simplify_chain_real_sympy at 0x7f0b35a578c0>
|
|
487
|
+
sage: cm.simplify_function(method='sympy') is \
|
|
488
|
+
....: sage.manifolds.utilities.simplify_chain_real_sympy
|
|
489
|
+
True
|
|
490
|
+
|
|
491
|
+
On complex manifolds, the simplifying functions are
|
|
492
|
+
:func:`~sage.manifolds.utilities.simplify_chain_generic`
|
|
493
|
+
and :func:`~sage.manifolds.utilities.simplify_chain_generic_sympy`
|
|
494
|
+
for respectively ``SR`` and ``sympy``::
|
|
495
|
+
|
|
496
|
+
sage: cmc = CalculusMethod(base_field_type='complex')
|
|
497
|
+
sage: cmc.simplify_function(method='SR') is \
|
|
498
|
+
....: sage.manifolds.utilities.simplify_chain_generic
|
|
499
|
+
True
|
|
500
|
+
sage: cmc.simplify_function(method='sympy') is \
|
|
501
|
+
....: sage.manifolds.utilities.simplify_chain_generic_sympy
|
|
502
|
+
True
|
|
503
|
+
|
|
504
|
+
Note that the simplifying functions can be customized via
|
|
505
|
+
:meth:`set_simplify_function`.
|
|
506
|
+
"""
|
|
507
|
+
if method is None:
|
|
508
|
+
method = self._current
|
|
509
|
+
return self._simplify_dict[method]
|
|
510
|
+
|
|
511
|
+
def reset(self):
|
|
512
|
+
r"""
|
|
513
|
+
Set the current calculus method to the default one.
|
|
514
|
+
|
|
515
|
+
EXAMPLES::
|
|
516
|
+
|
|
517
|
+
sage: from sage.manifolds.calculus_method import CalculusMethod
|
|
518
|
+
sage: cm = CalculusMethod(base_field_type='complex')
|
|
519
|
+
sage: cm
|
|
520
|
+
Available calculus methods (* = current):
|
|
521
|
+
- SR (default) (*)
|
|
522
|
+
- sympy
|
|
523
|
+
sage: cm.set('sympy')
|
|
524
|
+
sage: cm
|
|
525
|
+
Available calculus methods (* = current):
|
|
526
|
+
- SR (default)
|
|
527
|
+
- sympy (*)
|
|
528
|
+
sage: cm.reset()
|
|
529
|
+
sage: cm
|
|
530
|
+
Available calculus methods (* = current):
|
|
531
|
+
- SR (default) (*)
|
|
532
|
+
- sympy
|
|
533
|
+
"""
|
|
534
|
+
self._current = self._default
|
|
535
|
+
|
|
536
|
+
def _repr_(self):
|
|
537
|
+
r"""
|
|
538
|
+
String representation of the object.
|
|
539
|
+
|
|
540
|
+
TESTS::
|
|
541
|
+
|
|
542
|
+
sage: from sage.manifolds.calculus_method import CalculusMethod
|
|
543
|
+
sage: cm = CalculusMethod(base_field_type='complex')
|
|
544
|
+
sage: cm._repr_()
|
|
545
|
+
'Available calculus methods (* = current):\n - SR (default) (*)\n - sympy'
|
|
546
|
+
"""
|
|
547
|
+
resu = 'Available calculus methods (* = current):\n'
|
|
548
|
+
for method in self._methods:
|
|
549
|
+
resu += ' - {}'.format(method)
|
|
550
|
+
if method == self._default:
|
|
551
|
+
resu += ' (default)'
|
|
552
|
+
if method == self._current:
|
|
553
|
+
resu += ' (*)'
|
|
554
|
+
resu += '\n'
|
|
555
|
+
return resu[:-1]
|