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.

Files changed (172) hide show
  1. passagemath_symbolics/.dylibs/libgmp.10.dylib +0 -0
  2. passagemath_symbolics/__init__.py +3 -0
  3. passagemath_symbolics-10.6.40.dist-info/METADATA +187 -0
  4. passagemath_symbolics-10.6.40.dist-info/RECORD +172 -0
  5. passagemath_symbolics-10.6.40.dist-info/WHEEL +6 -0
  6. passagemath_symbolics-10.6.40.dist-info/top_level.txt +3 -0
  7. sage/all__sagemath_symbolics.py +17 -0
  8. sage/calculus/all.py +14 -0
  9. sage/calculus/calculus.py +2826 -0
  10. sage/calculus/desolvers.py +1866 -0
  11. sage/calculus/predefined.py +51 -0
  12. sage/calculus/tests.py +225 -0
  13. sage/calculus/var.cpython-314t-darwin.so +0 -0
  14. sage/calculus/var.pyx +401 -0
  15. sage/dynamics/all__sagemath_symbolics.py +6 -0
  16. sage/dynamics/complex_dynamics/all.py +5 -0
  17. sage/dynamics/complex_dynamics/mandel_julia.py +765 -0
  18. sage/dynamics/complex_dynamics/mandel_julia_helper.cpython-314t-darwin.so +0 -0
  19. sage/dynamics/complex_dynamics/mandel_julia_helper.pyx +1035 -0
  20. sage/ext/all__sagemath_symbolics.py +1 -0
  21. sage/ext_data/kenzo/CP2.txt +45 -0
  22. sage/ext_data/kenzo/CP3.txt +349 -0
  23. sage/ext_data/kenzo/CP4.txt +4774 -0
  24. sage/ext_data/kenzo/README.txt +49 -0
  25. sage/ext_data/kenzo/S4.txt +20 -0
  26. sage/ext_data/magma/latex/latex.m +1021 -0
  27. sage/ext_data/magma/latex/latex.spec +1 -0
  28. sage/ext_data/magma/sage/basic.m +356 -0
  29. sage/ext_data/magma/sage/sage.spec +1 -0
  30. sage/ext_data/magma/spec +9 -0
  31. sage/geometry/all__sagemath_symbolics.py +8 -0
  32. sage/geometry/hyperbolic_space/all.py +5 -0
  33. sage/geometry/hyperbolic_space/hyperbolic_coercion.py +743 -0
  34. sage/geometry/hyperbolic_space/hyperbolic_constants.py +5 -0
  35. sage/geometry/hyperbolic_space/hyperbolic_geodesic.py +2409 -0
  36. sage/geometry/hyperbolic_space/hyperbolic_interface.py +206 -0
  37. sage/geometry/hyperbolic_space/hyperbolic_isometry.py +1082 -0
  38. sage/geometry/hyperbolic_space/hyperbolic_model.py +1502 -0
  39. sage/geometry/hyperbolic_space/hyperbolic_point.py +621 -0
  40. sage/geometry/riemannian_manifolds/all.py +7 -0
  41. sage/geometry/riemannian_manifolds/parametrized_surface3d.py +1632 -0
  42. sage/geometry/riemannian_manifolds/surface3d_generators.py +461 -0
  43. sage/interfaces/all__sagemath_symbolics.py +1 -0
  44. sage/interfaces/magma.py +3017 -0
  45. sage/interfaces/magma_free.py +92 -0
  46. sage/interfaces/maple.py +1397 -0
  47. sage/interfaces/mathematica.py +1345 -0
  48. sage/interfaces/mathics.py +1312 -0
  49. sage/interfaces/sympy.py +1398 -0
  50. sage/interfaces/sympy_wrapper.py +197 -0
  51. sage/interfaces/tides.py +938 -0
  52. sage/libs/all__sagemath_symbolics.py +6 -0
  53. sage/manifolds/all.py +7 -0
  54. sage/manifolds/calculus_method.py +555 -0
  55. sage/manifolds/catalog.py +437 -0
  56. sage/manifolds/chart.py +4019 -0
  57. sage/manifolds/chart_func.py +3419 -0
  58. sage/manifolds/continuous_map.py +2183 -0
  59. sage/manifolds/continuous_map_image.py +155 -0
  60. sage/manifolds/differentiable/affine_connection.py +2475 -0
  61. sage/manifolds/differentiable/all.py +1 -0
  62. sage/manifolds/differentiable/automorphismfield.py +1383 -0
  63. sage/manifolds/differentiable/automorphismfield_group.py +604 -0
  64. sage/manifolds/differentiable/bundle_connection.py +1445 -0
  65. sage/manifolds/differentiable/characteristic_cohomology_class.py +1840 -0
  66. sage/manifolds/differentiable/chart.py +1241 -0
  67. sage/manifolds/differentiable/curve.py +1028 -0
  68. sage/manifolds/differentiable/de_rham_cohomology.py +541 -0
  69. sage/manifolds/differentiable/degenerate.py +559 -0
  70. sage/manifolds/differentiable/degenerate_submanifold.py +1671 -0
  71. sage/manifolds/differentiable/diff_form.py +1658 -0
  72. sage/manifolds/differentiable/diff_form_module.py +1062 -0
  73. sage/manifolds/differentiable/diff_map.py +1315 -0
  74. sage/manifolds/differentiable/differentiable_submanifold.py +291 -0
  75. sage/manifolds/differentiable/examples/all.py +1 -0
  76. sage/manifolds/differentiable/examples/euclidean.py +2517 -0
  77. sage/manifolds/differentiable/examples/real_line.py +897 -0
  78. sage/manifolds/differentiable/examples/sphere.py +1186 -0
  79. sage/manifolds/differentiable/examples/symplectic_space.py +187 -0
  80. sage/manifolds/differentiable/examples/symplectic_space_test.py +40 -0
  81. sage/manifolds/differentiable/integrated_curve.py +4035 -0
  82. sage/manifolds/differentiable/levi_civita_connection.py +841 -0
  83. sage/manifolds/differentiable/manifold.py +4254 -0
  84. sage/manifolds/differentiable/manifold_homset.py +1826 -0
  85. sage/manifolds/differentiable/metric.py +3032 -0
  86. sage/manifolds/differentiable/mixed_form.py +1507 -0
  87. sage/manifolds/differentiable/mixed_form_algebra.py +559 -0
  88. sage/manifolds/differentiable/multivector_module.py +800 -0
  89. sage/manifolds/differentiable/multivectorfield.py +1520 -0
  90. sage/manifolds/differentiable/poisson_tensor.py +268 -0
  91. sage/manifolds/differentiable/pseudo_riemannian.py +755 -0
  92. sage/manifolds/differentiable/pseudo_riemannian_submanifold.py +1839 -0
  93. sage/manifolds/differentiable/scalarfield.py +1343 -0
  94. sage/manifolds/differentiable/scalarfield_algebra.py +472 -0
  95. sage/manifolds/differentiable/symplectic_form.py +910 -0
  96. sage/manifolds/differentiable/symplectic_form_test.py +220 -0
  97. sage/manifolds/differentiable/tangent_space.py +412 -0
  98. sage/manifolds/differentiable/tangent_vector.py +616 -0
  99. sage/manifolds/differentiable/tensorfield.py +4665 -0
  100. sage/manifolds/differentiable/tensorfield_module.py +963 -0
  101. sage/manifolds/differentiable/tensorfield_paral.py +2450 -0
  102. sage/manifolds/differentiable/tensorfield_paral_test.py +16 -0
  103. sage/manifolds/differentiable/vector_bundle.py +1728 -0
  104. sage/manifolds/differentiable/vectorfield.py +1717 -0
  105. sage/manifolds/differentiable/vectorfield_module.py +2445 -0
  106. sage/manifolds/differentiable/vectorframe.py +1832 -0
  107. sage/manifolds/family.py +270 -0
  108. sage/manifolds/local_frame.py +1490 -0
  109. sage/manifolds/manifold.py +3090 -0
  110. sage/manifolds/manifold_homset.py +452 -0
  111. sage/manifolds/operators.py +359 -0
  112. sage/manifolds/point.py +994 -0
  113. sage/manifolds/scalarfield.py +3718 -0
  114. sage/manifolds/scalarfield_algebra.py +629 -0
  115. sage/manifolds/section.py +3111 -0
  116. sage/manifolds/section_module.py +831 -0
  117. sage/manifolds/structure.py +229 -0
  118. sage/manifolds/subset.py +2764 -0
  119. sage/manifolds/subsets/all.py +1 -0
  120. sage/manifolds/subsets/closure.py +131 -0
  121. sage/manifolds/subsets/pullback.py +885 -0
  122. sage/manifolds/topological_submanifold.py +891 -0
  123. sage/manifolds/trivialization.py +733 -0
  124. sage/manifolds/utilities.py +1348 -0
  125. sage/manifolds/vector_bundle.py +1342 -0
  126. sage/manifolds/vector_bundle_fiber.py +332 -0
  127. sage/manifolds/vector_bundle_fiber_element.py +111 -0
  128. sage/matrix/all__sagemath_symbolics.py +1 -0
  129. sage/matrix/matrix_symbolic_dense.cpython-314t-darwin.so +0 -0
  130. sage/matrix/matrix_symbolic_dense.pxd +6 -0
  131. sage/matrix/matrix_symbolic_dense.pyx +1022 -0
  132. sage/matrix/matrix_symbolic_sparse.cpython-314t-darwin.so +0 -0
  133. sage/matrix/matrix_symbolic_sparse.pxd +6 -0
  134. sage/matrix/matrix_symbolic_sparse.pyx +1029 -0
  135. sage/modules/all__sagemath_symbolics.py +1 -0
  136. sage/modules/vector_callable_symbolic_dense.py +105 -0
  137. sage/modules/vector_symbolic_dense.py +116 -0
  138. sage/modules/vector_symbolic_sparse.py +118 -0
  139. sage/rings/all__sagemath_symbolics.py +4 -0
  140. sage/rings/asymptotic/all.py +6 -0
  141. sage/rings/asymptotic/asymptotic_expansion_generators.py +1485 -0
  142. sage/rings/asymptotic/asymptotic_ring.py +4858 -0
  143. sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py +4153 -0
  144. sage/rings/asymptotic/growth_group.py +5373 -0
  145. sage/rings/asymptotic/growth_group_cartesian.py +1400 -0
  146. sage/rings/asymptotic/term_monoid.py +5237 -0
  147. sage/rings/function_field/all__sagemath_symbolics.py +2 -0
  148. sage/rings/polynomial/all__sagemath_symbolics.py +1 -0
  149. sage/symbolic/all.py +15 -0
  150. sage/symbolic/assumptions.py +985 -0
  151. sage/symbolic/benchmark.py +93 -0
  152. sage/symbolic/callable.py +459 -0
  153. sage/symbolic/complexity_measures.py +35 -0
  154. sage/symbolic/constants.py +1287 -0
  155. sage/symbolic/expression_conversion_algebraic.py +310 -0
  156. sage/symbolic/expression_conversion_sympy.py +317 -0
  157. sage/symbolic/expression_conversions.py +1713 -0
  158. sage/symbolic/function_factory.py +355 -0
  159. sage/symbolic/integration/all.py +1 -0
  160. sage/symbolic/integration/external.py +270 -0
  161. sage/symbolic/integration/integral.py +1115 -0
  162. sage/symbolic/maxima_wrapper.py +162 -0
  163. sage/symbolic/operators.py +267 -0
  164. sage/symbolic/random_tests.py +462 -0
  165. sage/symbolic/relation.py +1907 -0
  166. sage/symbolic/ring.cpython-314t-darwin.so +0 -0
  167. sage/symbolic/ring.pxd +5 -0
  168. sage/symbolic/ring.pyx +1396 -0
  169. sage/symbolic/subring.py +1025 -0
  170. sage/symbolic/symengine.py +19 -0
  171. sage/symbolic/tests.py +40 -0
  172. sage/symbolic/units.py +1470 -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,459 @@
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
+ if all(a in args for a in R.arguments()):
264
+ return True
265
+ else:
266
+ return False
267
+ return SymbolicRing._coerce_map_from_(self, R)
268
+
269
+ def construction(self):
270
+ """
271
+ EXAMPLES::
272
+
273
+ sage: f(x,y) = x^2 + y
274
+ sage: f.parent().construction()
275
+ (CallableSymbolicExpressionFunctor(x, y), Symbolic Ring)
276
+ """
277
+ return (CallableSymbolicExpressionFunctor(self.arguments()), SR)
278
+
279
+ def _element_constructor_(self, x):
280
+ """
281
+ TESTS::
282
+
283
+ sage: f(x) = x+1; g(y) = y+1
284
+ sage: f.parent()(g)
285
+ x |--> y + 1
286
+ sage: g.parent()(f)
287
+ y |--> x + 1
288
+ sage: f(x) = x+2*y; g(y) = y+3*x
289
+ sage: f.parent()(g)
290
+ x |--> 3*x + y
291
+ sage: g.parent()(f)
292
+ y |--> x + 2*y
293
+ """
294
+ return SymbolicRing._element_constructor_(self, x)
295
+
296
+ def _repr_(self):
297
+ """
298
+ String representation of ring of callable symbolic expressions.
299
+
300
+ EXAMPLES::
301
+
302
+ sage: R = CallableSymbolicExpressionRing(var('x,y,theta'))
303
+ sage: R._repr_()
304
+ 'Callable function ring with arguments (x, y, theta)'
305
+
306
+ We verify that :issue:`12298` has been fixed::
307
+
308
+ sage: S = CallableSymbolicExpressionRing([var('z')])
309
+ sage: S._repr_()
310
+ 'Callable function ring with argument z'
311
+ """
312
+ if len(self._arguments) == 0:
313
+ return "Callable function ring with no named arguments"
314
+ elif len(self._arguments) == 1:
315
+ return "Callable function ring with argument {}".format(self._arguments[0])
316
+ else:
317
+ return "Callable function ring with arguments {}".format(self._arguments)
318
+
319
+ def arguments(self):
320
+ """
321
+ Return the arguments of ``self``.
322
+
323
+ The order that the variables appear in ``self.arguments()`` is
324
+ the order that is used in evaluating the elements of ``self``.
325
+
326
+ EXAMPLES::
327
+
328
+ sage: x,y = var('x,y')
329
+ sage: f(x,y) = 2*x+y
330
+ sage: f.parent().arguments()
331
+ (x, y)
332
+ sage: f(y,x) = 2*x+y
333
+ sage: f.parent().arguments()
334
+ (y, x)
335
+ """
336
+ return self._arguments
337
+
338
+ args = arguments
339
+
340
+ def _repr_element_(self, x):
341
+ """
342
+ Return the string representation of the Expression ``x``.
343
+
344
+ EXAMPLES::
345
+
346
+ sage: f(y,x) = x + y
347
+ sage: f
348
+ (y, x) |--> x + y
349
+ sage: f.parent()
350
+ Callable function ring with arguments (y, x)
351
+ """
352
+ args = self.arguments()
353
+ repr_x = SymbolicRing._repr_element_(self, x)
354
+ if len(args) == 1:
355
+ return "%s |--> %s" % (args[0], repr_x)
356
+ else:
357
+ args = ", ".join(map(str, args))
358
+ return "(%s) |--> %s" % (args, repr_x)
359
+
360
+ def _latex_element_(self, x):
361
+ r"""
362
+ Finds the LaTeX representation of this expression.
363
+
364
+ EXAMPLES::
365
+
366
+ sage: f(A, t, omega, psi) = A*cos(omega*t - psi)
367
+ sage: f._latex_()
368
+ '\\left( A, t, \\omega, \\psi \\right) \\ {\\mapsto} \\ A \\cos\\left(\\omega t - \\psi\\right)'
369
+
370
+ sage: f(mu) = mu^3
371
+ sage: f._latex_()
372
+ '\\mu \\ {\\mapsto}\\ \\mu^{3}'
373
+ """
374
+ from sage.misc.latex import latex
375
+ args = self.args()
376
+ args = [latex(arg) for arg in args]
377
+ latex_x = SymbolicRing._latex_element_(self, x)
378
+ if len(args) == 1:
379
+ return r"%s \ {\mapsto}\ %s" % (args[0], latex_x)
380
+ else:
381
+ vars = ", ".join(args)
382
+ return r"\left( %s \right) \ {\mapsto} \ %s" % (vars, latex_x)
383
+
384
+ def _call_element_(self, _the_element, *args, **kwds):
385
+ """
386
+ Calling a callable symbolic expression returns a symbolic expression
387
+ with the appropriate arguments substituted.
388
+
389
+ EXAMPLES::
390
+
391
+ sage: var('a, x, y, z')
392
+ (a, x, y, z)
393
+ sage: f(x,y) = a + 2*x + 3*y + z
394
+ sage: f
395
+ (x, y) |--> a + 2*x + 3*y + z
396
+ sage: f(1,2)
397
+ a + z + 8
398
+ sage: f(y=2, a=-1)
399
+ 2*x + z + 5
400
+
401
+ Note that keyword arguments will override the regular arguments.
402
+ ::
403
+
404
+
405
+ sage: f.arguments()
406
+ (x, y)
407
+ sage: f(1,2)
408
+ a + z + 8
409
+ sage: f(10,2)
410
+ a + z + 26
411
+ sage: f(10,2,x=1)
412
+ a + z + 8
413
+ sage: f(z=100)
414
+ a + 2*x + 3*y + 100
415
+ """
416
+ if any(type(arg).__module__ == 'numpy' and type(arg).__name__ == "ndarray" for arg in args): # avoid importing
417
+ raise NotImplementedError("Numpy arrays are not supported as arguments for symbolic expressions")
418
+
419
+ d = dict(zip([repr(_) for _ in self.arguments()], args))
420
+ d.update(kwds)
421
+ return SR(_the_element.substitute(**d))
422
+
423
+ # __reduce__ gets replaced by the CallableSymbolicExpressionRingFactory
424
+ __reduce__ = object.__reduce__
425
+
426
+
427
+ class CallableSymbolicExpressionRingFactory(UniqueFactory):
428
+ def create_key(self, args, check=True):
429
+ """
430
+ EXAMPLES::
431
+
432
+ sage: x,y = var('x,y')
433
+ sage: CallableSymbolicExpressionRing.create_key((x,y))
434
+ (x, y)
435
+ """
436
+ if check:
437
+ from sage.structure.element import Expression
438
+ if len(args) == 1 and isinstance(args[0], (list, tuple)):
439
+ args, = args
440
+ for arg in args:
441
+ if not (isinstance(arg, Expression) and arg.is_symbol()):
442
+ raise TypeError("must construct a function with a tuple (or list) of variables")
443
+ args = tuple(args)
444
+ return args
445
+
446
+ def create_object(self, version, key, **extra_args):
447
+ """
448
+ Return a CallableSymbolicExpressionRing given a version and a key.
449
+
450
+ EXAMPLES::
451
+
452
+ sage: x,y = var('x,y')
453
+ sage: CallableSymbolicExpressionRing.create_object(0, (x, y))
454
+ Callable function ring with arguments (x, y)
455
+ """
456
+ return CallableSymbolicExpressionRing_class(key)
457
+
458
+
459
+ CallableSymbolicExpressionRing = CallableSymbolicExpressionRingFactory('sage.symbolic.callable.CallableSymbolicExpressionRing')
@@ -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))