passagemath-symbolics 10.8.1a1__cp314-cp314t-musllinux_1_2_aarch64.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.
Files changed (181) hide show
  1. passagemath_symbolics/__init__.py +3 -0
  2. passagemath_symbolics-10.8.1a1.dist-info/METADATA +186 -0
  3. passagemath_symbolics-10.8.1a1.dist-info/RECORD +181 -0
  4. passagemath_symbolics-10.8.1a1.dist-info/WHEEL +5 -0
  5. passagemath_symbolics-10.8.1a1.dist-info/top_level.txt +3 -0
  6. sage/all__sagemath_symbolics.py +17 -0
  7. sage/calculus/all.py +14 -0
  8. sage/calculus/calculus.py +2838 -0
  9. sage/calculus/desolvers.py +1864 -0
  10. sage/calculus/predefined.py +51 -0
  11. sage/calculus/tests.py +225 -0
  12. sage/calculus/var.cpython-314t-aarch64-linux-musl.so +0 -0
  13. sage/calculus/var.pyx +401 -0
  14. sage/dynamics/all__sagemath_symbolics.py +6 -0
  15. sage/dynamics/complex_dynamics/all.py +5 -0
  16. sage/dynamics/complex_dynamics/mandel_julia.py +765 -0
  17. sage/dynamics/complex_dynamics/mandel_julia_helper.cpython-314t-aarch64-linux-musl.so +0 -0
  18. sage/dynamics/complex_dynamics/mandel_julia_helper.pyx +1034 -0
  19. sage/ext/all__sagemath_symbolics.py +1 -0
  20. sage/ext_data/kenzo/CP2.txt +45 -0
  21. sage/ext_data/kenzo/CP3.txt +349 -0
  22. sage/ext_data/kenzo/CP4.txt +4774 -0
  23. sage/ext_data/kenzo/README.txt +49 -0
  24. sage/ext_data/kenzo/S4.txt +20 -0
  25. sage/ext_data/magma/latex/latex.m +1021 -0
  26. sage/ext_data/magma/latex/latex.spec +1 -0
  27. sage/ext_data/magma/sage/basic.m +356 -0
  28. sage/ext_data/magma/sage/sage.spec +1 -0
  29. sage/ext_data/magma/spec +9 -0
  30. sage/geometry/all__sagemath_symbolics.py +8 -0
  31. sage/geometry/hyperbolic_space/all.py +5 -0
  32. sage/geometry/hyperbolic_space/hyperbolic_coercion.py +755 -0
  33. sage/geometry/hyperbolic_space/hyperbolic_constants.py +5 -0
  34. sage/geometry/hyperbolic_space/hyperbolic_geodesic.py +2419 -0
  35. sage/geometry/hyperbolic_space/hyperbolic_interface.py +206 -0
  36. sage/geometry/hyperbolic_space/hyperbolic_isometry.py +1083 -0
  37. sage/geometry/hyperbolic_space/hyperbolic_model.py +1502 -0
  38. sage/geometry/hyperbolic_space/hyperbolic_point.py +621 -0
  39. sage/geometry/riemannian_manifolds/all.py +7 -0
  40. sage/geometry/riemannian_manifolds/parametrized_surface3d.py +1632 -0
  41. sage/geometry/riemannian_manifolds/surface3d_generators.py +461 -0
  42. sage/interfaces/all__sagemath_symbolics.py +1 -0
  43. sage/interfaces/magma.py +2991 -0
  44. sage/interfaces/magma_free.py +90 -0
  45. sage/interfaces/maple.py +1402 -0
  46. sage/interfaces/mathematica.py +1345 -0
  47. sage/interfaces/mathics.py +1312 -0
  48. sage/interfaces/sympy.py +1398 -0
  49. sage/interfaces/sympy_wrapper.py +197 -0
  50. sage/interfaces/tides.py +938 -0
  51. sage/libs/all__sagemath_symbolics.py +6 -0
  52. sage/manifolds/all.py +7 -0
  53. sage/manifolds/calculus_method.py +553 -0
  54. sage/manifolds/catalog.py +437 -0
  55. sage/manifolds/chart.py +4010 -0
  56. sage/manifolds/chart_func.py +3416 -0
  57. sage/manifolds/continuous_map.py +2183 -0
  58. sage/manifolds/continuous_map_image.py +155 -0
  59. sage/manifolds/differentiable/affine_connection.py +2475 -0
  60. sage/manifolds/differentiable/all.py +1 -0
  61. sage/manifolds/differentiable/automorphismfield.py +1383 -0
  62. sage/manifolds/differentiable/automorphismfield_group.py +604 -0
  63. sage/manifolds/differentiable/bundle_connection.py +1445 -0
  64. sage/manifolds/differentiable/characteristic_cohomology_class.py +1840 -0
  65. sage/manifolds/differentiable/chart.py +1241 -0
  66. sage/manifolds/differentiable/curve.py +1028 -0
  67. sage/manifolds/differentiable/de_rham_cohomology.py +541 -0
  68. sage/manifolds/differentiable/degenerate.py +559 -0
  69. sage/manifolds/differentiable/degenerate_submanifold.py +1668 -0
  70. sage/manifolds/differentiable/diff_form.py +1660 -0
  71. sage/manifolds/differentiable/diff_form_module.py +1062 -0
  72. sage/manifolds/differentiable/diff_map.py +1315 -0
  73. sage/manifolds/differentiable/differentiable_submanifold.py +291 -0
  74. sage/manifolds/differentiable/examples/all.py +1 -0
  75. sage/manifolds/differentiable/examples/euclidean.py +2517 -0
  76. sage/manifolds/differentiable/examples/real_line.py +897 -0
  77. sage/manifolds/differentiable/examples/sphere.py +1186 -0
  78. sage/manifolds/differentiable/examples/symplectic_space.py +187 -0
  79. sage/manifolds/differentiable/examples/symplectic_space_test.py +40 -0
  80. sage/manifolds/differentiable/integrated_curve.py +4035 -0
  81. sage/manifolds/differentiable/levi_civita_connection.py +841 -0
  82. sage/manifolds/differentiable/manifold.py +4254 -0
  83. sage/manifolds/differentiable/manifold_homset.py +1826 -0
  84. sage/manifolds/differentiable/metric.py +3032 -0
  85. sage/manifolds/differentiable/mixed_form.py +1507 -0
  86. sage/manifolds/differentiable/mixed_form_algebra.py +559 -0
  87. sage/manifolds/differentiable/multivector_module.py +800 -0
  88. sage/manifolds/differentiable/multivectorfield.py +1522 -0
  89. sage/manifolds/differentiable/poisson_tensor.py +268 -0
  90. sage/manifolds/differentiable/pseudo_riemannian.py +755 -0
  91. sage/manifolds/differentiable/pseudo_riemannian_submanifold.py +1839 -0
  92. sage/manifolds/differentiable/scalarfield.py +1343 -0
  93. sage/manifolds/differentiable/scalarfield_algebra.py +472 -0
  94. sage/manifolds/differentiable/symplectic_form.py +912 -0
  95. sage/manifolds/differentiable/symplectic_form_test.py +220 -0
  96. sage/manifolds/differentiable/tangent_space.py +412 -0
  97. sage/manifolds/differentiable/tangent_vector.py +616 -0
  98. sage/manifolds/differentiable/tensorfield.py +4665 -0
  99. sage/manifolds/differentiable/tensorfield_module.py +963 -0
  100. sage/manifolds/differentiable/tensorfield_paral.py +2450 -0
  101. sage/manifolds/differentiable/tensorfield_paral_test.py +16 -0
  102. sage/manifolds/differentiable/vector_bundle.py +1725 -0
  103. sage/manifolds/differentiable/vectorfield.py +1717 -0
  104. sage/manifolds/differentiable/vectorfield_module.py +2445 -0
  105. sage/manifolds/differentiable/vectorframe.py +1832 -0
  106. sage/manifolds/family.py +270 -0
  107. sage/manifolds/local_frame.py +1490 -0
  108. sage/manifolds/manifold.py +3090 -0
  109. sage/manifolds/manifold_homset.py +452 -0
  110. sage/manifolds/operators.py +359 -0
  111. sage/manifolds/point.py +994 -0
  112. sage/manifolds/scalarfield.py +3718 -0
  113. sage/manifolds/scalarfield_algebra.py +629 -0
  114. sage/manifolds/section.py +3111 -0
  115. sage/manifolds/section_module.py +831 -0
  116. sage/manifolds/structure.py +229 -0
  117. sage/manifolds/subset.py +2721 -0
  118. sage/manifolds/subsets/all.py +1 -0
  119. sage/manifolds/subsets/closure.py +131 -0
  120. sage/manifolds/subsets/pullback.py +883 -0
  121. sage/manifolds/topological_submanifold.py +891 -0
  122. sage/manifolds/trivialization.py +733 -0
  123. sage/manifolds/utilities.py +1348 -0
  124. sage/manifolds/vector_bundle.py +1347 -0
  125. sage/manifolds/vector_bundle_fiber.py +332 -0
  126. sage/manifolds/vector_bundle_fiber_element.py +111 -0
  127. sage/matrix/all__sagemath_symbolics.py +1 -0
  128. sage/matrix/matrix_symbolic_dense.cpython-314t-aarch64-linux-musl.so +0 -0
  129. sage/matrix/matrix_symbolic_dense.pxd +6 -0
  130. sage/matrix/matrix_symbolic_dense.pyx +1030 -0
  131. sage/matrix/matrix_symbolic_sparse.cpython-314t-aarch64-linux-musl.so +0 -0
  132. sage/matrix/matrix_symbolic_sparse.pxd +6 -0
  133. sage/matrix/matrix_symbolic_sparse.pyx +1038 -0
  134. sage/modules/all__sagemath_symbolics.py +1 -0
  135. sage/modules/vector_callable_symbolic_dense.py +105 -0
  136. sage/modules/vector_symbolic_dense.py +116 -0
  137. sage/modules/vector_symbolic_sparse.py +118 -0
  138. sage/rings/all__sagemath_symbolics.py +4 -0
  139. sage/rings/asymptotic/all.py +6 -0
  140. sage/rings/asymptotic/asymptotic_expansion_generators.py +1485 -0
  141. sage/rings/asymptotic/asymptotic_ring.py +4858 -0
  142. sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py +4106 -0
  143. sage/rings/asymptotic/growth_group.py +5373 -0
  144. sage/rings/asymptotic/growth_group_cartesian.py +1400 -0
  145. sage/rings/asymptotic/term_monoid.py +5205 -0
  146. sage/rings/function_field/all__sagemath_symbolics.py +2 -0
  147. sage/rings/polynomial/all__sagemath_symbolics.py +1 -0
  148. sage/symbolic/all.py +15 -0
  149. sage/symbolic/assumptions.py +987 -0
  150. sage/symbolic/benchmark.py +93 -0
  151. sage/symbolic/callable.py +456 -0
  152. sage/symbolic/callable.pyi +66 -0
  153. sage/symbolic/comparison_impl.pyi +38 -0
  154. sage/symbolic/complexity_measures.py +35 -0
  155. sage/symbolic/constants.py +1286 -0
  156. sage/symbolic/constants_c_impl.pyi +10 -0
  157. sage/symbolic/expression_conversion_algebraic.py +310 -0
  158. sage/symbolic/expression_conversion_sympy.py +317 -0
  159. sage/symbolic/expression_conversions.py +1727 -0
  160. sage/symbolic/function_factory.py +355 -0
  161. sage/symbolic/function_factory.pyi +41 -0
  162. sage/symbolic/getitem_impl.pyi +24 -0
  163. sage/symbolic/integration/all.py +1 -0
  164. sage/symbolic/integration/external.py +271 -0
  165. sage/symbolic/integration/integral.py +1075 -0
  166. sage/symbolic/maxima_wrapper.py +162 -0
  167. sage/symbolic/operators.py +267 -0
  168. sage/symbolic/operators.pyi +61 -0
  169. sage/symbolic/pynac_constant_impl.pyi +13 -0
  170. sage/symbolic/pynac_function_impl.pyi +8 -0
  171. sage/symbolic/random_tests.py +461 -0
  172. sage/symbolic/relation.py +2062 -0
  173. sage/symbolic/ring.cpython-314t-aarch64-linux-musl.so +0 -0
  174. sage/symbolic/ring.pxd +5 -0
  175. sage/symbolic/ring.pyi +110 -0
  176. sage/symbolic/ring.pyx +1393 -0
  177. sage/symbolic/series_impl.pyi +10 -0
  178. sage/symbolic/subring.py +1025 -0
  179. sage/symbolic/symengine.py +19 -0
  180. sage/symbolic/tests.py +40 -0
  181. sage/symbolic/units.py +1468 -0
@@ -0,0 +1,93 @@
1
+ # sage_setup: distribution = sagemath-symbolics
2
+ r"""
3
+ Benchmarks
4
+
5
+ Tests that will take a long time if something is wrong, but be very
6
+ quick otherwise. See https://wiki.sagemath.org/symbench. The
7
+ parameters chosen below are such that with pynac most of these take
8
+ well less than a second, but would not even be feasible using Sage's
9
+ Maxima-based symbolics.
10
+
11
+ Problem R1
12
+
13
+ Important note. Below we do s.expand().real() because s.real() takes forever (TODO?). ::
14
+
15
+ sage: f(z) = sqrt(1/3)*z^2 + i/3
16
+ sage: s = f(f(f(f(f(f(f(f(f(f(i/2))))))))))
17
+ sage: s.expand().real()
18
+ -15323490199844318074242473679071410934833494247466385771803570370858961112774390851798166656796902695599442662754502211584226105508648298600018090510170430216881977761279503642801008178271982531042720727178135881702924595044672634313417239327304576652633321095875724771887486594852083526001648217317718794685379391946143663292907934545842931411982264788766619812559999515408813796287448784343854980686798782575952258163992236113752353237705088451481168691158059505161807961082162315225057299394348203539002582692884735745377391416638540520323363224931163680324690025802009761307137504963304640835891588925883135078996398616361571065941964628043214890356454145039464055430143/160959987592246947739944859375773744043416001841910423046466880402863187009126824419781711398533250016237703449459397319370100476216445123130147322940019839927628599479294678599689928643570237983736966305423831947366332466878486992676823215303312139985015592974537721140932243906832125049776934072927576666849331956351862828567668505777388133331284248870175178634054430823171923639987569211668426477739974572402853248951261366399284257908177157179099041115431335587887276292978004143353025122721401971549897673882099546646236790739903146970578001092018346524464799146331225822142880459202800229013082033028722077703362360159827236163041299500992177627657014103138377287073792*sqrt(1/3)
19
+
20
+
21
+ Problem R2::
22
+
23
+ sage: def hermite(n, y):
24
+ ....: if n == 1: return 2*y
25
+ ....: if n == 0: return 1
26
+ ....: return expand(2*y*hermite(n-1,y) - 2*(n-1)*hermite(n-2,y))
27
+ sage: hermite(15,var('y'))
28
+ 32768*y^15 - 1720320*y^13 + 33546240*y^11 - 307507200*y^9 + 1383782400*y^7 - 2905943040*y^5 + 2421619200*y^3 - 518918400*y
29
+
30
+ Problem R3::
31
+
32
+ sage: f = sum(var('x,y,z')); a = [bool(f==f) for _ in range(100000)]
33
+
34
+ Problem R4::
35
+
36
+ sage: u = [e,pi,sqrt(2)]; Tuples(u,3).cardinality()
37
+ 27
38
+
39
+ Problem R5::
40
+
41
+ sage: def blowup(L, n):
42
+ ....: for i in [0..n]:
43
+ ....: L.append( (L[i] + L[i+1]) * L[i+2] )
44
+ sage: L = list(var('x,y,z'))
45
+ sage: blowup(L,15)
46
+ sage: len(set(L))
47
+ 19
48
+
49
+ Problem R6::
50
+
51
+ sage: sum(((x+sin(i))/x+(x-sin(i))/x) for i in range(100)).expand()
52
+ 200
53
+
54
+ Problem R7::
55
+
56
+ sage: f = x^24+34*x^12+45*x^3+9*x^18 +34*x^10+ 32*x^21
57
+ sage: a = [f(x=random()) for _ in range(10^4)]
58
+
59
+ Problem R10::
60
+
61
+ sage: v = [float(z) for z in [-pi,-pi+1/100..,pi]]
62
+
63
+ Problem R11::
64
+
65
+ sage: a = [random() + random()*I for w in [0..100]]
66
+ sage: a.sort()
67
+
68
+ Problem W3::
69
+
70
+ sage: acos(cos(x))
71
+ arccos(cos(x))
72
+
73
+ PROBLEM S1::
74
+
75
+ sage: _ = var('x,y,z')
76
+ sage: f = (x+y+z+1)^10
77
+ sage: g = expand(f*(f+1))
78
+
79
+ PROBLEM S2::
80
+
81
+ sage: _ = var('x,y')
82
+ sage: a = expand((x^sin(x) + y^cos(y) - z^(x+y))^100)
83
+
84
+ PROBLEM S3::
85
+
86
+ sage: _ = var('x,y,z')
87
+ sage: f = expand((x^y + y^z + z^x)^50)
88
+ sage: g = f.diff(x)
89
+
90
+ PROBLEM S4::
91
+
92
+ sage: w = (sin(x)*cos(x)).series(x,400)
93
+ """
@@ -0,0 +1,456 @@
1
+ # sage_setup: distribution = sagemath-symbolics
2
+ """
3
+ Callable Symbolic Expressions
4
+
5
+ EXAMPLES:
6
+
7
+ When you do arithmetic with::
8
+
9
+ sage: f(x, y, z) = sin(x+y+z)
10
+ sage: g(x, y) = y + 2*x
11
+ sage: f + g
12
+ (x, y, z) |--> 2*x + y + sin(x + y + z)
13
+
14
+ ::
15
+
16
+ sage: f(x, y, z) = sin(x+y+z)
17
+ sage: g(w, t) = cos(w - t)
18
+ sage: f + g
19
+ (t, w, x, y, z) |--> cos(-t + w) + sin(x + y + z)
20
+
21
+ ::
22
+
23
+ sage: f(x, y, t) = y*(x^2-t)
24
+ sage: g(x, y, w) = x + y - cos(w)
25
+ sage: f*g
26
+ (x, y, t, w) |--> (x^2 - t)*(x + y - cos(w))*y
27
+
28
+ ::
29
+
30
+ sage: f(x,y, t) = x+y
31
+ sage: g(x, y, w) = w + t
32
+ sage: f + g
33
+ (x, y, t, w) |--> t + w + x + y
34
+
35
+ TESTS:
36
+
37
+ The arguments in the definition must be symbolic variables (:issue:`10747`)::
38
+
39
+ sage: f(1)=2
40
+ Traceback (most recent call last):
41
+ ...
42
+ SyntaxError: can...t assign to function call...
43
+
44
+ sage: f(x,1)=2
45
+ Traceback (most recent call last):
46
+ ...
47
+ SyntaxError: can...t assign to function call...
48
+
49
+ sage: f(1,2)=3
50
+ Traceback (most recent call last):
51
+ ...
52
+ SyntaxError: can...t assign to function call...
53
+
54
+ sage: f(1,2)=x
55
+ Traceback (most recent call last):
56
+ ...
57
+ SyntaxError: can...t assign to function call...
58
+
59
+ sage: f(x,2)=x
60
+ Traceback (most recent call last):
61
+ ...
62
+ SyntaxError: can...t assign to function call...
63
+ """
64
+ import sage.rings.abc
65
+ from sage.symbolic.ring import SymbolicRing, SR
66
+ from sage.categories.pushout import ConstructionFunctor
67
+ from sage.structure.factory import UniqueFactory
68
+
69
+
70
+ ######################################################################
71
+ # Callable functions
72
+ ######################################################################
73
+
74
+ class CallableSymbolicExpressionFunctor(ConstructionFunctor):
75
+ def __init__(self, arguments):
76
+ """
77
+ A functor which produces a CallableSymbolicExpressionRing from
78
+ the SymbolicRing.
79
+
80
+ EXAMPLES::
81
+
82
+ sage: from sage.symbolic.callable import CallableSymbolicExpressionFunctor
83
+ sage: x,y = var('x,y')
84
+ sage: f = CallableSymbolicExpressionFunctor((x,y)); f
85
+ CallableSymbolicExpressionFunctor(x, y)
86
+ sage: f(SR)
87
+ Callable function ring with arguments (x, y)
88
+
89
+ sage: loads(dumps(f))
90
+ CallableSymbolicExpressionFunctor(x, y)
91
+ """
92
+ self._arguments = arguments
93
+ from sage.categories.rings import Rings
94
+ self.rank = 3
95
+ ConstructionFunctor.__init__(self, Rings(), Rings())
96
+
97
+ def __repr__(self):
98
+ """
99
+ EXAMPLES::
100
+
101
+ sage: from sage.symbolic.callable import CallableSymbolicExpressionFunctor
102
+ sage: x,y = var('x,y')
103
+ sage: CallableSymbolicExpressionFunctor((x,y))
104
+ CallableSymbolicExpressionFunctor(x, y)
105
+ """
106
+ return "CallableSymbolicExpressionFunctor%s" % repr(self.arguments())
107
+
108
+ def merge(self, other):
109
+ """
110
+ EXAMPLES::
111
+
112
+ sage: from sage.symbolic.callable import CallableSymbolicExpressionFunctor
113
+ sage: x,y = var('x,y')
114
+ sage: a = CallableSymbolicExpressionFunctor((x,))
115
+ sage: b = CallableSymbolicExpressionFunctor((y,))
116
+ sage: a.merge(b)
117
+ CallableSymbolicExpressionFunctor(x, y)
118
+ """
119
+ arguments = self.unify_arguments(other)
120
+ return CallableSymbolicExpressionFunctor(arguments)
121
+
122
+ def __call__(self, R):
123
+ """
124
+ EXAMPLES::
125
+
126
+ sage: from sage.symbolic.callable import CallableSymbolicExpressionFunctor
127
+ sage: x,y = var('x,y')
128
+ sage: a = CallableSymbolicExpressionFunctor((x,y))
129
+ sage: a(SR)
130
+ Callable function ring with arguments (x, y)
131
+ """
132
+ if R is not SR:
133
+ raise ValueError("can only make callable symbolic expression rings from the Symbolic Ring")
134
+ return CallableSymbolicExpressionRing(self.arguments())
135
+
136
+ def arguments(self):
137
+ """
138
+ EXAMPLES::
139
+
140
+ sage: from sage.symbolic.callable import CallableSymbolicExpressionFunctor
141
+ sage: x,y = var('x,y')
142
+ sage: a = CallableSymbolicExpressionFunctor((x,y))
143
+ sage: a.arguments()
144
+ (x, y)
145
+ """
146
+ return self._arguments
147
+
148
+ def unify_arguments(self, x):
149
+ r"""
150
+ Take the variable list from another ``CallableSymbolicExpression``
151
+ object and compare it with the current ``CallableSymbolicExpression``
152
+ object's variable list, combining them according to the following rules:
153
+
154
+ Let ``a`` be ``self``'s variable list, let ``b`` be ``y``'s
155
+ variable list.
156
+
157
+ #. If ``a == b``, then the variable lists are
158
+ identical, so return that variable list.
159
+
160
+ #. If ``a`` `\neq` ``b``, then check if the first `n` items in
161
+ ``a`` are the first `n` items in ``b``, or vice versa. If
162
+ so, return a list with these `n` items, followed by the
163
+ remaining items in ``a`` and ``b`` sorted together in
164
+ alphabetical order.
165
+
166
+
167
+ .. NOTE::
168
+
169
+ When used for arithmetic between
170
+ ``CallableSymbolicExpression``'s, these rules ensure that
171
+ the set of ``CallableSymbolicExpression``'s will have
172
+ certain properties. In particular, it ensures that the set
173
+ is a *commutative* ring, i.e., the order of the input
174
+ variables is the same no matter in which order arithmetic
175
+ is done.
176
+
177
+ INPUT:
178
+
179
+ - ``x`` -- a ``CallableSymbolicExpression``
180
+
181
+ OUTPUT: a tuple of variables
182
+
183
+ EXAMPLES::
184
+
185
+ sage: from sage.symbolic.callable import CallableSymbolicExpressionFunctor
186
+ sage: x,y = var('x,y')
187
+ sage: a = CallableSymbolicExpressionFunctor((x,))
188
+ sage: b = CallableSymbolicExpressionFunctor((y,))
189
+ sage: a.unify_arguments(b)
190
+ (x, y)
191
+
192
+ AUTHORS:
193
+
194
+ - Bobby Moretti: thanks to William Stein for the rules
195
+ """
196
+ a = self.arguments()
197
+ b = x.arguments()
198
+
199
+ # Rule #1
200
+ if [str(y) for y in a] == [str(z) for z in b]:
201
+ return a
202
+
203
+ # Rule #2
204
+ new_list = []
205
+ done = False
206
+ i = 0
207
+ while not done and i < min(len(a), len(b)):
208
+ if repr(a[i]) == repr(b[i]):
209
+ new_list.append(a[i])
210
+ i += 1
211
+ else:
212
+ done = True
213
+
214
+ temp = set()
215
+ # Sorting remaining variables.
216
+ for j in range(i, len(a)):
217
+ if a[j] not in temp:
218
+ temp.add(a[j])
219
+
220
+ for j in range(i, len(b)):
221
+ if b[j] not in temp:
222
+ temp.add(b[j])
223
+
224
+ new_list.extend(sorted(temp, key=repr))
225
+ return tuple(new_list)
226
+
227
+
228
+ class CallableSymbolicExpressionRing_class(SymbolicRing, sage.rings.abc.CallableSymbolicExpressionRing):
229
+ def __init__(self, arguments):
230
+ """
231
+ EXAMPLES:
232
+
233
+ We verify that coercion works in the case where ``x`` is not an
234
+ instance of SymbolicExpression, but its parent is still the
235
+ SymbolicRing::
236
+
237
+ sage: f(x) = 1
238
+ sage: f*e
239
+ x |--> e
240
+
241
+ TESTS::
242
+
243
+ sage: TestSuite(f.parent()).run(skip=['_test_divides'])
244
+ """
245
+ self._arguments = arguments
246
+ SymbolicRing.__init__(self, SR)
247
+ self._populate_coercion_lists_(coerce_list=[SR])
248
+ self.symbols = SR.symbols # Use the same list of symbols as SR
249
+
250
+ def _coerce_map_from_(self, R):
251
+ """
252
+ EXAMPLES::
253
+
254
+ sage: f(x,y) = x^2 + y
255
+ sage: g(x,y,z) = x + y + z
256
+ sage: f.parent().has_coerce_map_from(g.parent())
257
+ False
258
+ sage: g.parent().has_coerce_map_from(f.parent())
259
+ True
260
+ """
261
+ if isinstance(R, CallableSymbolicExpressionRing_class):
262
+ args = self.arguments()
263
+ return all(a in args for a in R.arguments())
264
+ return SymbolicRing._coerce_map_from_(self, R)
265
+
266
+ def construction(self):
267
+ """
268
+ EXAMPLES::
269
+
270
+ sage: f(x,y) = x^2 + y
271
+ sage: f.parent().construction()
272
+ (CallableSymbolicExpressionFunctor(x, y), Symbolic Ring)
273
+ """
274
+ return (CallableSymbolicExpressionFunctor(self.arguments()), SR)
275
+
276
+ def _element_constructor_(self, x):
277
+ """
278
+ TESTS::
279
+
280
+ sage: f(x) = x+1; g(y) = y+1
281
+ sage: f.parent()(g)
282
+ x |--> y + 1
283
+ sage: g.parent()(f)
284
+ y |--> x + 1
285
+ sage: f(x) = x+2*y; g(y) = y+3*x
286
+ sage: f.parent()(g)
287
+ x |--> 3*x + y
288
+ sage: g.parent()(f)
289
+ y |--> x + 2*y
290
+ """
291
+ return SymbolicRing._element_constructor_(self, x)
292
+
293
+ def _repr_(self):
294
+ """
295
+ String representation of ring of callable symbolic expressions.
296
+
297
+ EXAMPLES::
298
+
299
+ sage: R = CallableSymbolicExpressionRing(var('x,y,theta'))
300
+ sage: R._repr_()
301
+ 'Callable function ring with arguments (x, y, theta)'
302
+
303
+ We verify that :issue:`12298` has been fixed::
304
+
305
+ sage: S = CallableSymbolicExpressionRing([var('z')])
306
+ sage: S._repr_()
307
+ 'Callable function ring with argument z'
308
+ """
309
+ if len(self._arguments) == 0:
310
+ return "Callable function ring with no named arguments"
311
+ elif len(self._arguments) == 1:
312
+ return "Callable function ring with argument {}".format(self._arguments[0])
313
+ else:
314
+ return "Callable function ring with arguments {}".format(self._arguments)
315
+
316
+ def arguments(self):
317
+ """
318
+ Return the arguments of ``self``.
319
+
320
+ The order that the variables appear in ``self.arguments()`` is
321
+ the order that is used in evaluating the elements of ``self``.
322
+
323
+ EXAMPLES::
324
+
325
+ sage: x,y = var('x,y')
326
+ sage: f(x,y) = 2*x+y
327
+ sage: f.parent().arguments()
328
+ (x, y)
329
+ sage: f(y,x) = 2*x+y
330
+ sage: f.parent().arguments()
331
+ (y, x)
332
+ """
333
+ return self._arguments
334
+
335
+ args = arguments
336
+
337
+ def _repr_element_(self, x):
338
+ """
339
+ Return the string representation of the Expression ``x``.
340
+
341
+ EXAMPLES::
342
+
343
+ sage: f(y,x) = x + y
344
+ sage: f
345
+ (y, x) |--> x + y
346
+ sage: f.parent()
347
+ Callable function ring with arguments (y, x)
348
+ """
349
+ args = self.arguments()
350
+ repr_x = SymbolicRing._repr_element_(self, x)
351
+ if len(args) == 1:
352
+ return "%s |--> %s" % (args[0], repr_x)
353
+ else:
354
+ args = ", ".join(map(str, args))
355
+ return "(%s) |--> %s" % (args, repr_x)
356
+
357
+ def _latex_element_(self, x):
358
+ r"""
359
+ Finds the LaTeX representation of this expression.
360
+
361
+ EXAMPLES::
362
+
363
+ sage: f(A, t, omega, psi) = A*cos(omega*t - psi)
364
+ sage: f._latex_()
365
+ '\\left( A, t, \\omega, \\psi \\right) \\ {\\mapsto} \\ A \\cos\\left(\\omega t - \\psi\\right)'
366
+
367
+ sage: f(mu) = mu^3
368
+ sage: f._latex_()
369
+ '\\mu \\ {\\mapsto}\\ \\mu^{3}'
370
+ """
371
+ from sage.misc.latex import latex
372
+ args = self.args()
373
+ args = [latex(arg) for arg in args]
374
+ latex_x = SymbolicRing._latex_element_(self, x)
375
+ if len(args) == 1:
376
+ return r"%s \ {\mapsto}\ %s" % (args[0], latex_x)
377
+ else:
378
+ vars = ", ".join(args)
379
+ return r"\left( %s \right) \ {\mapsto} \ %s" % (vars, latex_x)
380
+
381
+ def _call_element_(self, _the_element, *args, **kwds):
382
+ """
383
+ Calling a callable symbolic expression returns a symbolic expression
384
+ with the appropriate arguments substituted.
385
+
386
+ EXAMPLES::
387
+
388
+ sage: var('a, x, y, z')
389
+ (a, x, y, z)
390
+ sage: f(x,y) = a + 2*x + 3*y + z
391
+ sage: f
392
+ (x, y) |--> a + 2*x + 3*y + z
393
+ sage: f(1,2)
394
+ a + z + 8
395
+ sage: f(y=2, a=-1)
396
+ 2*x + z + 5
397
+
398
+ Note that keyword arguments will override the regular arguments.
399
+ ::
400
+
401
+
402
+ sage: f.arguments()
403
+ (x, y)
404
+ sage: f(1,2)
405
+ a + z + 8
406
+ sage: f(10,2)
407
+ a + z + 26
408
+ sage: f(10,2,x=1)
409
+ a + z + 8
410
+ sage: f(z=100)
411
+ a + 2*x + 3*y + 100
412
+ """
413
+ if any(type(arg).__module__ == 'numpy' and type(arg).__name__ == "ndarray" for arg in args): # avoid importing
414
+ raise NotImplementedError("Numpy arrays are not supported as arguments for symbolic expressions")
415
+
416
+ d = dict(zip([repr(_) for _ in self.arguments()], args))
417
+ d.update(kwds)
418
+ return SR(_the_element.substitute(**d))
419
+
420
+ # __reduce__ gets replaced by the CallableSymbolicExpressionRingFactory
421
+ __reduce__ = object.__reduce__
422
+
423
+
424
+ class CallableSymbolicExpressionRingFactory(UniqueFactory):
425
+ def create_key(self, args, check=True):
426
+ """
427
+ EXAMPLES::
428
+
429
+ sage: x,y = var('x,y')
430
+ sage: CallableSymbolicExpressionRing.create_key((x,y))
431
+ (x, y)
432
+ """
433
+ if check:
434
+ from sage.structure.element import Expression
435
+ if len(args) == 1 and isinstance(args[0], (list, tuple)):
436
+ args, = args
437
+ for arg in args:
438
+ if not (isinstance(arg, Expression) and arg.is_symbol()):
439
+ raise TypeError("must construct a function with a tuple (or list) of variables")
440
+ args = tuple(args)
441
+ return args
442
+
443
+ def create_object(self, version, key, **extra_args):
444
+ """
445
+ Return a CallableSymbolicExpressionRing given a version and a key.
446
+
447
+ EXAMPLES::
448
+
449
+ sage: x,y = var('x,y')
450
+ sage: CallableSymbolicExpressionRing.create_object(0, (x, y))
451
+ Callable function ring with arguments (x, y)
452
+ """
453
+ return CallableSymbolicExpressionRing_class(key)
454
+
455
+
456
+ CallableSymbolicExpressionRing = CallableSymbolicExpressionRingFactory('sage.symbolic.callable.CallableSymbolicExpressionRing')
@@ -0,0 +1,66 @@
1
+ from collections.abc import Callable
2
+ from typing import Any, Union
3
+ from sage.rings.abc import CallableSymbolicExpressionRing as CallableSymbolicExpressionRingABC
4
+ from sage.symbolic.ring import SymbolicRing, SR
5
+ from sage.categories.pushout import ConstructionFunctor
6
+ from sage.structure.factory import UniqueFactory
7
+
8
+ class CallableSymbolicExpressionFunctor(ConstructionFunctor):
9
+ def __init__(self, arguments: tuple):
10
+ ...
11
+
12
+ def __repr__(self) -> str:
13
+ ...
14
+
15
+ def merge(self, other: 'CallableSymbolicExpressionFunctor') -> 'CallableSymbolicExpressionFunctor':
16
+ ...
17
+
18
+ def __call__(self, R: SymbolicRing) -> 'CallableSymbolicExpressionRing':
19
+ ...
20
+
21
+ def arguments(self) -> tuple:
22
+ ...
23
+
24
+ def unify_arguments(self, x: 'CallableSymbolicExpressionFunctor') -> tuple:
25
+ ...
26
+
27
+ class CallableSymbolicExpressionRing_class(SymbolicRing, CallableSymbolicExpressionRingABC):
28
+ def __init__(self, arguments: tuple):
29
+ ...
30
+
31
+ def _coerce_map_from_(self, R: Any) -> bool:
32
+ ...
33
+
34
+ def construction(self) -> tuple:
35
+ ...
36
+
37
+ def _element_constructor_(self, x: Any) -> Any:
38
+ ...
39
+
40
+ def _repr_(self) -> str:
41
+ ...
42
+
43
+ def arguments(self) -> tuple:
44
+ ...
45
+
46
+ args = arguments
47
+
48
+ def _repr_element_(self, x: Any) -> str:
49
+ ...
50
+
51
+ def _latex_element_(self, x: Any) -> str:
52
+ ...
53
+
54
+ def _call_element_(self, _the_element: Any, *args: Any, **kwds: Any) -> Any:
55
+ ...
56
+
57
+ __reduce__ = object.__reduce__
58
+
59
+ class CallableSymbolicExpressionRingFactory(UniqueFactory):
60
+ def create_key(self, args: Any, check: bool = True) -> tuple:
61
+ ...
62
+
63
+ def create_object(self, version: int, key: tuple, **extra_args: Any) -> 'CallableSymbolicExpressionRing_class':
64
+ ...
65
+
66
+ CallableSymbolicExpressionRing = CallableSymbolicExpressionRingFactory('sage.symbolic.callable.CallableSymbolicExpressionRing')
@@ -0,0 +1,38 @@
1
+ from collections.abc import Iterable
2
+ from typing import Any
3
+
4
+ def print_order(lhs: Any, rhs: Any) -> int:
5
+ ...
6
+
7
+ class _print_key:
8
+ def __init__(self, ex: Any):
9
+ ...
10
+
11
+ def __lt__(self, other: '_print_key') -> bool:
12
+ ...
13
+
14
+ def print_sorted(expressions: Iterable) -> list:
15
+ ...
16
+
17
+ class _math_key:
18
+ def __init__(self, ex: Any):
19
+ ...
20
+
21
+ def __lt__(self, other: '_math_key') -> bool:
22
+ ...
23
+
24
+ def math_sorted(expressions: Iterable) -> list:
25
+ ...
26
+
27
+ def mixed_order(lhs: Any, rhs: Any) -> int:
28
+ ...
29
+
30
+ class _mixed_key:
31
+ def __init__(self, ex: Any):
32
+ ...
33
+
34
+ def __lt__(self, other: '_mixed_key') -> bool:
35
+ ...
36
+
37
+ def mixed_sorted(expressions: Iterable) -> list:
38
+ ...
@@ -0,0 +1,35 @@
1
+ # sage_setup: distribution = sagemath-symbolics
2
+ """
3
+ Complexity Measures
4
+
5
+ Some measures of symbolic expression complexity. Each complexity
6
+ measure is expected to take a symbolic expression as an argument, and
7
+ return a number.
8
+ """
9
+
10
+
11
+ def string_length(expr):
12
+ """
13
+ Return the length of ``expr`` after converting it to a string.
14
+
15
+ INPUT:
16
+
17
+ - ``expr`` -- the expression whose complexity we want to measure
18
+
19
+ OUTPUT: a real number representing the complexity of ``expr``
20
+
21
+ RATIONALE:
22
+
23
+ If the expression is longer on-screen, then a human would probably
24
+ consider it more complex.
25
+
26
+ EXAMPLES:
27
+
28
+ This expression has three characters, ``x``, ``^``, and ``2``::
29
+
30
+ sage: from sage.symbolic.complexity_measures import string_length
31
+ sage: f = x^2
32
+ sage: string_length(f)
33
+ 3
34
+ """
35
+ return len(str(expr))