passagemath-symbolics 10.6.40__cp314-cp314t-macosx_13_0_x86_64.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.
Potentially problematic release.
This version of passagemath-symbolics might be problematic. Click here for more details.
- passagemath_symbolics/.dylibs/libgmp.10.dylib +0 -0
- passagemath_symbolics/__init__.py +3 -0
- passagemath_symbolics-10.6.40.dist-info/METADATA +187 -0
- passagemath_symbolics-10.6.40.dist-info/RECORD +172 -0
- passagemath_symbolics-10.6.40.dist-info/WHEEL +6 -0
- passagemath_symbolics-10.6.40.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
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-symbolics
|
|
2
|
+
"Access to Maxima methods"
|
|
3
|
+
|
|
4
|
+
###############################################################################
|
|
5
|
+
# Sage: Open Source Mathematical Software
|
|
6
|
+
# Copyright (C) 2010 Burcin Erocal <burcin@erocal.org>
|
|
7
|
+
# Distributed under the terms of the GNU General Public License (GPL),
|
|
8
|
+
# version 2 or any later version. The full text of the GPL is available at:
|
|
9
|
+
# https://www.gnu.org/licenses/
|
|
10
|
+
###############################################################################
|
|
11
|
+
|
|
12
|
+
from sage.structure.sage_object import SageObject
|
|
13
|
+
from sage.interfaces.maxima import MaximaFunctionElement
|
|
14
|
+
from sage.misc.instancedoc import instancedoc
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@instancedoc
|
|
18
|
+
class MaximaFunctionElementWrapper(MaximaFunctionElement):
|
|
19
|
+
def __call__(self, *args, **kwds):
|
|
20
|
+
"""
|
|
21
|
+
Return a Sage expression instead of a Maxima pexpect interface element.
|
|
22
|
+
|
|
23
|
+
EXAMPLES::
|
|
24
|
+
|
|
25
|
+
sage: t = sin(x)^2 + cos(x)^2; t
|
|
26
|
+
cos(x)^2 + sin(x)^2
|
|
27
|
+
sage: res = t.maxima_methods().trigsimp(); res
|
|
28
|
+
1
|
|
29
|
+
sage: parent(res)
|
|
30
|
+
Symbolic Ring
|
|
31
|
+
"""
|
|
32
|
+
return super().__call__(*args, **kwds).sage()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class MaximaWrapper(SageObject):
|
|
36
|
+
def __init__(self, exp):
|
|
37
|
+
"""
|
|
38
|
+
Wrapper around Sage expressions to give access to Maxima methods.
|
|
39
|
+
|
|
40
|
+
We convert the given expression to Maxima and convert the return value
|
|
41
|
+
back to a Sage expression. Tab completion and help strings of Maxima
|
|
42
|
+
methods also work as expected.
|
|
43
|
+
|
|
44
|
+
EXAMPLES::
|
|
45
|
+
|
|
46
|
+
sage: t = log(sqrt(2) - 1) + log(sqrt(2) + 1); t
|
|
47
|
+
log(sqrt(2) + 1) + log(sqrt(2) - 1)
|
|
48
|
+
sage: u = t.maxima_methods(); u
|
|
49
|
+
MaximaWrapper(log(sqrt(2) + 1) + log(sqrt(2) - 1))
|
|
50
|
+
sage: type(u)
|
|
51
|
+
<class 'sage.symbolic.maxima_wrapper.MaximaWrapper'>
|
|
52
|
+
sage: u.logcontract()
|
|
53
|
+
log((sqrt(2) + 1)*(sqrt(2) - 1))
|
|
54
|
+
sage: u.logcontract().parent()
|
|
55
|
+
Symbolic Ring
|
|
56
|
+
|
|
57
|
+
TESTS:
|
|
58
|
+
|
|
59
|
+
Test tab completions::
|
|
60
|
+
|
|
61
|
+
sage: import sage.interfaces.tab_completion as s
|
|
62
|
+
sage: u = t.maxima_methods()
|
|
63
|
+
sage: s.completions('u.elliptic_',globals())
|
|
64
|
+
['u.elliptic_e', 'u.elliptic_ec', 'u.elliptic_eu', 'u.elliptic_f', 'u.elliptic_kc', 'u.elliptic_pi']
|
|
65
|
+
"""
|
|
66
|
+
self._exp = exp
|
|
67
|
+
self._maxima_exp = None
|
|
68
|
+
|
|
69
|
+
def __getattr__(self, s):
|
|
70
|
+
"""
|
|
71
|
+
Direct attempts to get attributes of this wrapper to the corresponding
|
|
72
|
+
Maxima expression. This allows tab completion to work as expected.
|
|
73
|
+
|
|
74
|
+
We wrap the function calls in order to convert results back to Sage.
|
|
75
|
+
|
|
76
|
+
EXAMPLES::
|
|
77
|
+
|
|
78
|
+
sage: t = sin(x)^2 + cos(x)^2; t
|
|
79
|
+
cos(x)^2 + sin(x)^2
|
|
80
|
+
sage: u = t.maxima_methods()
|
|
81
|
+
sage: import sage.interfaces.tab_completion as s
|
|
82
|
+
sage: s.completions('u.airy_',globals())
|
|
83
|
+
['u.airy_ai', 'u.airy_bi', 'u.airy_dai', 'u.airy_dbi']
|
|
84
|
+
sage: type(u.airy_ai)
|
|
85
|
+
<class 'sage.symbolic.maxima_wrapper.MaximaFunctionElementWrapper'>
|
|
86
|
+
sage: u.airy_ai()
|
|
87
|
+
airy_ai(cos(x)^2 + sin(x)^2)
|
|
88
|
+
"""
|
|
89
|
+
if self._maxima_exp is None:
|
|
90
|
+
self._maxima_exp = self._exp._maxima_()
|
|
91
|
+
if s[0] == '_':
|
|
92
|
+
return getattr(self._maxima_exp, s)
|
|
93
|
+
# add a wrapper function which converts the result back to
|
|
94
|
+
# a Sage expression
|
|
95
|
+
return MaximaFunctionElementWrapper(self._maxima_exp, s)
|
|
96
|
+
|
|
97
|
+
def __dir__(self):
|
|
98
|
+
"""
|
|
99
|
+
Enable the tab completions.
|
|
100
|
+
|
|
101
|
+
EXAMPLES::
|
|
102
|
+
|
|
103
|
+
sage: t = sin(x) + cos(x)
|
|
104
|
+
sage: u = t.maxima_methods()
|
|
105
|
+
sage: 'zeta' in u.__dir__()
|
|
106
|
+
True
|
|
107
|
+
"""
|
|
108
|
+
return self._maxima_()._tab_completion()
|
|
109
|
+
|
|
110
|
+
def sage(self):
|
|
111
|
+
"""
|
|
112
|
+
Return the Sage expression this wrapper corresponds to.
|
|
113
|
+
|
|
114
|
+
EXAMPLES::
|
|
115
|
+
|
|
116
|
+
sage: t = log(sqrt(2) - 1) + log(sqrt(2) + 1); t
|
|
117
|
+
log(sqrt(2) + 1) + log(sqrt(2) - 1)
|
|
118
|
+
sage: u = t.maxima_methods().sage()
|
|
119
|
+
sage: u is t
|
|
120
|
+
True
|
|
121
|
+
"""
|
|
122
|
+
return self._exp
|
|
123
|
+
|
|
124
|
+
def _symbolic_(self, parent):
|
|
125
|
+
"""
|
|
126
|
+
EXAMPLES::
|
|
127
|
+
|
|
128
|
+
sage: t = log(sqrt(2) - 1) + log(sqrt(2) + 1); t
|
|
129
|
+
log(sqrt(2) + 1) + log(sqrt(2) - 1)
|
|
130
|
+
sage: u = t.maxima_methods()
|
|
131
|
+
sage: u._symbolic_(SR) is t
|
|
132
|
+
True
|
|
133
|
+
sage: SR(u) is t # indirect doctest
|
|
134
|
+
True
|
|
135
|
+
"""
|
|
136
|
+
return parent(self._exp)
|
|
137
|
+
|
|
138
|
+
def __reduce__(self):
|
|
139
|
+
"""
|
|
140
|
+
EXAMPLES::
|
|
141
|
+
|
|
142
|
+
sage: t = log(sqrt(2) - 1) + log(sqrt(2) + 1); t
|
|
143
|
+
log(sqrt(2) + 1) + log(sqrt(2) - 1)
|
|
144
|
+
sage: u = t.maxima_methods(); u
|
|
145
|
+
MaximaWrapper(log(sqrt(2) + 1) + log(sqrt(2) - 1))
|
|
146
|
+
sage: loads(dumps(u))
|
|
147
|
+
MaximaWrapper(log(sqrt(2) + 1) + log(sqrt(2) - 1))
|
|
148
|
+
"""
|
|
149
|
+
return (MaximaWrapper, (self._exp,))
|
|
150
|
+
|
|
151
|
+
def _repr_(self):
|
|
152
|
+
"""
|
|
153
|
+
EXAMPLES::
|
|
154
|
+
|
|
155
|
+
sage: t = log(sqrt(2) - 1) + log(sqrt(2) + 1); t
|
|
156
|
+
log(sqrt(2) + 1) + log(sqrt(2) - 1)
|
|
157
|
+
sage: u = t.maxima_methods(); u
|
|
158
|
+
MaximaWrapper(log(sqrt(2) + 1) + log(sqrt(2) - 1))
|
|
159
|
+
sage: u._repr_()
|
|
160
|
+
'MaximaWrapper(log(sqrt(2) + 1) + log(sqrt(2) - 1))'
|
|
161
|
+
"""
|
|
162
|
+
return "MaximaWrapper(%s)" % (self._exp)
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-symbolics
|
|
2
|
+
"Operators"
|
|
3
|
+
|
|
4
|
+
import operator
|
|
5
|
+
|
|
6
|
+
from sage.structure.element import Expression
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def add_vararg(first, *rest):
|
|
10
|
+
r"""
|
|
11
|
+
Return the sum of all the arguments.
|
|
12
|
+
|
|
13
|
+
INPUT:
|
|
14
|
+
|
|
15
|
+
- ``first``, ``*rest`` -- arguments to add
|
|
16
|
+
|
|
17
|
+
OUTPUT: sum of the arguments
|
|
18
|
+
|
|
19
|
+
EXAMPLES::
|
|
20
|
+
|
|
21
|
+
sage: from sage.symbolic.operators import add_vararg
|
|
22
|
+
sage: add_vararg(1, 2, 3, 4, 5, 6, 7)
|
|
23
|
+
28
|
|
24
|
+
sage: x = SR.var('x')
|
|
25
|
+
sage: s = 1 + x + x^2 # symbolic sum
|
|
26
|
+
sage: bool(s.operator()(*s.operands()) == s)
|
|
27
|
+
True
|
|
28
|
+
"""
|
|
29
|
+
for r in rest:
|
|
30
|
+
first = first + r
|
|
31
|
+
return first
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def mul_vararg(first, *rest):
|
|
35
|
+
r"""
|
|
36
|
+
Return the product of all the arguments.
|
|
37
|
+
|
|
38
|
+
INPUT:
|
|
39
|
+
|
|
40
|
+
- ``first``, ``*rest`` -- arguments to multiply
|
|
41
|
+
|
|
42
|
+
OUTPUT: product of the arguments
|
|
43
|
+
|
|
44
|
+
EXAMPLES::
|
|
45
|
+
|
|
46
|
+
sage: from sage.symbolic.operators import mul_vararg
|
|
47
|
+
sage: mul_vararg(9, 8, 7, 6, 5, 4)
|
|
48
|
+
60480
|
|
49
|
+
sage: x = SR.var('x')
|
|
50
|
+
sage: p = x * cos(x) * sin(x) # symbolic product
|
|
51
|
+
sage: bool(p.operator()(*p.operands()) == p)
|
|
52
|
+
True
|
|
53
|
+
"""
|
|
54
|
+
for r in rest:
|
|
55
|
+
first = first * r
|
|
56
|
+
return first
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
arithmetic_operators = {add_vararg: '+',
|
|
60
|
+
mul_vararg: '*',
|
|
61
|
+
operator.add: '+',
|
|
62
|
+
operator.sub: '-',
|
|
63
|
+
operator.mul: '*',
|
|
64
|
+
operator.truediv: '/',
|
|
65
|
+
operator.floordiv: '//',
|
|
66
|
+
operator.pow: '^'}
|
|
67
|
+
|
|
68
|
+
relation_operators = {operator.eq: '==',
|
|
69
|
+
operator.lt: '<',
|
|
70
|
+
operator.gt: '>',
|
|
71
|
+
operator.ne: '!=',
|
|
72
|
+
operator.le: '<=',
|
|
73
|
+
operator.ge: '>='}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class FDerivativeOperator:
|
|
77
|
+
r"""
|
|
78
|
+
Function derivative operators.
|
|
79
|
+
|
|
80
|
+
A function derivative operator represents a partial derivative
|
|
81
|
+
of a function with respect to some variables.
|
|
82
|
+
|
|
83
|
+
The underlying data are the function, and the parameter set,
|
|
84
|
+
a list recording the indices of the variables with respect
|
|
85
|
+
to which the partial derivative is taken.
|
|
86
|
+
"""
|
|
87
|
+
def __init__(self, function, parameter_set):
|
|
88
|
+
r"""
|
|
89
|
+
Initialize this function derivative operator.
|
|
90
|
+
|
|
91
|
+
EXAMPLES::
|
|
92
|
+
|
|
93
|
+
sage: from sage.symbolic.operators import FDerivativeOperator
|
|
94
|
+
sage: f = function('foo')
|
|
95
|
+
sage: op = FDerivativeOperator(f, [0, 1])
|
|
96
|
+
sage: loads(dumps(op))
|
|
97
|
+
D[0, 1](foo)
|
|
98
|
+
"""
|
|
99
|
+
self._f = function
|
|
100
|
+
self._parameter_set = [int(_) for _ in parameter_set]
|
|
101
|
+
|
|
102
|
+
def __call__(self, *args):
|
|
103
|
+
r"""
|
|
104
|
+
Call this function derivative operator on these arguments.
|
|
105
|
+
|
|
106
|
+
EXAMPLES::
|
|
107
|
+
|
|
108
|
+
sage: from sage.symbolic.operators import FDerivativeOperator
|
|
109
|
+
sage: x, y = SR.var('x, y')
|
|
110
|
+
sage: f = function('foo')
|
|
111
|
+
sage: op = FDerivativeOperator(f, [0, 1])
|
|
112
|
+
sage: op(x, y)
|
|
113
|
+
diff(foo(x, y), x, y)
|
|
114
|
+
sage: op(x, x^2)
|
|
115
|
+
D[0, 1](foo)(x, x^2)
|
|
116
|
+
|
|
117
|
+
TESTS:
|
|
118
|
+
|
|
119
|
+
We should be able to operate on functions evaluated at a
|
|
120
|
+
point, not just a symbolic variable, :issue:`12796`::
|
|
121
|
+
|
|
122
|
+
sage: from sage.symbolic.operators import FDerivativeOperator
|
|
123
|
+
sage: f = function('f')
|
|
124
|
+
sage: op = FDerivativeOperator(f, [0])
|
|
125
|
+
sage: op(1)
|
|
126
|
+
D[0](f)(1)
|
|
127
|
+
"""
|
|
128
|
+
if (not all(isinstance(x, Expression) and x.is_symbol() for x in args) or
|
|
129
|
+
len(args) != len(set(args))):
|
|
130
|
+
# An evaluated derivative of the form f'(1) is not a
|
|
131
|
+
# symbolic variable, yet we would like to treat it
|
|
132
|
+
# like one. So, we replace the argument `1` with a
|
|
133
|
+
# temporary variable e.g. `t0` and then evaluate the
|
|
134
|
+
# derivative f'(t0) symbolically at t0=1. See trac
|
|
135
|
+
# #12796.
|
|
136
|
+
from sage.symbolic.ring import SR
|
|
137
|
+
|
|
138
|
+
temp_args = SR.temp_var(n=len(args))
|
|
139
|
+
vars = [temp_args[i] for i in self._parameter_set]
|
|
140
|
+
return self._f(*temp_args).diff(*vars).function(*temp_args)(*args)
|
|
141
|
+
vars = [args[i] for i in self._parameter_set]
|
|
142
|
+
return self._f(*args).diff(*vars)
|
|
143
|
+
|
|
144
|
+
def __repr__(self):
|
|
145
|
+
r"""
|
|
146
|
+
Return the string representation of this function derivative operator.
|
|
147
|
+
|
|
148
|
+
EXAMPLES::
|
|
149
|
+
|
|
150
|
+
sage: from sage.symbolic.operators import FDerivativeOperator
|
|
151
|
+
sage: f = function('foo')
|
|
152
|
+
sage: op = FDerivativeOperator(f, [0, 1]); op
|
|
153
|
+
D[0, 1](foo)
|
|
154
|
+
"""
|
|
155
|
+
return "D[%s](%s)" % (", ".join(map(repr, self._parameter_set)), self._f)
|
|
156
|
+
|
|
157
|
+
def function(self):
|
|
158
|
+
r"""
|
|
159
|
+
Return the function associated to this function derivative operator.
|
|
160
|
+
|
|
161
|
+
EXAMPLES::
|
|
162
|
+
|
|
163
|
+
sage: from sage.symbolic.operators import FDerivativeOperator
|
|
164
|
+
sage: f = function('foo')
|
|
165
|
+
sage: op = FDerivativeOperator(f, [0, 1])
|
|
166
|
+
sage: op.function()
|
|
167
|
+
foo
|
|
168
|
+
"""
|
|
169
|
+
return self._f
|
|
170
|
+
|
|
171
|
+
def change_function(self, new):
|
|
172
|
+
r"""
|
|
173
|
+
Return a new function derivative operator with the same
|
|
174
|
+
parameter set but for a new function.
|
|
175
|
+
|
|
176
|
+
EXAMPLES::
|
|
177
|
+
|
|
178
|
+
sage: from sage.symbolic.operators import FDerivativeOperator
|
|
179
|
+
sage: f = function('foo')
|
|
180
|
+
sage: b = function('bar')
|
|
181
|
+
sage: op = FDerivativeOperator(f, [0, 1])
|
|
182
|
+
sage: op.change_function(bar)
|
|
183
|
+
D[0, 1](bar)
|
|
184
|
+
"""
|
|
185
|
+
return FDerivativeOperator(new, self._parameter_set)
|
|
186
|
+
|
|
187
|
+
def parameter_set(self):
|
|
188
|
+
r"""
|
|
189
|
+
Return the parameter set of this function derivative operator.
|
|
190
|
+
|
|
191
|
+
This is the list of indices of variables with respect to which
|
|
192
|
+
the derivative is taken.
|
|
193
|
+
|
|
194
|
+
EXAMPLES::
|
|
195
|
+
|
|
196
|
+
sage: from sage.symbolic.operators import FDerivativeOperator
|
|
197
|
+
sage: f = function('foo')
|
|
198
|
+
sage: op = FDerivativeOperator(f, [0, 1])
|
|
199
|
+
sage: op.parameter_set()
|
|
200
|
+
[0, 1]
|
|
201
|
+
"""
|
|
202
|
+
return self._parameter_set
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class DerivativeOperator:
|
|
206
|
+
"""
|
|
207
|
+
Derivative operator.
|
|
208
|
+
|
|
209
|
+
Acting with this operator onto a function gives a new operator (of
|
|
210
|
+
type :class:`FDerivativeOperator`) representing the function
|
|
211
|
+
differentiated with respect to one or multiple of its arguments.
|
|
212
|
+
|
|
213
|
+
This operator takes a list of indices specifying the position of
|
|
214
|
+
the arguments to differentiate. For example, D[0, 0, 1] is an
|
|
215
|
+
operator that differentiates a function twice with respect to its
|
|
216
|
+
first argument and once with respect to its second argument.
|
|
217
|
+
|
|
218
|
+
EXAMPLES::
|
|
219
|
+
|
|
220
|
+
sage: x, y = var('x,y'); f = function('f')
|
|
221
|
+
sage: D[0](f)(x)
|
|
222
|
+
diff(f(x), x)
|
|
223
|
+
sage: D[0](f)(x, y)
|
|
224
|
+
diff(f(x, y), x)
|
|
225
|
+
sage: D[0, 1](f)(x, y)
|
|
226
|
+
diff(f(x, y), x, y)
|
|
227
|
+
sage: D[0, 1](f)(x, x^2)
|
|
228
|
+
D[0, 1](f)(x, x^2)
|
|
229
|
+
"""
|
|
230
|
+
class DerivativeOperatorWithParameters:
|
|
231
|
+
def __init__(self, parameter_set):
|
|
232
|
+
self._parameter_set = parameter_set
|
|
233
|
+
|
|
234
|
+
def __call__(self, function):
|
|
235
|
+
return FDerivativeOperator(function, self._parameter_set)
|
|
236
|
+
|
|
237
|
+
def __repr__(self):
|
|
238
|
+
"""
|
|
239
|
+
Return the string representation of this derivative operator.
|
|
240
|
+
|
|
241
|
+
EXAMPLES::
|
|
242
|
+
|
|
243
|
+
sage: D[0]
|
|
244
|
+
D[0]
|
|
245
|
+
sage: D[0, 1]
|
|
246
|
+
D[0, 1]
|
|
247
|
+
"""
|
|
248
|
+
return "D[%s]" % (", ".join(map(repr, self._parameter_set)))
|
|
249
|
+
|
|
250
|
+
def __getitem__(self, args):
|
|
251
|
+
"""
|
|
252
|
+
TESTS:
|
|
253
|
+
|
|
254
|
+
The order in which the indices are given should not matter::
|
|
255
|
+
|
|
256
|
+
sage: x, y = var('x,y'); f = function('f')
|
|
257
|
+
sage: bool(D[0, 1, 0](f)(x, y) == D[0, 0, 1](f)(x, y))
|
|
258
|
+
True
|
|
259
|
+
sage: bool(D[1, 0, 0](f)(x, y) == D[0, 0, 1](f)(x, y))
|
|
260
|
+
True
|
|
261
|
+
"""
|
|
262
|
+
if not isinstance(args, tuple):
|
|
263
|
+
args = (args,)
|
|
264
|
+
return self.DerivativeOperatorWithParameters(args)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
D = DerivativeOperator()
|