passagemath-symbolics 10.6.37__cp310-cp310-musllinux_1_2_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.
- passagemath_symbolics/__init__.py +3 -0
- passagemath_symbolics-10.6.37.dist-info/METADATA +187 -0
- passagemath_symbolics-10.6.37.dist-info/RECORD +171 -0
- passagemath_symbolics-10.6.37.dist-info/WHEEL +5 -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-310-x86_64-linux-gnu.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-310-x86_64-linux-gnu.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-310-x86_64-linux-gnu.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-310-x86_64-linux-gnu.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-310-x86_64-linux-gnu.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/symbolic/subring.py
ADDED
|
@@ -0,0 +1,1025 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-symbolics
|
|
2
|
+
r"""
|
|
3
|
+
Subrings of the Symbolic Ring
|
|
4
|
+
|
|
5
|
+
Subrings of the symbolic ring can be created via the
|
|
6
|
+
:meth:`~sage.symbolic.ring.SymbolicRing.subring` method of
|
|
7
|
+
``SR``. This will call :class:`SymbolicSubring <SymbolicSubringFactory>`
|
|
8
|
+
of this module.
|
|
9
|
+
|
|
10
|
+
The following kinds of subrings are supported:
|
|
11
|
+
|
|
12
|
+
- A symbolic subring of expressions, whose variables are contained in
|
|
13
|
+
a given set of symbolic variables (see
|
|
14
|
+
:class:`SymbolicSubringAcceptingVars`). E.g.
|
|
15
|
+
::
|
|
16
|
+
|
|
17
|
+
sage: SR.subring(accepting_variables=('a', 'b'))
|
|
18
|
+
Symbolic Subring accepting the variables a, b
|
|
19
|
+
|
|
20
|
+
- A symbolic subring of expressions, whose variables are disjoint to a
|
|
21
|
+
given set of symbolic variables (see
|
|
22
|
+
:class:`SymbolicSubringRejectingVars`). E.g.
|
|
23
|
+
::
|
|
24
|
+
|
|
25
|
+
sage: SR.subring(rejecting_variables=('r', 's'))
|
|
26
|
+
Symbolic Subring rejecting the variables r, s
|
|
27
|
+
|
|
28
|
+
- The subring of symbolic constants (see
|
|
29
|
+
:class:`SymbolicConstantsSubring`). E.g.
|
|
30
|
+
::
|
|
31
|
+
|
|
32
|
+
sage: SR.subring(no_variables=True)
|
|
33
|
+
Symbolic Constants Subring
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
TESTS:
|
|
37
|
+
|
|
38
|
+
In the following we have a couple of tests to see whether the coercion
|
|
39
|
+
framework works properly::
|
|
40
|
+
|
|
41
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
42
|
+
sage: V = var('a, r, x')
|
|
43
|
+
sage: A = SymbolicSubring(accepting_variables=(a,)); A
|
|
44
|
+
Symbolic Subring accepting the variable a
|
|
45
|
+
sage: R = SymbolicSubring(rejecting_variables=(r,)); R
|
|
46
|
+
Symbolic Subring rejecting the variable r
|
|
47
|
+
sage: C = SymbolicSubring(no_variables=True); C
|
|
48
|
+
Symbolic Constants Subring
|
|
49
|
+
|
|
50
|
+
::
|
|
51
|
+
|
|
52
|
+
sage: sage.categories.pushout.pushout(A, R)
|
|
53
|
+
Symbolic Subring rejecting the variable r
|
|
54
|
+
sage: sage.categories.pushout.pushout(R, C)
|
|
55
|
+
Symbolic Subring rejecting the variable r
|
|
56
|
+
sage: sage.categories.pushout.pushout(C, A)
|
|
57
|
+
Symbolic Subring accepting the variable a
|
|
58
|
+
sage: sage.categories.pushout.pushout(A, SR)
|
|
59
|
+
Symbolic Ring
|
|
60
|
+
sage: sage.categories.pushout.pushout(R, SR)
|
|
61
|
+
Symbolic Ring
|
|
62
|
+
sage: sage.categories.pushout.pushout(C, SR)
|
|
63
|
+
Symbolic Ring
|
|
64
|
+
|
|
65
|
+
::
|
|
66
|
+
|
|
67
|
+
sage: cm = sage.structure.element.get_coercion_model()
|
|
68
|
+
sage: cm.common_parent(A, R)
|
|
69
|
+
Symbolic Subring rejecting the variable r
|
|
70
|
+
sage: cm.common_parent(R, C)
|
|
71
|
+
Symbolic Subring rejecting the variable r
|
|
72
|
+
sage: cm.common_parent(C, A)
|
|
73
|
+
Symbolic Subring accepting the variable a
|
|
74
|
+
sage: cm.common_parent(A, SR)
|
|
75
|
+
Symbolic Ring
|
|
76
|
+
sage: cm.common_parent(R, SR)
|
|
77
|
+
Symbolic Ring
|
|
78
|
+
sage: cm.common_parent(C, SR)
|
|
79
|
+
Symbolic Ring
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
AUTHORS:
|
|
83
|
+
|
|
84
|
+
- Daniel Krenn (2015)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
Classes and Methods
|
|
88
|
+
===================
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
# ****************************************************************************
|
|
92
|
+
# Copyright (C) 2015 Daniel Krenn <dev@danielkrenn.at>
|
|
93
|
+
#
|
|
94
|
+
# This program is free software: you can redistribute it and/or modify
|
|
95
|
+
# it under the terms of the GNU General Public License as published by
|
|
96
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
97
|
+
# (at your option) any later version.
|
|
98
|
+
# https://www.gnu.org/licenses/
|
|
99
|
+
# ****************************************************************************
|
|
100
|
+
|
|
101
|
+
import sage.rings.abc
|
|
102
|
+
from .ring import SymbolicRing, SR
|
|
103
|
+
from sage.categories.pushout import ConstructionFunctor
|
|
104
|
+
from sage.structure.factory import UniqueFactory
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class SymbolicSubringFactory(UniqueFactory):
|
|
108
|
+
r"""
|
|
109
|
+
A factory creating a symbolic subring.
|
|
110
|
+
|
|
111
|
+
INPUT:
|
|
112
|
+
|
|
113
|
+
Specify one of the following keywords to create a subring.
|
|
114
|
+
|
|
115
|
+
- ``accepting_variables`` -- (default: ``None``) a tuple or other
|
|
116
|
+
iterable of variables. If specified, then a symbolic subring of
|
|
117
|
+
expressions in only these variables is created.
|
|
118
|
+
|
|
119
|
+
- ``rejecting_variables`` -- (default: ``None``) a tuple or other
|
|
120
|
+
iterable of variables. If specified, then a symbolic subring of
|
|
121
|
+
expressions in variables distinct to these variables is
|
|
122
|
+
created.
|
|
123
|
+
|
|
124
|
+
- ``no_variables`` -- boolean (default: ``False``); if set,
|
|
125
|
+
then a symbolic subring of constant expressions (i.e.,
|
|
126
|
+
expressions without a variable) is created.
|
|
127
|
+
|
|
128
|
+
EXAMPLES::
|
|
129
|
+
|
|
130
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
131
|
+
sage: V = var('a, b, c, r, s, t, x, y, z')
|
|
132
|
+
|
|
133
|
+
::
|
|
134
|
+
|
|
135
|
+
sage: A = SymbolicSubring(accepting_variables=(a, b, c)); A
|
|
136
|
+
Symbolic Subring accepting the variables a, b, c
|
|
137
|
+
sage: tuple((v, v in A) for v in V)
|
|
138
|
+
((a, True), (b, True), (c, True),
|
|
139
|
+
(r, False), (s, False), (t, False),
|
|
140
|
+
(x, False), (y, False), (z, False))
|
|
141
|
+
|
|
142
|
+
::
|
|
143
|
+
|
|
144
|
+
sage: R = SymbolicSubring(rejecting_variables=(r, s, t)); R
|
|
145
|
+
Symbolic Subring rejecting the variables r, s, t
|
|
146
|
+
sage: tuple((v, v in R) for v in V)
|
|
147
|
+
((a, True), (b, True), (c, True),
|
|
148
|
+
(r, False), (s, False), (t, False),
|
|
149
|
+
(x, True), (y, True), (z, True))
|
|
150
|
+
|
|
151
|
+
::
|
|
152
|
+
|
|
153
|
+
sage: C = SymbolicSubring(no_variables=True); C
|
|
154
|
+
Symbolic Constants Subring
|
|
155
|
+
sage: tuple((v, v in C) for v in V)
|
|
156
|
+
((a, False), (b, False), (c, False),
|
|
157
|
+
(r, False), (s, False), (t, False),
|
|
158
|
+
(x, False), (y, False), (z, False))
|
|
159
|
+
|
|
160
|
+
TESTS::
|
|
161
|
+
|
|
162
|
+
sage: SymbolicSubring(accepting_variables=tuple()) is C
|
|
163
|
+
True
|
|
164
|
+
|
|
165
|
+
::
|
|
166
|
+
|
|
167
|
+
sage: SymbolicSubring(rejecting_variables=tuple()) is SR
|
|
168
|
+
True
|
|
169
|
+
"""
|
|
170
|
+
def create_key_and_extra_args(
|
|
171
|
+
self, accepting_variables=None, rejecting_variables=None,
|
|
172
|
+
no_variables=False, **kwds):
|
|
173
|
+
r"""
|
|
174
|
+
Given the arguments and keyword, create a key that uniquely
|
|
175
|
+
determines this object.
|
|
176
|
+
|
|
177
|
+
See :class:`SymbolicSubringFactory` for details.
|
|
178
|
+
|
|
179
|
+
TESTS::
|
|
180
|
+
|
|
181
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
182
|
+
sage: SymbolicSubring.create_key_and_extra_args()
|
|
183
|
+
Traceback (most recent call last):
|
|
184
|
+
...
|
|
185
|
+
ValueError: cannot create a symbolic subring since nothing is specified
|
|
186
|
+
sage: SymbolicSubring.create_key_and_extra_args(
|
|
187
|
+
....: accepting_variables=('a',), rejecting_variables=('r',))
|
|
188
|
+
Traceback (most recent call last):
|
|
189
|
+
...
|
|
190
|
+
ValueError: cannot create a symbolic subring since input is ambiguous
|
|
191
|
+
sage: SymbolicSubring.create_key_and_extra_args(
|
|
192
|
+
....: accepting_variables=('a',), no_variables=True)
|
|
193
|
+
Traceback (most recent call last):
|
|
194
|
+
...
|
|
195
|
+
ValueError: cannot create a symbolic subring since input is ambiguous
|
|
196
|
+
sage: SymbolicSubring.create_key_and_extra_args(
|
|
197
|
+
....: rejecting_variables=('r',), no_variables=True)
|
|
198
|
+
Traceback (most recent call last):
|
|
199
|
+
...
|
|
200
|
+
ValueError: cannot create a symbolic subring since input is ambiguous
|
|
201
|
+
"""
|
|
202
|
+
if accepting_variables is None and \
|
|
203
|
+
rejecting_variables is None and \
|
|
204
|
+
not no_variables:
|
|
205
|
+
raise ValueError('cannot create a symbolic subring '
|
|
206
|
+
'since nothing is specified')
|
|
207
|
+
if accepting_variables is not None and rejecting_variables is not None or \
|
|
208
|
+
rejecting_variables is not None and no_variables or \
|
|
209
|
+
no_variables and accepting_variables is not None:
|
|
210
|
+
raise ValueError('cannot create a symbolic subring '
|
|
211
|
+
'since input is ambiguous')
|
|
212
|
+
|
|
213
|
+
if accepting_variables is not None:
|
|
214
|
+
vars = tuple(accepting_variables)
|
|
215
|
+
if vars:
|
|
216
|
+
cls = SymbolicSubringAcceptingVars
|
|
217
|
+
else:
|
|
218
|
+
cls = SymbolicConstantsSubring
|
|
219
|
+
elif rejecting_variables is not None:
|
|
220
|
+
vars = tuple(rejecting_variables)
|
|
221
|
+
cls = SymbolicSubringRejectingVars
|
|
222
|
+
elif no_variables:
|
|
223
|
+
vars = tuple()
|
|
224
|
+
cls = SymbolicConstantsSubring
|
|
225
|
+
|
|
226
|
+
vars = tuple(sorted(iter(SR(v) for v in vars), key=str))
|
|
227
|
+
return (cls, vars), kwds
|
|
228
|
+
|
|
229
|
+
def create_object(self, version, key, **kwds):
|
|
230
|
+
r"""
|
|
231
|
+
Create an object from the given arguments.
|
|
232
|
+
|
|
233
|
+
See :class:`SymbolicSubringFactory` for details.
|
|
234
|
+
|
|
235
|
+
TESTS::
|
|
236
|
+
|
|
237
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
238
|
+
sage: SymbolicSubring(rejecting_variables=tuple()) is SR # indirect doctest
|
|
239
|
+
True
|
|
240
|
+
"""
|
|
241
|
+
cls, vars = key
|
|
242
|
+
if cls is SymbolicSubringRejectingVars and not vars:
|
|
243
|
+
return SR
|
|
244
|
+
return cls(vars, **kwds)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
SymbolicSubring = SymbolicSubringFactory("SymbolicSubring")
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
class GenericSymbolicSubring(SymbolicRing):
|
|
251
|
+
|
|
252
|
+
def __init__(self, vars):
|
|
253
|
+
r"""
|
|
254
|
+
An abstract base class for a symbolic subring.
|
|
255
|
+
|
|
256
|
+
INPUT:
|
|
257
|
+
|
|
258
|
+
- ``vars`` -- tuple of symbolic variables
|
|
259
|
+
|
|
260
|
+
TESTS::
|
|
261
|
+
|
|
262
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
263
|
+
sage: SymbolicSubring(accepting_variables=('a',)) # indirect doctest
|
|
264
|
+
Symbolic Subring accepting the variable a
|
|
265
|
+
sage: SymbolicSubring(rejecting_variables=('r',)) # indirect doctest
|
|
266
|
+
Symbolic Subring rejecting the variable r
|
|
267
|
+
sage: SymbolicSubring(no_variables=True) # indirect doctest
|
|
268
|
+
Symbolic Constants Subring
|
|
269
|
+
sage: SymbolicSubring(rejecting_variables=tuple()) # indirect doctest
|
|
270
|
+
Symbolic Ring
|
|
271
|
+
|
|
272
|
+
::
|
|
273
|
+
|
|
274
|
+
sage: SR.subring(accepting_variables=(0, pi, sqrt(2), 'zzz', I))
|
|
275
|
+
Traceback (most recent call last):
|
|
276
|
+
...
|
|
277
|
+
ValueError: Invalid variables: 0, I, pi, sqrt(2)
|
|
278
|
+
"""
|
|
279
|
+
super().__init__()
|
|
280
|
+
self._vars_ = set(vars)
|
|
281
|
+
if not all(v.is_symbol() for v in self._vars_):
|
|
282
|
+
raise ValueError('Invalid variables: {}'.format(
|
|
283
|
+
', '.join(str(v) for v in sorted(self._vars_, key=str)
|
|
284
|
+
if not v.is_symbol())))
|
|
285
|
+
|
|
286
|
+
def _repr_variables_(self):
|
|
287
|
+
r"""
|
|
288
|
+
Return a representation string of the variables.
|
|
289
|
+
|
|
290
|
+
OUTPUT: string
|
|
291
|
+
|
|
292
|
+
TESTS::
|
|
293
|
+
|
|
294
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
295
|
+
sage: SymbolicSubring(accepting_variables=tuple())._repr_variables_()
|
|
296
|
+
'no variable'
|
|
297
|
+
sage: SymbolicSubring(accepting_variables=('a',))._repr_variables_()
|
|
298
|
+
'the variable a'
|
|
299
|
+
sage: SymbolicSubring(accepting_variables=('a', 'b'))._repr_variables_()
|
|
300
|
+
'the variables a, b'
|
|
301
|
+
"""
|
|
302
|
+
if not self._vars_:
|
|
303
|
+
s = 'no variable'
|
|
304
|
+
elif len(self._vars_) == 1:
|
|
305
|
+
s = 'the variable '
|
|
306
|
+
else:
|
|
307
|
+
s = 'the variables '
|
|
308
|
+
return s + ', '.join(str(v) for v in sorted(self._vars_, key=str))
|
|
309
|
+
|
|
310
|
+
def has_valid_variable(self, variable):
|
|
311
|
+
r"""
|
|
312
|
+
Return whether the given ``variable`` is valid in this subring.
|
|
313
|
+
|
|
314
|
+
INPUT:
|
|
315
|
+
|
|
316
|
+
- ``variable`` -- a symbolic variable
|
|
317
|
+
|
|
318
|
+
OUTPUT: boolean
|
|
319
|
+
|
|
320
|
+
EXAMPLES::
|
|
321
|
+
|
|
322
|
+
sage: from sage.symbolic.subring import GenericSymbolicSubring
|
|
323
|
+
sage: GenericSymbolicSubring(vars=tuple()).has_valid_variable(x)
|
|
324
|
+
Traceback (most recent call last):
|
|
325
|
+
...
|
|
326
|
+
NotImplementedError: Not implemented in this abstract base class
|
|
327
|
+
"""
|
|
328
|
+
raise NotImplementedError('Not implemented in this abstract base class')
|
|
329
|
+
|
|
330
|
+
def _element_constructor_(self, x):
|
|
331
|
+
r"""
|
|
332
|
+
Create the element of this subring specified by the input ``x``.
|
|
333
|
+
|
|
334
|
+
INPUT:
|
|
335
|
+
|
|
336
|
+
- ``x`` -- an object
|
|
337
|
+
|
|
338
|
+
OUTPUT: an element of this symbolic subring
|
|
339
|
+
|
|
340
|
+
TESTS::
|
|
341
|
+
|
|
342
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
343
|
+
sage: S = SymbolicSubring(accepting_variables=('a',))
|
|
344
|
+
sage: S('a') # indirect doctest
|
|
345
|
+
a
|
|
346
|
+
sage: _.parent()
|
|
347
|
+
Symbolic Subring accepting the variable a
|
|
348
|
+
sage: S('x') # indirect doctest
|
|
349
|
+
Traceback (most recent call last):
|
|
350
|
+
...
|
|
351
|
+
TypeError: x is not contained in Symbolic Subring accepting the variable a
|
|
352
|
+
"""
|
|
353
|
+
expression = super()._element_constructor_(x)
|
|
354
|
+
assert expression.parent() is self
|
|
355
|
+
if not all(self.has_valid_variable(var)
|
|
356
|
+
for var in expression.variables()):
|
|
357
|
+
raise TypeError('%s is not contained in %s' % (x, self))
|
|
358
|
+
return expression
|
|
359
|
+
|
|
360
|
+
def _coerce_map_from_(self, P):
|
|
361
|
+
r"""
|
|
362
|
+
Return whether ``P`` coerces into this symbolic subring.
|
|
363
|
+
|
|
364
|
+
INPUT:
|
|
365
|
+
|
|
366
|
+
- ``P`` -- a parent
|
|
367
|
+
|
|
368
|
+
OUTPUT: boolean or ``None``
|
|
369
|
+
|
|
370
|
+
TESTS::
|
|
371
|
+
|
|
372
|
+
sage: from sage.symbolic.subring import GenericSymbolicSubring
|
|
373
|
+
sage: GenericSymbolicSubring(vars=tuple()).has_coerce_map_from(SR) # indirect doctest # not tested see #19231
|
|
374
|
+
False
|
|
375
|
+
|
|
376
|
+
::
|
|
377
|
+
|
|
378
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
379
|
+
sage: C = SymbolicSubring(no_variables=True)
|
|
380
|
+
sage: C.has_coerce_map_from(ZZ) # indirect doctest
|
|
381
|
+
True
|
|
382
|
+
sage: C.has_coerce_map_from(QQ) # indirect doctest
|
|
383
|
+
True
|
|
384
|
+
sage: C.has_coerce_map_from(RR) # indirect doctest
|
|
385
|
+
True
|
|
386
|
+
sage: C.has_coerce_map_from(RIF) # indirect doctest
|
|
387
|
+
True
|
|
388
|
+
sage: C.has_coerce_map_from(CC) # indirect doctest
|
|
389
|
+
True
|
|
390
|
+
sage: C.has_coerce_map_from(CIF) # indirect doctest
|
|
391
|
+
True
|
|
392
|
+
sage: C.has_coerce_map_from(AA) # indirect doctest
|
|
393
|
+
True
|
|
394
|
+
sage: C.has_coerce_map_from(QQbar) # indirect doctest
|
|
395
|
+
True
|
|
396
|
+
sage: C.has_coerce_map_from(SR) # indirect doctest
|
|
397
|
+
False
|
|
398
|
+
"""
|
|
399
|
+
from sage.rings.infinity import InfinityRing
|
|
400
|
+
from sage.rings.qqbar import AA, QQbar
|
|
401
|
+
from sage.rings.real_lazy import RLF, CLF
|
|
402
|
+
|
|
403
|
+
if isinstance(P, type):
|
|
404
|
+
return SR._coerce_map_from_(P)
|
|
405
|
+
|
|
406
|
+
if RLF.has_coerce_map_from(P) or \
|
|
407
|
+
CLF.has_coerce_map_from(P) or \
|
|
408
|
+
AA.has_coerce_map_from(P) or \
|
|
409
|
+
QQbar.has_coerce_map_from(P):
|
|
410
|
+
return True
|
|
411
|
+
|
|
412
|
+
if (P is InfinityRing or
|
|
413
|
+
isinstance(P, (sage.rings.abc.RealIntervalField,
|
|
414
|
+
sage.rings.abc.ComplexIntervalField))):
|
|
415
|
+
return True
|
|
416
|
+
|
|
417
|
+
if P._is_numerical():
|
|
418
|
+
return P not in (RLF, CLF, AA, QQbar)
|
|
419
|
+
|
|
420
|
+
def __eq__(self, other):
|
|
421
|
+
"""
|
|
422
|
+
Compare two symbolic subrings.
|
|
423
|
+
|
|
424
|
+
EXAMPLES::
|
|
425
|
+
|
|
426
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
427
|
+
sage: A = SymbolicSubring(accepting_variables=('a',))
|
|
428
|
+
sage: B = SymbolicSubring(accepting_variables=('b',))
|
|
429
|
+
sage: AB = SymbolicSubring(accepting_variables=('a', 'b'))
|
|
430
|
+
sage: A == A
|
|
431
|
+
True
|
|
432
|
+
sage: A == B
|
|
433
|
+
False
|
|
434
|
+
sage: A == AB
|
|
435
|
+
False
|
|
436
|
+
"""
|
|
437
|
+
if not isinstance(other, GenericSymbolicSubring):
|
|
438
|
+
return False
|
|
439
|
+
return self._vars_ == other._vars_
|
|
440
|
+
|
|
441
|
+
def __ne__(self, other):
|
|
442
|
+
"""
|
|
443
|
+
Check whether ``self`` and ``other`` are not equal.
|
|
444
|
+
|
|
445
|
+
EXAMPLES::
|
|
446
|
+
|
|
447
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
448
|
+
sage: A = SymbolicSubring(accepting_variables=('a',))
|
|
449
|
+
sage: B = SymbolicSubring(accepting_variables=('b',))
|
|
450
|
+
sage: AB = SymbolicSubring(accepting_variables=('a', 'b'))
|
|
451
|
+
sage: A != A
|
|
452
|
+
False
|
|
453
|
+
sage: A != B
|
|
454
|
+
True
|
|
455
|
+
sage: A != AB
|
|
456
|
+
True
|
|
457
|
+
"""
|
|
458
|
+
return not self == other
|
|
459
|
+
|
|
460
|
+
def __hash__(self):
|
|
461
|
+
"""
|
|
462
|
+
Return the hash of ``self``.
|
|
463
|
+
|
|
464
|
+
EXAMPLES::
|
|
465
|
+
|
|
466
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
467
|
+
sage: A = SymbolicSubring(accepting_variables=('a',))
|
|
468
|
+
sage: B = SymbolicSubring(accepting_variables=('b',))
|
|
469
|
+
sage: hash(A) == hash(A)
|
|
470
|
+
True
|
|
471
|
+
sage: hash(A) == hash(B)
|
|
472
|
+
False
|
|
473
|
+
"""
|
|
474
|
+
return hash(tuple(sorted(self._vars_)))
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
class GenericSymbolicSubringFunctor(ConstructionFunctor):
|
|
478
|
+
r"""
|
|
479
|
+
A base class for the functors constructing symbolic subrings.
|
|
480
|
+
|
|
481
|
+
INPUT:
|
|
482
|
+
|
|
483
|
+
- ``vars`` -- tuple, set, or other iterable of symbolic variables
|
|
484
|
+
|
|
485
|
+
EXAMPLES::
|
|
486
|
+
|
|
487
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
488
|
+
sage: SymbolicSubring(no_variables=True).construction()[0] # indirect doctest
|
|
489
|
+
Subring<accepting no variable>
|
|
490
|
+
|
|
491
|
+
.. SEEALSO::
|
|
492
|
+
|
|
493
|
+
:class:`sage.categories.pushout.ConstructionFunctor`.
|
|
494
|
+
"""
|
|
495
|
+
|
|
496
|
+
_functor_name = 'GenericSymbolicSubringFunctor'
|
|
497
|
+
|
|
498
|
+
rank = 11
|
|
499
|
+
|
|
500
|
+
# The symbolic subring construction returns an object admitting a
|
|
501
|
+
# coercion map into the original, not vice versa.
|
|
502
|
+
coercion_reversed = True
|
|
503
|
+
|
|
504
|
+
_repr_type_ = 'generic'
|
|
505
|
+
|
|
506
|
+
def __init__(self, vars):
|
|
507
|
+
r"""
|
|
508
|
+
See :class:`GenericSymbolicSubringFunctor` for details.
|
|
509
|
+
|
|
510
|
+
TESTS::
|
|
511
|
+
|
|
512
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
513
|
+
sage: SymbolicSubring(accepting_variables=('a',)).construction()[0] # indirect doctest
|
|
514
|
+
Subring<accepting a>
|
|
515
|
+
"""
|
|
516
|
+
self.vars = set(vars)
|
|
517
|
+
from sage.categories.rings import Rings
|
|
518
|
+
super().__init__(Rings(), Rings())
|
|
519
|
+
|
|
520
|
+
def _repr_variables_(self):
|
|
521
|
+
r"""
|
|
522
|
+
Return a representation string of the variables.
|
|
523
|
+
|
|
524
|
+
OUTPUT: string
|
|
525
|
+
|
|
526
|
+
TESTS::
|
|
527
|
+
|
|
528
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
529
|
+
sage: F = SymbolicSubring(accepting_variables=('a',)).construction()[0]
|
|
530
|
+
sage: F._repr_variables_()
|
|
531
|
+
'a'
|
|
532
|
+
"""
|
|
533
|
+
return ', '.join(str(v) for v in sorted(self.vars, key=str))
|
|
534
|
+
|
|
535
|
+
def _repr_(self):
|
|
536
|
+
r"""
|
|
537
|
+
Return a representation string of this functor.
|
|
538
|
+
|
|
539
|
+
OUTPUT: string
|
|
540
|
+
|
|
541
|
+
TESTS::
|
|
542
|
+
|
|
543
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
544
|
+
sage: SymbolicSubring(accepting_variables=('a',)) # indirect doctest
|
|
545
|
+
Symbolic Subring accepting the variable a
|
|
546
|
+
sage: SymbolicSubring(rejecting_variables=('r',)) # indirect doctest
|
|
547
|
+
Symbolic Subring rejecting the variable r
|
|
548
|
+
sage: SymbolicSubring(no_variables=True) # indirect doctest
|
|
549
|
+
Symbolic Constants Subring
|
|
550
|
+
"""
|
|
551
|
+
return 'Subring<%s%s%s>' % (
|
|
552
|
+
self._repr_type_, ' ' if self._repr_type_ else '',
|
|
553
|
+
self._repr_variables_() if self.vars else 'no variable')
|
|
554
|
+
|
|
555
|
+
def merge(self, other):
|
|
556
|
+
r"""
|
|
557
|
+
Merge this functor with ``other`` if possible.
|
|
558
|
+
|
|
559
|
+
INPUT:
|
|
560
|
+
|
|
561
|
+
- ``other`` -- a functor
|
|
562
|
+
|
|
563
|
+
OUTPUT: a functor or ``None``
|
|
564
|
+
|
|
565
|
+
EXAMPLES::
|
|
566
|
+
|
|
567
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
568
|
+
sage: F = SymbolicSubring(accepting_variables=('a',)).construction()[0]
|
|
569
|
+
sage: F.merge(F) is F
|
|
570
|
+
True
|
|
571
|
+
"""
|
|
572
|
+
if self == other:
|
|
573
|
+
return self
|
|
574
|
+
|
|
575
|
+
def __eq__(self, other):
|
|
576
|
+
r"""
|
|
577
|
+
Return whether this functor is equal to ``other``.
|
|
578
|
+
|
|
579
|
+
INPUT:
|
|
580
|
+
|
|
581
|
+
- ``other`` -- a functor
|
|
582
|
+
|
|
583
|
+
OUTPUT: boolean
|
|
584
|
+
|
|
585
|
+
EXAMPLES::
|
|
586
|
+
|
|
587
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
588
|
+
sage: F = SymbolicSubring(accepting_variables=('a',)).construction()[0]
|
|
589
|
+
sage: F == F
|
|
590
|
+
True
|
|
591
|
+
"""
|
|
592
|
+
return type(self) is type(other) and self.vars == other.vars
|
|
593
|
+
|
|
594
|
+
def __ne__(self, other):
|
|
595
|
+
r"""
|
|
596
|
+
Return whether this functor is not equal to ``other``.
|
|
597
|
+
|
|
598
|
+
INPUT:
|
|
599
|
+
|
|
600
|
+
- ``other`` -- a functor
|
|
601
|
+
|
|
602
|
+
OUTPUT: boolean
|
|
603
|
+
|
|
604
|
+
EXAMPLES::
|
|
605
|
+
|
|
606
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
607
|
+
sage: F = SymbolicSubring(accepting_variables=('a',)).construction()[0]
|
|
608
|
+
sage: F != F
|
|
609
|
+
False
|
|
610
|
+
"""
|
|
611
|
+
return not self == other
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
class SymbolicSubringAcceptingVars(GenericSymbolicSubring):
|
|
615
|
+
r"""
|
|
616
|
+
The symbolic subring consisting of symbolic expressions in the given variables.
|
|
617
|
+
"""
|
|
618
|
+
|
|
619
|
+
def _repr_(self):
|
|
620
|
+
r"""
|
|
621
|
+
Return a representation string of this symbolic subring.
|
|
622
|
+
|
|
623
|
+
OUTPUT: string
|
|
624
|
+
|
|
625
|
+
TESTS::
|
|
626
|
+
|
|
627
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
628
|
+
sage: SymbolicSubring(accepting_variables=('a',)) # indirect doctest
|
|
629
|
+
Symbolic Subring accepting the variable a
|
|
630
|
+
"""
|
|
631
|
+
return 'Symbolic Subring accepting %s' % \
|
|
632
|
+
(self._repr_variables_())
|
|
633
|
+
|
|
634
|
+
def has_valid_variable(self, variable):
|
|
635
|
+
r"""
|
|
636
|
+
Return whether the given ``variable`` is valid in this subring.
|
|
637
|
+
|
|
638
|
+
INPUT:
|
|
639
|
+
|
|
640
|
+
- ``variable`` -- a symbolic variable
|
|
641
|
+
|
|
642
|
+
OUTPUT: boolean
|
|
643
|
+
|
|
644
|
+
EXAMPLES::
|
|
645
|
+
|
|
646
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
647
|
+
sage: S = SymbolicSubring(accepting_variables=('a',))
|
|
648
|
+
sage: S.has_valid_variable('a')
|
|
649
|
+
True
|
|
650
|
+
sage: S.has_valid_variable('r')
|
|
651
|
+
False
|
|
652
|
+
sage: S.has_valid_variable('x')
|
|
653
|
+
False
|
|
654
|
+
"""
|
|
655
|
+
return SR(variable) in self._vars_
|
|
656
|
+
|
|
657
|
+
def construction(self):
|
|
658
|
+
r"""
|
|
659
|
+
Return the functorial construction of this symbolic subring.
|
|
660
|
+
|
|
661
|
+
OUTPUT:
|
|
662
|
+
|
|
663
|
+
A tuple whose first entry is a construction functor and its second
|
|
664
|
+
is the symbolic ring.
|
|
665
|
+
|
|
666
|
+
EXAMPLES::
|
|
667
|
+
|
|
668
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
669
|
+
sage: SymbolicSubring(accepting_variables=('a',)).construction()
|
|
670
|
+
(Subring<accepting a>, Symbolic Ring)
|
|
671
|
+
"""
|
|
672
|
+
return (SymbolicSubringAcceptingVarsFunctor(self._vars_), SR)
|
|
673
|
+
|
|
674
|
+
def _coerce_map_from_(self, P):
|
|
675
|
+
r"""
|
|
676
|
+
Return whether ``P`` coerces into this symbolic subring.
|
|
677
|
+
|
|
678
|
+
INPUT:
|
|
679
|
+
|
|
680
|
+
- ``P`` -- a parent
|
|
681
|
+
|
|
682
|
+
OUTPUT: boolean or ``None``
|
|
683
|
+
|
|
684
|
+
TESTS::
|
|
685
|
+
|
|
686
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
687
|
+
sage: A = SymbolicSubring(accepting_variables=('a',))
|
|
688
|
+
sage: AB = SymbolicSubring(accepting_variables=('a', 'b'))
|
|
689
|
+
sage: A.has_coerce_map_from(AB) # indirect doctest
|
|
690
|
+
False
|
|
691
|
+
sage: AB.has_coerce_map_from(A) # indirect doctest
|
|
692
|
+
True
|
|
693
|
+
"""
|
|
694
|
+
if isinstance(P, SymbolicSubringAcceptingVars):
|
|
695
|
+
return self._vars_ >= P._vars_
|
|
696
|
+
return super()._coerce_map_from_(P)
|
|
697
|
+
|
|
698
|
+
def _an_element_(self):
|
|
699
|
+
r"""
|
|
700
|
+
Return an element of this symbolic subring.
|
|
701
|
+
|
|
702
|
+
OUTPUT: a symbolic expression
|
|
703
|
+
|
|
704
|
+
TESTS::
|
|
705
|
+
|
|
706
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
707
|
+
sage: SymbolicSubring(accepting_variables=('a',)).an_element()
|
|
708
|
+
a
|
|
709
|
+
sage: _.parent()
|
|
710
|
+
Symbolic Subring accepting the variable a
|
|
711
|
+
"""
|
|
712
|
+
return self(sorted(self._vars_, key=str)[0])
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
class SymbolicSubringAcceptingVarsFunctor(GenericSymbolicSubringFunctor):
|
|
716
|
+
|
|
717
|
+
_functor_name = 'SymbolicSubringAcceptingVarsFunctor'
|
|
718
|
+
|
|
719
|
+
_repr_type_ = 'accepting'
|
|
720
|
+
|
|
721
|
+
def merge(self, other):
|
|
722
|
+
r"""
|
|
723
|
+
Merge this functor with ``other`` if possible.
|
|
724
|
+
|
|
725
|
+
INPUT:
|
|
726
|
+
|
|
727
|
+
- ``other`` -- a functor
|
|
728
|
+
|
|
729
|
+
OUTPUT: a functor or ``None``
|
|
730
|
+
|
|
731
|
+
EXAMPLES::
|
|
732
|
+
|
|
733
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
734
|
+
sage: F = SymbolicSubring(accepting_variables=('a',)).construction()[0]
|
|
735
|
+
sage: G = SymbolicSubring(rejecting_variables=('r',)).construction()[0]
|
|
736
|
+
sage: F.merge(F) is F
|
|
737
|
+
True
|
|
738
|
+
sage: F.merge(G) is G
|
|
739
|
+
True
|
|
740
|
+
"""
|
|
741
|
+
if self == other:
|
|
742
|
+
return self
|
|
743
|
+
elif type(self) is type(other):
|
|
744
|
+
return type(self)(self.vars | other.vars)
|
|
745
|
+
elif isinstance(other, SymbolicSubringRejectingVarsFunctor):
|
|
746
|
+
if not (self.vars & other.vars):
|
|
747
|
+
return other
|
|
748
|
+
|
|
749
|
+
def _apply_functor(self, R):
|
|
750
|
+
"""
|
|
751
|
+
Apply this functor to the given symbolic ring `R`.
|
|
752
|
+
|
|
753
|
+
INPUT:
|
|
754
|
+
|
|
755
|
+
- ``R`` -- a symbolic ring
|
|
756
|
+
|
|
757
|
+
OUTPUT: a subring of ``R``
|
|
758
|
+
|
|
759
|
+
EXAMPLES::
|
|
760
|
+
|
|
761
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
762
|
+
sage: F, R = SymbolicSubring(accepting_variables=('a',)).construction()
|
|
763
|
+
sage: F(R) # indirect doctest
|
|
764
|
+
Symbolic Subring accepting the variable a
|
|
765
|
+
|
|
766
|
+
TESTS::
|
|
767
|
+
|
|
768
|
+
sage: F(F(R))
|
|
769
|
+
Traceback (most recent call last):
|
|
770
|
+
...
|
|
771
|
+
NotImplementedError: This functor can only be applied on the
|
|
772
|
+
symbolic ring but Symbolic Subring accepting the variable a given.
|
|
773
|
+
"""
|
|
774
|
+
if R is not SR:
|
|
775
|
+
raise NotImplementedError('This functor can only be applied on '
|
|
776
|
+
'the symbolic ring but %s given.' % (R,))
|
|
777
|
+
return SymbolicSubring(accepting_variables=self.vars)
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
class SymbolicSubringRejectingVars(GenericSymbolicSubring):
|
|
781
|
+
r"""
|
|
782
|
+
The symbolic subring consisting of symbolic expressions whose variables
|
|
783
|
+
are none of the given variables.
|
|
784
|
+
"""
|
|
785
|
+
|
|
786
|
+
def _repr_(self):
|
|
787
|
+
r"""
|
|
788
|
+
Return a representation string of this symbolic subring.
|
|
789
|
+
|
|
790
|
+
OUTPUT: string
|
|
791
|
+
|
|
792
|
+
TESTS::
|
|
793
|
+
|
|
794
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
795
|
+
sage: SymbolicSubring(rejecting_variables=('r',)) # indirect doctest
|
|
796
|
+
Symbolic Subring rejecting the variable r
|
|
797
|
+
"""
|
|
798
|
+
return 'Symbolic Subring rejecting %s' % \
|
|
799
|
+
(self._repr_variables_())
|
|
800
|
+
|
|
801
|
+
def has_valid_variable(self, variable):
|
|
802
|
+
r"""
|
|
803
|
+
Return whether the given ``variable`` is valid in this subring.
|
|
804
|
+
|
|
805
|
+
INPUT:
|
|
806
|
+
|
|
807
|
+
- ``variable`` -- a symbolic variable
|
|
808
|
+
|
|
809
|
+
OUTPUT: boolean
|
|
810
|
+
|
|
811
|
+
EXAMPLES::
|
|
812
|
+
|
|
813
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
814
|
+
sage: S = SymbolicSubring(rejecting_variables=('r',))
|
|
815
|
+
sage: S.has_valid_variable('a')
|
|
816
|
+
True
|
|
817
|
+
sage: S.has_valid_variable('r')
|
|
818
|
+
False
|
|
819
|
+
sage: S.has_valid_variable('x')
|
|
820
|
+
True
|
|
821
|
+
"""
|
|
822
|
+
return SR(variable) not in self._vars_
|
|
823
|
+
|
|
824
|
+
def construction(self):
|
|
825
|
+
r"""
|
|
826
|
+
Return the functorial construction of this symbolic subring.
|
|
827
|
+
|
|
828
|
+
OUTPUT:
|
|
829
|
+
|
|
830
|
+
A tuple whose first entry is a construction functor and its second
|
|
831
|
+
is the symbolic ring.
|
|
832
|
+
|
|
833
|
+
EXAMPLES::
|
|
834
|
+
|
|
835
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
836
|
+
sage: SymbolicSubring(rejecting_variables=('r',)).construction()
|
|
837
|
+
(Subring<rejecting r>, Symbolic Ring)
|
|
838
|
+
"""
|
|
839
|
+
return (SymbolicSubringRejectingVarsFunctor(self._vars_), SR)
|
|
840
|
+
|
|
841
|
+
def _coerce_map_from_(self, P):
|
|
842
|
+
r"""
|
|
843
|
+
Return whether ``P`` coerces into this symbolic subring.
|
|
844
|
+
|
|
845
|
+
INPUT:
|
|
846
|
+
|
|
847
|
+
- ``P`` -- a parent
|
|
848
|
+
|
|
849
|
+
OUTPUT: boolean or ``None``
|
|
850
|
+
|
|
851
|
+
TESTS::
|
|
852
|
+
|
|
853
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
854
|
+
sage: R = SymbolicSubring(rejecting_variables=('r',))
|
|
855
|
+
sage: RS = SymbolicSubring(rejecting_variables=('r', 's'))
|
|
856
|
+
sage: RS.has_coerce_map_from(R) # indirect doctest
|
|
857
|
+
False
|
|
858
|
+
sage: R.has_coerce_map_from(RS) # indirect doctest
|
|
859
|
+
True
|
|
860
|
+
sage: A = SymbolicSubring(accepting_variables=('a',))
|
|
861
|
+
sage: R.has_coerce_map_from(A)
|
|
862
|
+
True
|
|
863
|
+
sage: A.has_coerce_map_from(R)
|
|
864
|
+
False
|
|
865
|
+
"""
|
|
866
|
+
if isinstance(P, SymbolicSubringRejectingVars):
|
|
867
|
+
return self._vars_ <= P._vars_
|
|
868
|
+
elif isinstance(P, SymbolicSubringAcceptingVars):
|
|
869
|
+
return not (self._vars_ & P._vars_)
|
|
870
|
+
return super()._coerce_map_from_(P)
|
|
871
|
+
|
|
872
|
+
def _an_element_(self):
|
|
873
|
+
r"""
|
|
874
|
+
Return an element of this symbolic subring.
|
|
875
|
+
|
|
876
|
+
OUTPUT: a symbolic expression
|
|
877
|
+
|
|
878
|
+
TESTS::
|
|
879
|
+
|
|
880
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
881
|
+
sage: SymbolicSubring(rejecting_variables=('r',)).an_element()
|
|
882
|
+
some_variable
|
|
883
|
+
sage: _.parent()
|
|
884
|
+
Symbolic Subring rejecting the variable r
|
|
885
|
+
sage: SymbolicSubring(rejecting_variables=('some_variable',)).an_element()
|
|
886
|
+
some_some_variable
|
|
887
|
+
sage: _.parent()
|
|
888
|
+
Symbolic Subring rejecting the variable some_variable
|
|
889
|
+
sage: SymbolicSubring(rejecting_variables=('some_some_variable',)).an_element()
|
|
890
|
+
some_variable
|
|
891
|
+
sage: _.parent()
|
|
892
|
+
Symbolic Subring rejecting the variable some_some_variable
|
|
893
|
+
sage: SymbolicSubring(rejecting_variables=('some_variable','some_some_variable')).an_element()
|
|
894
|
+
some_some_some_variable
|
|
895
|
+
sage: _.parent()
|
|
896
|
+
Symbolic Subring rejecting the variables some_some_variable, some_variable
|
|
897
|
+
"""
|
|
898
|
+
v = SR.an_element()
|
|
899
|
+
while not self.has_valid_variable(v):
|
|
900
|
+
v = SR('some_' + str(v))
|
|
901
|
+
return self(v)
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
class SymbolicSubringRejectingVarsFunctor(GenericSymbolicSubringFunctor):
|
|
905
|
+
|
|
906
|
+
_functor_name = 'SymbolicSubringRejectingVarsFunctor'
|
|
907
|
+
|
|
908
|
+
_repr_type_ = 'rejecting'
|
|
909
|
+
|
|
910
|
+
def merge(self, other):
|
|
911
|
+
r"""
|
|
912
|
+
Merge this functor with ``other`` if possible.
|
|
913
|
+
|
|
914
|
+
INPUT:
|
|
915
|
+
|
|
916
|
+
- ``other`` -- a functor
|
|
917
|
+
|
|
918
|
+
OUTPUT: a functor or ``None``
|
|
919
|
+
|
|
920
|
+
EXAMPLES::
|
|
921
|
+
|
|
922
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
923
|
+
sage: F = SymbolicSubring(accepting_variables=('a',)).construction()[0]
|
|
924
|
+
sage: G = SymbolicSubring(rejecting_variables=('r',)).construction()[0]
|
|
925
|
+
sage: G.merge(G) is G
|
|
926
|
+
True
|
|
927
|
+
sage: G.merge(F) is G
|
|
928
|
+
True
|
|
929
|
+
"""
|
|
930
|
+
if self == other:
|
|
931
|
+
return self
|
|
932
|
+
elif type(self) is type(other):
|
|
933
|
+
return type(self)(self.vars & other.vars)
|
|
934
|
+
elif isinstance(other, SymbolicSubringAcceptingVarsFunctor):
|
|
935
|
+
if not (self.vars & other.vars):
|
|
936
|
+
return self
|
|
937
|
+
|
|
938
|
+
def _apply_functor(self, R):
|
|
939
|
+
"""
|
|
940
|
+
Apply this functor to the given symbolic ring `R`.
|
|
941
|
+
|
|
942
|
+
INPUT:
|
|
943
|
+
|
|
944
|
+
- ``R`` -- a symbolic ring
|
|
945
|
+
|
|
946
|
+
OUTPUT: a subring of ``R``
|
|
947
|
+
|
|
948
|
+
EXAMPLES::
|
|
949
|
+
|
|
950
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
951
|
+
sage: F, R = SymbolicSubring(rejecting_variables=('r',)).construction()
|
|
952
|
+
sage: F(R) # indirect doctest
|
|
953
|
+
Symbolic Subring rejecting the variable r
|
|
954
|
+
|
|
955
|
+
TESTS::
|
|
956
|
+
|
|
957
|
+
sage: F(F(R))
|
|
958
|
+
Traceback (most recent call last):
|
|
959
|
+
...
|
|
960
|
+
NotImplementedError: This functor can only be applied on the
|
|
961
|
+
symbolic ring but Symbolic Subring rejecting the variable r given.
|
|
962
|
+
"""
|
|
963
|
+
if R is not SR:
|
|
964
|
+
raise NotImplementedError('This functor can only be applied on '
|
|
965
|
+
'the symbolic ring but %s given.' % (R,))
|
|
966
|
+
return SymbolicSubring(rejecting_variables=self.vars)
|
|
967
|
+
|
|
968
|
+
|
|
969
|
+
class SymbolicConstantsSubring(SymbolicSubringAcceptingVars):
|
|
970
|
+
r"""
|
|
971
|
+
The symbolic subring consisting of symbolic constants.
|
|
972
|
+
"""
|
|
973
|
+
|
|
974
|
+
def _repr_(self):
|
|
975
|
+
r"""
|
|
976
|
+
Return a representation string of this symbolic subring.
|
|
977
|
+
|
|
978
|
+
OUTPUT: string
|
|
979
|
+
|
|
980
|
+
TESTS::
|
|
981
|
+
|
|
982
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
983
|
+
sage: SymbolicSubring(no_variables=True) # indirect doctest
|
|
984
|
+
Symbolic Constants Subring
|
|
985
|
+
"""
|
|
986
|
+
return 'Symbolic Constants Subring'
|
|
987
|
+
|
|
988
|
+
def has_valid_variable(self, variable):
|
|
989
|
+
r"""
|
|
990
|
+
Return whether the given ``variable`` is valid in this subring.
|
|
991
|
+
|
|
992
|
+
INPUT:
|
|
993
|
+
|
|
994
|
+
- ``variable`` -- a symbolic variable
|
|
995
|
+
|
|
996
|
+
OUTPUT: boolean
|
|
997
|
+
|
|
998
|
+
EXAMPLES::
|
|
999
|
+
|
|
1000
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
1001
|
+
sage: S = SymbolicSubring(no_variables=True)
|
|
1002
|
+
sage: S.has_valid_variable('a')
|
|
1003
|
+
False
|
|
1004
|
+
sage: S.has_valid_variable('r')
|
|
1005
|
+
False
|
|
1006
|
+
sage: S.has_valid_variable('x')
|
|
1007
|
+
False
|
|
1008
|
+
"""
|
|
1009
|
+
return False
|
|
1010
|
+
|
|
1011
|
+
def _an_element_(self):
|
|
1012
|
+
r"""
|
|
1013
|
+
Return an element of this symbolic subring.
|
|
1014
|
+
|
|
1015
|
+
OUTPUT: a symbolic expression
|
|
1016
|
+
|
|
1017
|
+
TESTS::
|
|
1018
|
+
|
|
1019
|
+
sage: from sage.symbolic.subring import SymbolicSubring
|
|
1020
|
+
sage: SymbolicSubring(no_variables=True).an_element()
|
|
1021
|
+
I*pi*e
|
|
1022
|
+
sage: _.parent()
|
|
1023
|
+
Symbolic Constants Subring
|
|
1024
|
+
"""
|
|
1025
|
+
return self(SR('I') * SR('pi') * SR('e'))
|