passagemath-symbolics 10.6.43__cp314-cp314t-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.

Potentially problematic release.


This version of passagemath-symbolics might be problematic. Click here for more details.

Files changed (171) hide show
  1. passagemath_symbolics/__init__.py +3 -0
  2. passagemath_symbolics-10.6.43.dist-info/METADATA +187 -0
  3. passagemath_symbolics-10.6.43.dist-info/RECORD +171 -0
  4. passagemath_symbolics-10.6.43.dist-info/WHEEL +5 -0
  5. passagemath_symbolics-10.6.43.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 +2826 -0
  9. sage/calculus/desolvers.py +1866 -0
  10. sage/calculus/predefined.py +51 -0
  11. sage/calculus/tests.py +225 -0
  12. sage/calculus/var.cpython-314t-x86_64-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-x86_64-linux-musl.so +0 -0
  18. sage/dynamics/complex_dynamics/mandel_julia_helper.pyx +1035 -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 +743 -0
  33. sage/geometry/hyperbolic_space/hyperbolic_constants.py +5 -0
  34. sage/geometry/hyperbolic_space/hyperbolic_geodesic.py +2409 -0
  35. sage/geometry/hyperbolic_space/hyperbolic_interface.py +206 -0
  36. sage/geometry/hyperbolic_space/hyperbolic_isometry.py +1082 -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 +3017 -0
  44. sage/interfaces/magma_free.py +92 -0
  45. sage/interfaces/maple.py +1397 -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 +555 -0
  54. sage/manifolds/catalog.py +437 -0
  55. sage/manifolds/chart.py +4019 -0
  56. sage/manifolds/chart_func.py +3419 -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 +1671 -0
  70. sage/manifolds/differentiable/diff_form.py +1658 -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 +1520 -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 +910 -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 +1728 -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 +2764 -0
  118. sage/manifolds/subsets/all.py +1 -0
  119. sage/manifolds/subsets/closure.py +131 -0
  120. sage/manifolds/subsets/pullback.py +885 -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 +1342 -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-x86_64-linux-musl.so +0 -0
  129. sage/matrix/matrix_symbolic_dense.pxd +6 -0
  130. sage/matrix/matrix_symbolic_dense.pyx +1022 -0
  131. sage/matrix/matrix_symbolic_sparse.cpython-314t-x86_64-linux-musl.so +0 -0
  132. sage/matrix/matrix_symbolic_sparse.pxd +6 -0
  133. sage/matrix/matrix_symbolic_sparse.pyx +1029 -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 +4153 -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 +5237 -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 +985 -0
  150. sage/symbolic/benchmark.py +93 -0
  151. sage/symbolic/callable.py +459 -0
  152. sage/symbolic/complexity_measures.py +35 -0
  153. sage/symbolic/constants.py +1287 -0
  154. sage/symbolic/expression_conversion_algebraic.py +310 -0
  155. sage/symbolic/expression_conversion_sympy.py +317 -0
  156. sage/symbolic/expression_conversions.py +1713 -0
  157. sage/symbolic/function_factory.py +355 -0
  158. sage/symbolic/integration/all.py +1 -0
  159. sage/symbolic/integration/external.py +270 -0
  160. sage/symbolic/integration/integral.py +1115 -0
  161. sage/symbolic/maxima_wrapper.py +162 -0
  162. sage/symbolic/operators.py +267 -0
  163. sage/symbolic/random_tests.py +462 -0
  164. sage/symbolic/relation.py +1907 -0
  165. sage/symbolic/ring.cpython-314t-x86_64-linux-musl.so +0 -0
  166. sage/symbolic/ring.pxd +5 -0
  167. sage/symbolic/ring.pyx +1396 -0
  168. sage/symbolic/subring.py +1025 -0
  169. sage/symbolic/symengine.py +19 -0
  170. sage/symbolic/tests.py +40 -0
  171. sage/symbolic/units.py +1470 -0
@@ -0,0 +1,1115 @@
1
+ # sage_setup: distribution = sagemath-symbolics
2
+ """
3
+ Symbolic Integration
4
+ """
5
+ # ****************************************************************************
6
+ # Copyright (C) 2009 Golam Mortuza Hossain <gmhossain@gmail.com>
7
+ # Copyright (C) 2010 Burcin Erocal <burcin@erocal.org>
8
+ #
9
+ # This program is free software: you can redistribute it and/or modify
10
+ # it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation, either version 2 of the License, or
12
+ # (at your option) any later version.
13
+ # https://www.gnu.org/licenses/
14
+ # ****************************************************************************`
15
+ from sage.structure.element import Expression
16
+ from sage.symbolic.ring import SR
17
+ from sage.symbolic.function import BuiltinFunction
18
+
19
+ ##################################################################
20
+ # Table of available integration routines
21
+ ##################################################################
22
+
23
+ import sage.symbolic.integration.external as external
24
+
25
+ # Add new integration routines to the dictionary below. This will make them
26
+ # accessible with the 'algorithm' keyword parameter of top level integrate().
27
+ available_integrators = {}
28
+ available_integrators['maxima'] = external.maxima_integrator
29
+ available_integrators['sympy'] = external.sympy_integrator
30
+ available_integrators['mathematica_free'] = external.mma_free_integrator
31
+ available_integrators['fricas'] = external.fricas_integrator
32
+ available_integrators['giac'] = external.libgiac_integrator
33
+ available_integrators['libgiac'] = external.libgiac_integrator
34
+
35
+ ######################################################
36
+ #
37
+ # Class implementing symbolic integration
38
+ #
39
+ ######################################################
40
+
41
+
42
+ class IndefiniteIntegral(BuiltinFunction):
43
+ def __init__(self):
44
+ """
45
+ Class to represent an indefinite integral.
46
+
47
+ EXAMPLES::
48
+
49
+ sage: from sage.symbolic.integration.integral import indefinite_integral
50
+ sage: indefinite_integral(log(x), x) #indirect doctest
51
+ x*log(x) - x
52
+ sage: indefinite_integral(x^2, x)
53
+ 1/3*x^3
54
+ sage: indefinite_integral(4*x*log(x), x)
55
+ 2*x^2*log(x) - x^2
56
+ sage: indefinite_integral(exp(x), 2*x)
57
+ 2*e^x
58
+
59
+ TESTS:
60
+
61
+ Check for :issue:`28913`::
62
+
63
+ sage: # needs sage.libs.giac
64
+ sage: Ex = (1-2*x^(1/3))^(3/4)/x
65
+ sage: integrate(Ex, x, algorithm='giac') # long time
66
+ 4*(-2*x^(1/3) + 1)^(3/4) + 6*arctan((-2*x^(1/3) + 1)^(1/4)) - 3*log(abs((-2*x^(1/3) + 1)^(1/4) + 1)) + 3*log(abs((-2*x^(1/3) + 1)^(1/4) - 1))
67
+
68
+ Check for :issue:`29833`::
69
+
70
+ sage: (x,a,b)=var('x a b')
71
+ sage: assume(b > 0)
72
+ sage: f = (exp((x-a)/b) + 1)**(-1)
73
+ sage: (f*f).integrate(x, algorithm='mathematica_free') # optional -- internet
74
+ -b*log(e^(a/b) + e^(x/b)) + x + b/(e^(-(a - x)/b) + 1)
75
+
76
+ After :issue:`25119` we can integrate the following function,
77
+ although giac and sympy give different-looking answers::
78
+
79
+ sage: result = integrate(sqrt(x^2)/x,x)
80
+ ...
81
+ sage: result in [x*sgn(x), sqrt(x^2)]
82
+ True
83
+ """
84
+ # The automatic evaluation routine will try these integrators
85
+ # in the given order. This is an attribute of the class instead of
86
+ # a global variable in this module to enable customization by
87
+ # creating a subclasses which define a different set of integrators
88
+ #
89
+ # The libgiac integrator may immediately return a symbolic
90
+ # (unevaluated) answer if libgiac is unavailable. This essentially
91
+ # causes it to be skipped.
92
+ self.integrators = [external.maxima_integrator,
93
+ external.libgiac_integrator,
94
+ external.sympy_integrator]
95
+
96
+ BuiltinFunction.__init__(self, "integrate", nargs=2, conversions={'sympy': 'Integral',
97
+ 'giac': 'integrate'})
98
+
99
+ def _eval_(self, f, x):
100
+ """
101
+ EXAMPLES::
102
+
103
+ sage: from sage.symbolic.integration.integral import indefinite_integral
104
+ sage: indefinite_integral(exp(x), x) # indirect doctest
105
+ e^x
106
+ sage: indefinite_integral(exp(x), x^2)
107
+ 2*(x - 1)*e^x
108
+
109
+ TESTS:
110
+
111
+ Check that :issue:`28842` is fixed::
112
+
113
+ sage: integrate(1/(x^4 + x^3 + 1), x)
114
+ integrate(1/(x^4 + x^3 + 1), x)
115
+
116
+ Check that :issue:`32002` is fixed. This needs giac since only
117
+ giac can integrate it in any case::
118
+
119
+ sage: # needs sage.libs.giac
120
+ sage: result = integral(2*min_symbolic(x,2*x),x)
121
+ ...
122
+ sage: result
123
+ -1/2*x^2*sgn(x) + 3/2*x^2
124
+ """
125
+ # Check for x
126
+ if not (isinstance(x, Expression) and x.is_symbol()):
127
+ if len(x.variables()) == 1:
128
+ nx = x.variables()[0]
129
+ f = f * x.diff(nx)
130
+ x = nx
131
+ else:
132
+ return None
133
+
134
+ # we try all listed integration algorithms
135
+ A = None
136
+ for integrator in self.integrators:
137
+ try:
138
+ A = integrator(f, x)
139
+ except (NotImplementedError, TypeError,
140
+ AttributeError, RuntimeError):
141
+ pass
142
+ except ValueError:
143
+ # maxima is telling us something
144
+ raise
145
+ else:
146
+ if not hasattr(A, 'operator'):
147
+ return A
148
+ else:
149
+ uneval = integral(SR.wild(0), x, hold=True)
150
+ if not A.has(uneval):
151
+ return A
152
+ return A
153
+
154
+ def _tderivative_(self, f, x, diff_param=None):
155
+ """
156
+ EXAMPLES::
157
+
158
+ sage: from sage.symbolic.integration.integral import indefinite_integral
159
+ sage: f = function('f'); a,b=var('a,b')
160
+ sage: h = indefinite_integral(f(x), x)
161
+ sage: h.diff(x) # indirect doctest
162
+ f(x)
163
+ sage: h.diff(a)
164
+ 0
165
+ """
166
+ if x.has(diff_param):
167
+ return f * x.derivative(diff_param)
168
+ else:
169
+ return f.derivative(diff_param).integral(x)
170
+
171
+ def _print_latex_(self, f, x):
172
+ r"""
173
+ EXAMPLES::
174
+
175
+ sage: from sage.symbolic.integration.integral import indefinite_integral
176
+ sage: print_latex = indefinite_integral._print_latex_
177
+ sage: var('x,a,b')
178
+ (x, a, b)
179
+ sage: f = function('f')
180
+ sage: print_latex(f(x),x)
181
+ '\\int f\\left(x\\right)\\,{d x}'
182
+ sage: latex(integrate(tan(x)/x, x))
183
+ \int \frac{\tan\left(x\right)}{x}\,{d x}
184
+ """
185
+ from sage.misc.latex import latex
186
+ if not (isinstance(x, Expression) and x.is_symbol()):
187
+ dx_str = "{d \\left(%s\\right)}" % latex(x)
188
+ else:
189
+ dx_str = "{d %s}" % latex(x)
190
+
191
+ return "\\int %s\\,%s" % (latex(f), dx_str)
192
+
193
+
194
+ indefinite_integral = IndefiniteIntegral()
195
+
196
+
197
+ class DefiniteIntegral(BuiltinFunction):
198
+ def __init__(self):
199
+ """
200
+ The symbolic function representing a definite integral.
201
+
202
+ EXAMPLES::
203
+
204
+ sage: from sage.symbolic.integration.integral import definite_integral
205
+ sage: definite_integral(sin(x),x,0,pi)
206
+ 2
207
+
208
+ TESTS:
209
+
210
+ Check for :issue:`32354`::
211
+
212
+ sage: # needs sage.libs.giac
213
+ sage: ex = 1/max_symbolic(x, 1)**2
214
+ sage: integral(ex, x, 0, 2, algorithm='giac')
215
+ 3/2
216
+ sage: result = integral(1/max_symbolic(x, 1)**2, x, 0, oo, algorithm='giac')
217
+ ...
218
+ sage: result
219
+ 2
220
+ """
221
+ # The automatic evaluation routine will try these integrators
222
+ # in the given order. This is an attribute of the class instead of
223
+ # a global variable in this module to enable customization by
224
+ # creating a subclasses which define a different set of integrators
225
+ self.integrators = [external.maxima_integrator,
226
+ external.libgiac_integrator,
227
+ external.sympy_integrator]
228
+
229
+ BuiltinFunction.__init__(self, "integrate", nargs=4, conversions={'sympy': 'Integral',
230
+ 'giac': 'integrate'})
231
+
232
+ def _eval_(self, f, x, a, b):
233
+ """
234
+ Return the results of symbolic evaluation of the integral.
235
+
236
+ EXAMPLES::
237
+
238
+ sage: from sage.symbolic.integration.integral import definite_integral
239
+ sage: definite_integral(exp(x),x,0,1) # indirect doctest
240
+ e - 1
241
+
242
+ TESTS:
243
+
244
+ Check that :issue:`32002` is fixed::
245
+
246
+ sage: result = integral(2*min_symbolic(x,2*x),x,-1,1)
247
+ ...
248
+ sage: result
249
+ -1
250
+ """
251
+ # Check for x
252
+ if not (isinstance(x, Expression) and x.is_symbol()):
253
+ if len(x.variables()) == 1:
254
+ nx = x.variables()[0]
255
+ f = f * x.diff(nx)
256
+ x = nx
257
+ else:
258
+ return None
259
+
260
+ args = (f, x, a, b)
261
+
262
+ # we try all listed integration algorithms
263
+ A = None
264
+ for integrator in self.integrators:
265
+ try:
266
+ A = integrator(*args)
267
+ except (NotImplementedError, TypeError,
268
+ AttributeError, RuntimeError):
269
+ pass
270
+ except ValueError:
271
+ # maxima is telling us something
272
+ raise
273
+ else:
274
+ if not hasattr(A, 'operator'):
275
+ return A
276
+ else:
277
+ uneval = integral(SR.wild(0), x, a, b, hold=True)
278
+ if not A.has(uneval):
279
+ return A
280
+ return A
281
+
282
+ def _evalf_(self, f, x, a, b, parent=None, algorithm=None):
283
+ """
284
+ Return a numerical approximation of the integral.
285
+
286
+ EXAMPLES::
287
+
288
+ sage: from sage.symbolic.integration.integral import definite_integral
289
+ sage: f = sin(x)*log(x)/x^2
290
+ sage: h = definite_integral(f, x, 1, 2, hold=True); h
291
+ integrate(log(x)*sin(x)/x^2, x, 1, 2)
292
+ sage: h.n() # indirect doctest
293
+ 0.14839875208053...
294
+
295
+ TESTS:
296
+
297
+ Check if :issue:`3863` is fixed::
298
+
299
+ sage: integrate(x^2.7 * e^(-2.4*x), x, 0, 3).n()
300
+ 0.154572952320790
301
+ """
302
+ from sage.calculus.integration import numerical_integral
303
+ # The gsl routine returns a tuple, which also contains the error.
304
+ # We only return the result.
305
+ return numerical_integral(f, a, b)[0]
306
+
307
+ def _tderivative_(self, f, x, a, b, diff_param=None):
308
+ """
309
+ Return the derivative of symbolic integration.
310
+
311
+ EXAMPLES::
312
+
313
+ sage: from sage.symbolic.integration.integral import definite_integral
314
+ sage: f = function('f'); a,b=var('a,b')
315
+ sage: h = definite_integral(f(x), x,a,b)
316
+ ...
317
+ sage: h.diff(x) # indirect doctest
318
+ 0
319
+ sage: h.diff(a)
320
+ -f(a)
321
+ sage: h.diff(b)
322
+ f(b)
323
+
324
+ TESTS:
325
+
326
+ Check for :issue:`28656`::
327
+
328
+ sage: t = var("t")
329
+ sage: f = function("f")
330
+ sage: F(x) = integrate(f(t),t,0,x)
331
+ sage: F(x).diff(x)
332
+ f(x)
333
+ """
334
+ if not x.has(diff_param):
335
+ # integration variable != differentiation variable
336
+ ans = definite_integral(f.diff(diff_param), x, a, b)
337
+ else:
338
+ ans = SR.zero()
339
+ if hasattr(b, 'diff'):
340
+ ans += f.subs(x == b) * b.diff(diff_param)
341
+ if hasattr(a, 'diff'):
342
+ ans -= f.subs(x == a) * a.diff(diff_param)
343
+ return ans
344
+
345
+ def _print_latex_(self, f, x, a, b):
346
+ r"""
347
+ Convert this integral to LaTeX notation.
348
+
349
+ EXAMPLES::
350
+
351
+ sage: from sage.symbolic.integration.integral import definite_integral
352
+ sage: print_latex = definite_integral._print_latex_
353
+ sage: var('x,a,b')
354
+ (x, a, b)
355
+ sage: f = function('f')
356
+ sage: print_latex(f(x),x,0,1)
357
+ '\\int_{0}^{1} f\\left(x\\right)\\,{d x}'
358
+ sage: latex(integrate(tan(x)/x, x, 0, 1))
359
+ \int_{0}^{1} \frac{\tan\left(x\right)}{x}\,{d x}
360
+ """
361
+ from sage.misc.latex import latex
362
+ if not (isinstance(x, Expression) and x.is_symbol()):
363
+ dx_str = "{d \\left(%s\\right)}" % latex(x)
364
+ else:
365
+ dx_str = "{d %s}" % latex(x)
366
+ return "\\int_{%s}^{%s} %s\\,%s" % (latex(a), latex(b),
367
+ latex(f), dx_str)
368
+
369
+ def _sympy_(self, f, x, a, b):
370
+ """
371
+ Convert this integral to the equivalent SymPy object.
372
+
373
+ The resulting SymPy integral can be evaluated using ``doit()``.
374
+
375
+ EXAMPLES::
376
+
377
+ sage: integral(x, x, 0, 1, hold=True)._sympy_() # needs sympy
378
+ Integral(x, (x, 0, 1))
379
+ sage: _.doit() # needs sympy
380
+ 1/2
381
+ """
382
+ from sympy.integrals import Integral
383
+ return Integral(f, (x, a, b))
384
+
385
+
386
+ definite_integral = DefiniteIntegral()
387
+
388
+
389
+ def _normalize_integral_input(f, v, a=None, b=None):
390
+ r"""
391
+ Validate and return variable and endpoints for an integral.
392
+
393
+ INPUT:
394
+
395
+ - ``f`` -- an expression to integrate
396
+
397
+ - ``v`` -- a variable of integration or a triple
398
+
399
+ - ``a`` -- (optional) the left endpoint of integration
400
+
401
+ - ``b`` -- (optional) the right endpoint of integration
402
+
403
+ It is also possible to pass the last three parameters in ``v`` as a triple.
404
+
405
+ If the input contains endpoints, both endpoints must be given.
406
+
407
+ OUTPUT: a tuple of ``f``, ``v``, ``a``, and ``b``
408
+
409
+ EXAMPLES::
410
+
411
+ sage: from sage.symbolic.integration.integral import \
412
+ ....: _normalize_integral_input
413
+ sage: _normalize_integral_input(x^2, x, 0, 3)
414
+ (x^2, x, 0, 3)
415
+ sage: _normalize_integral_input(x^2, [x, 0, 3], None, None)
416
+ (x^2, x, 0, 3)
417
+ sage: _normalize_integral_input(x^2, [x], None, None)
418
+ (x^2, x, None, None)
419
+
420
+ TESTS::
421
+
422
+ sage: _normalize_integral_input(x^2, [0, 3], None, None)
423
+ Traceback (most recent call last):
424
+ ...
425
+ TypeError: invalid input [0, 3] - please use variable,
426
+ with or without two endpoints
427
+ sage: _normalize_integral_input(x^2, x, 0, None)
428
+ Traceback (most recent call last):
429
+ ...
430
+ TypeError: only one endpoint was given!
431
+ """
432
+ if isinstance(v, (list, tuple)) and a is None and b is None:
433
+ if len(v) == 1: # bare variable in a tuple
434
+ v = v[0]
435
+ elif len(v) == 3: # variable and two endpoints
436
+ v, a, b = v
437
+ else:
438
+ raise TypeError("invalid input %s - please use variable, "
439
+ "with or without two endpoints" % repr(v))
440
+
441
+ if (a is None) ^ (b is None):
442
+ raise TypeError('only one endpoint was given!')
443
+
444
+ return f, v, a, b
445
+
446
+
447
+ def integrate(expression, v=None, a=None, b=None, algorithm=None, hold=False):
448
+ r"""
449
+ Return the indefinite integral with respect to the variable
450
+ `v`, ignoring the constant of integration. Or, if endpoints
451
+ `a` and `b` are specified, returns the definite
452
+ integral over the interval `[a, b]`.
453
+
454
+ If ``self`` has only one variable, then it returns the
455
+ integral with respect to that variable.
456
+
457
+ If definite integration fails, it could be still possible to
458
+ evaluate the definite integral using indefinite integration with
459
+ the Newton - Leibniz theorem (however, the user has to ensure that the
460
+ indefinite integral is continuous on the compact interval `[a,b]` and
461
+ this theorem can be applied).
462
+
463
+ INPUT:
464
+
465
+ - ``v`` -- a variable or variable name; this can also be a tuple of
466
+ the variable (optional) and endpoints (i.e., ``(x,0,1)`` or ``(0,1)``)
467
+
468
+ - ``a`` -- (optional) lower endpoint of definite integral
469
+
470
+ - ``b`` -- (optional) upper endpoint of definite integral
471
+
472
+ - ``algorithm`` -- (default: ``'maxima'``, ``'libgiac'`` and ``'sympy'``) one of
473
+
474
+ - ``'maxima'`` -- use maxima
475
+
476
+ - ``'sympy'`` -- use sympy (also in Sage)
477
+
478
+ - ``'mathematica_free'`` -- use http://integrals.wolfram.com/
479
+
480
+ - ``'fricas'`` -- use FriCAS (the optional fricas spkg has to be installed)
481
+
482
+ - ``'giac'`` -- use libgiac
483
+
484
+ - ``'libgiac'`` -- use libgiac (alias for ``'giac'``)
485
+
486
+ To prevent automatic evaluation, use the ``hold`` argument.
487
+
488
+ .. SEEALSO::
489
+
490
+ To integrate a polynomial over a polytope, use the optional
491
+ ``latte_int`` package
492
+ :meth:`sage.geometry.polyhedron.base.Polyhedron_base.integrate`.
493
+
494
+ EXAMPLES::
495
+
496
+ sage: x = var('x')
497
+ sage: h = sin(x)/(cos(x))^2
498
+ sage: h.integral(x)
499
+ 1/cos(x)
500
+
501
+ ::
502
+
503
+ sage: f = x^2/(x+1)^3
504
+ sage: f.integral(x)
505
+ 1/2*(4*x + 3)/(x^2 + 2*x + 1) + log(x + 1)
506
+
507
+ ::
508
+
509
+ sage: f = x*cos(x^2)
510
+ sage: f.integral(x, 0, sqrt(pi))
511
+ 0
512
+ sage: f.integral(x, a=-pi, b=pi)
513
+ 0
514
+
515
+ ::
516
+
517
+ sage: f(x) = sin(x)
518
+ sage: f.integral(x, 0, pi/2)
519
+ 1
520
+
521
+ The variable is required, but the endpoints are optional::
522
+
523
+ sage: y = var('y')
524
+ sage: integral(sin(x), x)
525
+ -cos(x)
526
+ sage: integral(sin(x), y)
527
+ y*sin(x)
528
+ sage: integral(sin(x), x, pi, 2*pi)
529
+ -2
530
+ sage: integral(sin(x), y, pi, 2*pi)
531
+ pi*sin(x)
532
+ sage: integral(sin(x), (x, pi, 2*pi))
533
+ -2
534
+ sage: integral(sin(x), (y, pi, 2*pi))
535
+ pi*sin(x)
536
+
537
+ Using the ``hold`` parameter it is possible to prevent automatic
538
+ evaluation, which can then be evaluated via :meth:`simplify`::
539
+
540
+ sage: integral(x^2, x, 0, 3)
541
+ 9
542
+ sage: a = integral(x^2, x, 0, 3, hold=True) ; a
543
+ integrate(x^2, x, 0, 3)
544
+ sage: a.simplify()
545
+ 9
546
+
547
+ Constraints are sometimes needed::
548
+
549
+ sage: var('x, n')
550
+ (x, n)
551
+ sage: integral(x^n,x)
552
+ Traceback (most recent call last):
553
+ ...
554
+ ValueError: Computation failed since Maxima requested additional
555
+ constraints; using the 'assume' command before evaluation
556
+ *may* help (example of legal syntax is 'assume(n>0)', see `assume?`
557
+ for more details)
558
+ Is n equal to -1?
559
+ sage: assume(n > 0)
560
+ sage: integral(x^n,x)
561
+ x^(n + 1)/(n + 1)
562
+ sage: forget()
563
+
564
+ Usually the constraints are of sign, but others are possible::
565
+
566
+ sage: assume(n==-1)
567
+ sage: integral(x^n,x)
568
+ log(x)
569
+
570
+ Note that an exception is raised when a definite integral is
571
+ divergent::
572
+
573
+ sage: forget() # always remember to forget assumptions you no longer need
574
+ sage: integrate(1/x^3,(x,0,1))
575
+ Traceback (most recent call last):
576
+ ...
577
+ ValueError: Integral is divergent.
578
+ sage: integrate(1/x^3,x,-1,3)
579
+ Traceback (most recent call last):
580
+ ...
581
+ ValueError: Integral is divergent.
582
+
583
+ But Sage can calculate the convergent improper integral of
584
+ this function::
585
+
586
+ sage: integrate(1/x^3,x,1,infinity)
587
+ 1/2
588
+
589
+ The examples in the Maxima documentation::
590
+
591
+ sage: var('x, y, z, b')
592
+ (x, y, z, b)
593
+ sage: integral(sin(x)^3, x)
594
+ 1/3*cos(x)^3 - cos(x)
595
+ sage: integral(x/sqrt(b^2-x^2), b)
596
+ x*log(2*b + 2*sqrt(b^2 - x^2))
597
+ sage: integral(x/sqrt(b^2-x^2), x)
598
+ -sqrt(b^2 - x^2)
599
+ sage: integral(cos(x)^2 * exp(x), x, 0, pi)
600
+ 3/5*e^pi - 3/5
601
+ sage: integral(x^2 * exp(-x^2), x, -oo, oo)
602
+ 1/2*sqrt(pi)
603
+
604
+ We integrate the same function in both Mathematica and Sage (via
605
+ Maxima)::
606
+
607
+ sage: _ = var('x, y, z')
608
+ sage: f = sin(x^2) + y^z
609
+ sage: g = mathematica(f) # optional - mathematica
610
+ sage: print(g) # optional - mathematica
611
+ z 2
612
+ y + Sin[x ]
613
+ sage: print(g.Integrate(x)) # optional - mathematica
614
+ z Pi 2
615
+ x y + Sqrt[--] FresnelS[Sqrt[--] x]
616
+ 2 Pi
617
+ sage: print(f.integral(x))
618
+ x*y^z + 1/16*sqrt(pi)*((I + 1)*sqrt(2)*erf((1/2*I + 1/2)*sqrt(2)*x)
619
+ + (I - 1)*sqrt(2)*erf((1/2*I - 1/2)*sqrt(2)*x)
620
+ - (I - 1)*sqrt(2)*erf(sqrt(-I)*x)
621
+ + (I + 1)*sqrt(2)*erf((-1)^(1/4)*x))
622
+
623
+ Alternatively, just use algorithm='mathematica_free' to integrate via Mathematica
624
+ over the internet (does NOT require a Mathematica license!)::
625
+
626
+ sage: _ = var('x, y, z') # optional - internet
627
+ sage: f = sin(x^2) + y^z # optional - internet
628
+ sage: f.integrate(x, algorithm='mathematica_free') # optional - internet
629
+ x*y^z + sqrt(1/2)*sqrt(pi)*fresnel_sin(sqrt(2)*x/sqrt(pi))
630
+
631
+ We can also use Sympy::
632
+
633
+ sage: integrate(x*sin(log(x)), x)
634
+ -1/5*x^2*(cos(log(x)) - 2*sin(log(x)))
635
+ sage: integrate(x*sin(log(x)), x, algorithm='sympy') # needs sympy
636
+ -1/5*x^2*cos(log(x)) + 2/5*x^2*sin(log(x))
637
+ sage: _ = var('y, z')
638
+ sage: (x^y - z).integrate(y)
639
+ -y*z + x^y/log(x)
640
+ sage: (x^y - z).integrate(y, algorithm='sympy') # needs sympy
641
+ -y*z + cases(((log(x) != 0, x^y/log(x)), (1, y)))
642
+
643
+ We integrate the above function in Maple now::
644
+
645
+ sage: g = maple(f); g.sort() # optional - maple
646
+ y^z+sin(x^2)
647
+ sage: g.integrate(x).sort() # optional - maple
648
+ x*y^z+1/2*2^(1/2)*Pi^(1/2)*FresnelS(2^(1/2)/Pi^(1/2)*x)
649
+
650
+ We next integrate a function with no closed form integral. Notice
651
+ that the answer comes back as an expression that contains an
652
+ integral itself. ::
653
+
654
+ sage: A = integral(1/ ((x-4) * (x^4+x+1)), x); A
655
+ integrate(1/((x^4 + x + 1)*(x - 4)), x)
656
+
657
+ Sometimes, in this situation, using the algorithm "maxima"
658
+ gives instead a partially integrated answer::
659
+
660
+ sage: integral(1/(x**7-1),x,algorithm='maxima')
661
+ -1/7*integrate((x^5 + 2*x^4 + 3*x^3 + 4*x^2 + 5*x + 6)/(x^6 + x^5 + x^4 + x^3 + x^2 + x + 1), x) + 1/7*log(x - 1)
662
+
663
+ We now show that floats are not converted to rationals
664
+ automatically since we by default have keepfloat: true in maxima.
665
+
666
+ ::
667
+
668
+ sage: integral(e^(-x^2),(x, 0, 0.1))
669
+ 0.05623145800914245*sqrt(pi)
670
+
671
+ An example of an integral that fricas can integrate::
672
+
673
+ sage: f(x) = sqrt(x+sqrt(1+x^2))/x
674
+ sage: integrate(f(x), x, algorithm='fricas') # optional - fricas
675
+ 2*sqrt(x + sqrt(x^2 + 1)) - 2*arctan(sqrt(x + sqrt(x^2 + 1)))
676
+ - log(sqrt(x + sqrt(x^2 + 1)) + 1) + log(sqrt(x + sqrt(x^2 + 1)) - 1)
677
+
678
+ where the default integrator obtains another answer::
679
+
680
+ sage: integrate(f(x), x) # long time
681
+ 1/8*sqrt(x)*gamma(1/4)*gamma(-1/4)^2*hypergeometric((-1/4, -1/4, 1/4),
682
+ (1/2, 3/4),
683
+ -1/x^2)/(pi*gamma(3/4))
684
+
685
+ The following definite integral is not found by maxima::
686
+
687
+ sage: f(x) = (x^4 - 3*x^2 + 6) / (x^6 - 5*x^4 + 5*x^2 + 4)
688
+ sage: integrate(f(x), x, 1, 2, algorithm='maxima')
689
+ integrate((x^4 - 3*x^2 + 6)/(x^6 - 5*x^4 + 5*x^2 + 4), x, 1, 2)
690
+
691
+ but is nevertheless computed::
692
+
693
+ sage: integrate(f(x), x, 1, 2)
694
+ -1/2*pi + arctan(8) + arctan(5) + arctan(2) + arctan(1/2)
695
+
696
+ Both fricas and sympy give the correct result::
697
+
698
+ sage: integrate(f(x), x, 1, 2, algorithm='fricas') # optional - fricas
699
+ -1/2*pi + arctan(8) + arctan(5) + arctan(2) + arctan(1/2)
700
+ sage: integrate(f(x), x, 1, 2, algorithm='sympy') # needs sympy
701
+ -1/2*pi + arctan(8) + arctan(5) + arctan(2) + arctan(1/2)
702
+
703
+ Using Giac to integrate the absolute value of a trigonometric
704
+ expression. If Giac is installed, this will be attempted
705
+ automatically in the event that Maxima is unable to integrate the
706
+ expression::
707
+
708
+ sage: # needs sage.libs.giac
709
+ sage: result = integrate(abs(cos(x)), x, 0, 2*pi, algorithm='giac')
710
+ ...
711
+ sage: result
712
+ 4
713
+ sage: result = integrate(abs(cos(x)), x, 0, 2*pi)
714
+ ...
715
+ sage: result
716
+ 4
717
+
718
+ ALIASES: integral() and integrate() are the same.
719
+
720
+ EXAMPLES:
721
+
722
+ Here is an example where we have to use assume::
723
+
724
+ sage: a,b = var('a,b')
725
+ sage: integrate(1/(x^3 *(a+b*x)^(1/3)), x)
726
+ Traceback (most recent call last):
727
+ ...
728
+ ValueError: Computation failed since Maxima requested additional
729
+ constraints; using the 'assume' command before evaluation
730
+ *may* help (example of legal syntax is 'assume(a>0)', see `assume?`
731
+ for more details)
732
+ Is a positive or negative?
733
+
734
+ So we just assume that `a>0` and the integral works::
735
+
736
+ sage: assume(a>0)
737
+ sage: integrate(1/(x^3 *(a+b*x)^(1/3)), x)
738
+ 2/9*sqrt(3)*b^2*arctan(1/3*sqrt(3)*(2*(b*x + a)^(1/3) + a^(1/3))/a^(1/3))/a^(7/3)
739
+ - 1/9*b^2*log((b*x + a)^(2/3) + (b*x + a)^(1/3)*a^(1/3) + a^(2/3))/a^(7/3)
740
+ + 2/9*b^2*log((b*x + a)^(1/3) - a^(1/3))/a^(7/3) + 1/6*(4*(b*x + a)^(5/3)*b^2
741
+ - 7*(b*x + a)^(2/3)*a*b^2)/((b*x + a)^2*a^2 - 2*(b*x + a)*a^3 + a^4)
742
+
743
+ TESTS:
744
+
745
+ The following integral was broken prior to Maxima 5.15.0 -
746
+ see :issue:`3013`::
747
+
748
+ sage: integrate(sin(x)*cos(10*x)*log(x), x)
749
+ -1/198*(9*cos(11*x) - 11*cos(9*x))*log(x) + 1/44*Ei(11*I*x) - 1/36*Ei(9*I*x) - 1/36*Ei(-9*I*x) + 1/44*Ei(-11*I*x)
750
+
751
+ It is no longer possible to use certain functions without an
752
+ explicit variable. Instead, evaluate the function at a variable,
753
+ and then take the integral::
754
+
755
+ sage: integrate(sin)
756
+ Traceback (most recent call last):
757
+ ...
758
+ TypeError: unable to convert sin to a symbolic expression
759
+
760
+ sage: integrate(sin(x), x)
761
+ -cos(x)
762
+ sage: integrate(sin(x), x, 0, 1)
763
+ -cos(1) + 1
764
+
765
+ Check if :issue:`780` is fixed::
766
+
767
+ sage: _ = var('x,y')
768
+ sage: f = log(x^2+y^2)
769
+ sage: res = integral(f,x,1414/10^7, 1); res
770
+ Traceback (most recent call last):
771
+ ...
772
+ ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help ...
773
+ Is ... positive, negative or zero?
774
+ sage: assume(y>1)
775
+ sage: res = integral(f,x,1414/10^7, 1); res
776
+ -2*y*arctan(707/5000000/y) + 2*y*arctan(1/y) + log(y^2 + 1) - 707/5000000*log(y^2 + 499849/25000000000000) - 4999293/2500000
777
+ sage: nres = numerical_integral(f.subs(y=2), 0.0001414, 1.); nres
778
+ (1.4638323264144..., 1.6251803529759...e-14)
779
+ sage: res.subs(y=2).n()
780
+ 1.46383232641443
781
+ sage: nres = numerical_integral(f.subs(y=.5), 0.0001414, 1.); nres
782
+ (-0.669511708872807, 7.768678110854711e-15)
783
+ sage: res.subs(y=.5).n()
784
+ -0.669511708872807
785
+
786
+ Check if :issue:`6816` is fixed::
787
+
788
+ sage: var('t,theta')
789
+ (t, theta)
790
+ sage: integrate(t*cos(-theta*t),t,0,pi)
791
+ (pi*theta*sin(pi*theta) + cos(pi*theta))/theta^2 - 1/theta^2
792
+ sage: integrate(t*cos(-theta*t),(t,0,pi))
793
+ (pi*theta*sin(pi*theta) + cos(pi*theta))/theta^2 - 1/theta^2
794
+ sage: integrate(t*cos(-theta*t),t)
795
+ (t*theta*sin(t*theta) + cos(t*theta))/theta^2
796
+ sage: integrate(x^2,(x)) # this worked before
797
+ 1/3*x^3
798
+ sage: integrate(x^2,(x,)) # this didn't
799
+ 1/3*x^3
800
+ sage: integrate(x^2,(x,1,2))
801
+ 7/3
802
+ sage: integrate(x^2,(x,1,2,3))
803
+ Traceback (most recent call last):
804
+ ...
805
+ TypeError: invalid input (x, 1, 2, 3) - please use variable, with or without two endpoints
806
+
807
+ Note that this used to be the test, but it is actually divergent
808
+ (Maxima currently asks for assumptions on theta)::
809
+
810
+ sage: integrate(t*cos(-theta*t),(t,-oo,oo))
811
+ Traceback (most recent call last):
812
+ ...
813
+ ValueError: Computation failed since Maxima requested additional constraints;...
814
+
815
+ Check if :issue:`6189` is fixed::
816
+
817
+ sage: n = N; n
818
+ <function numerical_approx at ...>
819
+ sage: F(x) = 1/sqrt(2*pi*1^2)*exp(-1/(2*1^2)*(x-0)^2)
820
+ sage: G(x) = 1/sqrt(2*pi*n(1)^2)*exp(-1/(2*n(1)^2)*(x-n(0))^2)
821
+ sage: integrate( (F(x)-F(x))^2, x, -infinity, infinity).n()
822
+ 0.000000000000000
823
+ sage: integrate( ((F(x)-G(x))^2).expand(), x, -infinity, infinity).n()
824
+ -6.26376265908397e-17
825
+ sage: integrate( (F(x)-G(x))^2, x, -infinity, infinity).n()# abstol 1e-6
826
+ 0
827
+
828
+ This was broken before Maxima 5.20::
829
+
830
+ sage: exp(-x*i).integral(x,0,1)
831
+ I*e^(-I) - I
832
+
833
+ Test that :issue:`8729` is fixed::
834
+
835
+ sage: t = var('t')
836
+ sage: a = sqrt((sin(t))^2 + (cos(t))^2)
837
+ sage: integrate(a, t, 0, 2*pi)
838
+ 2*pi
839
+ sage: a.simplify_full().simplify_trig()
840
+ 1
841
+
842
+ Maxima uses Cauchy Principal Value calculations to
843
+ integrate certain convergent integrals. Here we test
844
+ that this does not raise an error message (see :issue:`11987`)::
845
+
846
+ sage: integrate(sin(x)*sin(x/3)/x^2, x, 0, oo)
847
+ 1/6*pi
848
+
849
+ Maxima returned a negative value for this integral prior to
850
+ maxima-5.24 (:issue:`10923`). Ideally we would get an answer in terms
851
+ of the gamma function; however, we get something equivalent::
852
+
853
+ sage: actual_result = integral(e^(-1/x^2), x, 0, 1)
854
+ sage: actual_result.canonicalize_radical()
855
+ (sqrt(pi)*(erf(1)*e - e) + 1)*e^(-1)
856
+ sage: ideal_result = 1/2*gamma(-1/2, 1)
857
+ sage: error = actual_result - ideal_result
858
+ sage: error.numerical_approx() # abs tol 1e-10
859
+ 0
860
+
861
+ We will get a correct answer here, which is better than
862
+ the previous (wrong) answer of zero. See :issue:`10914`::
863
+
864
+ sage: f = abs(sin(x))
865
+ sage: result = integrate(f, x, 0, 2*pi)
866
+ ...
867
+ sage: result
868
+ 4
869
+
870
+ Another incorrect integral fixed upstream in Maxima, from
871
+ :issue:`11233`::
872
+
873
+ sage: a,t = var('a,t')
874
+ sage: assume(a>0)
875
+ sage: assume(x>0)
876
+ sage: f = log(1 + a/(x * t)^2)
877
+ sage: F = integrate(f, t, 1, Infinity)
878
+ sage: F(x=1, a=7).numerical_approx() # abs tol 1e-10
879
+ 4.32025625668262
880
+ sage: forget()
881
+
882
+ Verify that MinusInfinity works with sympy (:issue:`12345`)::
883
+
884
+ sage: integral(1/x^2, x, -infinity, -1, algorithm='sympy') # needs sympy
885
+ 1
886
+
887
+ Check that :issue:`11737` is fixed::
888
+
889
+ sage: N(integrate(sin(x^2)/(x^2), x, 1, infinity), prec=54)
890
+ 0.285736646322853
891
+ sage: N(integrate(sin(x^2)/(x^2), x, 1, infinity)) # known bug (nonzero imag part)
892
+ 0.285736646322853
893
+
894
+ Check that :issue:`14209` is fixed::
895
+
896
+ sage: integral(e^(-abs(x))/cosh(x),x,-infinity,infinity)
897
+ 2*log(2)
898
+ sage: integral(e^(-abs(x))/cosh(x),x,-infinity,infinity)
899
+ 2*log(2)
900
+
901
+ Check that :issue:`12628` is fixed::
902
+
903
+ sage: var('z,n')
904
+ (z, n)
905
+ sage: f(z, n) = sin(n*z) / (n*z)
906
+ sage: integrate(f(z,1)*f(z,3)*f(z,5)*f(z,7),z,0,oo)
907
+ 22/315*pi
908
+ sage: for k in srange(1, 16, 2):
909
+ ....: print(integrate(prod(f(z, ell)
910
+ ....: for ell in srange(1, k+1, 2)), z, 0, oo))
911
+ 1/2*pi
912
+ 1/6*pi
913
+ 1/10*pi
914
+ 22/315*pi
915
+ 3677/72576*pi
916
+ 48481/1247400*pi
917
+ 193359161/6227020800*pi
918
+ 5799919/227026800*pi
919
+
920
+ Check that :issue:`12628` is fixed::
921
+
922
+ sage: integrate(1/(sqrt(x)*((1+sqrt(x))^2)),x,1,9)
923
+ 1/2
924
+
925
+ Check that :issue:`8728` is fixed::
926
+
927
+ sage: forget()
928
+ sage: c,w,T = var('c,w,T')
929
+ sage: assume(1-c^2 > 0)
930
+ sage: assume(abs(c) - sqrt(1-c^2) - 1 > 0)
931
+ sage: assume(abs(sqrt(1-c^2)-1) - abs(c) > 0)
932
+ sage: integrate(cos(w+T) / (1+c*cos(T))^2, T, 0, 2*pi)
933
+ 2*pi*sqrt(-c^2 + 1)*c*cos(w)/(c^4 - 2*c^2 + 1)
934
+
935
+ Check that :issue:`13733` is fixed (but the bug reappeared, see :issue:`30063`)::
936
+
937
+ sage: a = integral(log(cot(x) - 1), x, 0, pi/4); a # long time (about 6 s) # known bug
938
+ -1/4*pi*log(2) - 1/2*I*dilog(I + 1) + 1/2*I*dilog(-I + 1) + 1/2*I*dilog(1/2*I + 1/2) - 1/2*I*dilog(-1/2*I + 1/2)
939
+ sage: abs(N(a - pi*log(2)/8)) < 1e-15 # long time # known bug
940
+ True
941
+
942
+ Check that :issue:`17968` is fixed::
943
+
944
+ sage: a = N(integrate(exp(x^3), (x, 1, 2)), prec=54)
945
+ sage: a.real_part() # abs tol 1e-13
946
+ 275.510983763312
947
+ sage: a.imag_part() # abs tol 1e-13
948
+ 0.0
949
+
950
+ This used to be solved by the ``abs_integrate`` Maxima package
951
+ but can be solved now without it::
952
+
953
+ sage: integrate(abs(x), x)
954
+ 1/2*x*abs(x)
955
+ sage: integral(abs(cos(x))*sin(x),(x,pi/2,pi))
956
+ 1/2
957
+ sage: f = (x^2)*exp(x) / (1+exp(x))^2
958
+ sage: integrate(f, (x, -infinity, infinity))
959
+ 1/3*pi^2
960
+
961
+ Some integrals are now working (:issue:`27958`, using giac or sympy)::
962
+
963
+ sage: result = integrate(abs(x^2 - 1), x, -2, 2)
964
+ ...
965
+ sage: result
966
+ 4
967
+
968
+ sage: result = integrate(sgn(x) - sgn(1-x), x)
969
+ ...
970
+ sage: result
971
+ abs(x - 1) + abs(x)
972
+
973
+ sage: result = integrate(1 / (1 + abs(x-5)), x, -5, 6)
974
+ ...
975
+ sage: result
976
+ log(11) + log(2)
977
+
978
+ sage: result = integrate(abs(x^2 - 1), x, -2, 2)
979
+ ...
980
+ sage: result
981
+ 4
982
+
983
+ Examples that only giac can correctly integrate (for now)::
984
+
985
+ sage: # needs sage.libs.giac
986
+ sage: g = abs(sin(x)*cos(x))
987
+ sage: result = g.integrate(x, 0, 2*pi)
988
+ ...
989
+ sage: result
990
+ 2
991
+
992
+ ::
993
+
994
+ sage: # needs sage.libs.giac
995
+ sage: f = sqrt(x + 1/x^2)
996
+ sage: actual = integrate(f, x)
997
+ ...
998
+ sage: expected = (1/3*(2*sqrt(x^3 + 1) - log(sqrt(x^3 + 1) + 1)
999
+ ....: + log(abs(sqrt(x^3 + 1) - 1)))*sgn(x))
1000
+ sage: bool(actual == expected)
1001
+ True
1002
+
1003
+ ::
1004
+
1005
+ sage: # needs sage.libs.giac
1006
+ sage: result = integrate(cos(x + abs(x)), x)
1007
+ ...
1008
+ sage: result
1009
+ sin(x*sgn(x) + x)/(sgn(x) + 1)
1010
+
1011
+ ::
1012
+
1013
+ sage: # needs sage.libs.giac
1014
+ sage: result = integrate(1/(1 + abs(x)), x)
1015
+ ...
1016
+ sage: result
1017
+ log(abs(x*sgn(x) + 1))/sgn(x)
1018
+
1019
+ ::
1020
+
1021
+ sage: # needs sage.libs.giac
1022
+ sage: result = integrate(1/sqrt(abs(x)), x)
1023
+ ...
1024
+ sage: result
1025
+ 2*sqrt(x*sgn(x))/sgn(x)
1026
+
1027
+ ::
1028
+
1029
+ sage: # needs sage.libs.giac
1030
+ sage: result = integrate(1/(1 + abs(x)), x)
1031
+ ...
1032
+ sage: result
1033
+ log(abs(x*sgn(x) + 1))/sgn(x)
1034
+
1035
+ ::
1036
+
1037
+ sage: # needs sage.libs.giac
1038
+ sage: result = integrate(cos(x + abs(x)), x)
1039
+ ...
1040
+ sage: result
1041
+ sin(x*sgn(x) + x)/(sgn(x) + 1)
1042
+
1043
+ Some tests for :issue:`17468`::
1044
+
1045
+ sage: integral(log(abs(2*sin(x))), x, 0, pi/3)
1046
+ 1/36*I*pi^2 + I*dilog(1/2*I*sqrt(3) + 1/2) + I*dilog(-1/2*I*sqrt(3) - 1/2)
1047
+ sage: integral(log(abs(sin(x))), x, 0, pi/2)
1048
+ -1/2*pi*log(2)
1049
+
1050
+ Check that :issue:`25823` is fixed::
1051
+
1052
+ sage: f = log(sin(x))*sin(x)^2
1053
+ sage: g = integrate(f, x) ; g
1054
+ 1/4*I*x^2
1055
+ - 1/2*I*x*arctan2(sin(x), cos(x) + 1)
1056
+ + 1/2*I*x*arctan2(sin(x), -cos(x) + 1)
1057
+ - 1/4*x*log(cos(x)^2 + sin(x)^2 + 2*cos(x) + 1)
1058
+ - 1/4*x*log(cos(x)^2 + sin(x)^2 - 2*cos(x) + 1)
1059
+ + 1/4*(2*x - sin(2*x))*log(sin(x))
1060
+ + 1/4*x
1061
+ + 1/2*I*dilog(-e^(I*x))
1062
+ + 1/2*I*dilog(e^(I*x)) + 1/8*sin(2*x)
1063
+
1064
+ Indeed::
1065
+
1066
+ sage: (g.derivative() - f).full_simplify().full_simplify()
1067
+ 0
1068
+
1069
+ Test for :issue:`24117`::
1070
+
1071
+ sage: integrate(sqrt(1-4*sin(x)^2),x, algorithm='maxima')
1072
+ integrate(sqrt(-4*sin(x)^2 + 1), x)
1073
+
1074
+ Check that :issue:`30353` is fixed::
1075
+
1076
+ sage: a = SR.var('a')
1077
+ sage: assume(a > 0)
1078
+ sage: assume(a < 1)
1079
+ sage: integrate(x*log(1/(a*x+(1-x)^2)), x, 0, 1, algorithm='maxima')
1080
+ 1/4*a^2*log(a) + 1/2*sqrt(-a^2 + 4*a)*a*arctan(sqrt(-a^2 + 4*a)*(a - 2)/(a^2 - 4*a)) - 1/2*sqrt(-a^2 + 4*a)*a*arctan(sqrt(-a^2 + 4*a)/(a - 4)) - a*log(a) - sqrt(-a^2 + 4*a)*arctan(sqrt(-a^2 + 4*a)*(a - 2)/(a^2 - 4*a)) + sqrt(-a^2 + 4*a)*arctan(sqrt(-a^2 + 4*a)/(a - 4)) - 1/2*a + 3/2
1081
+
1082
+ Check that :issue:`25905` is fixed::
1083
+
1084
+ sage: var('a d x c')
1085
+ (a, d, x, c)
1086
+ sage: f = (I*a*tan(d*x + c) + a)^3*tan(d*x + c)
1087
+ sage: integrate(f, x, algorithm='fricas') # optional - fricas
1088
+ -2/3*(24*a^3*e^(4*I*d*x + 4*I*c) + 33*a^3*e^(2*I*d*x + 2*I*c) + 13*a^3 + 6*(a^3*e^(6*I*d*x + 6*I*c) + 3*a^3*e^(4*I*d*x + 4*I*c) + 3*a^3*e^(2*I*d*x + 2*I*c) + a^3)*log(e^(2*I*d*x + 2*I*c) + 1))/(d*e^(6*I*d*x + 6*I*c) + 3*d*e^(4*I*d*x + 4*I*c) + 3*d*e^(2*I*d*x + 2*I*c) + d)
1089
+
1090
+ The fundamental theorem of calculus holds for elliptic integrals
1091
+ of the second kind, :issue:`26563`::
1092
+
1093
+ sage: x,m = SR.var('x,m', domain='real') # long time
1094
+ sage: integrate(elliptic_e(x,m).diff(x), x) # long time
1095
+ elliptic_e(x, m)
1096
+
1097
+ Check that :issue:`20467` is fixed::
1098
+
1099
+ sage: k = var('k')
1100
+ sage: integral(sin(k*x)/x*erf(x^2), x, 0, oo, algorithm='maxima')
1101
+ integrate(erf(x^2)*sin(k*x)/x, x, 0, +Infinity)
1102
+ """
1103
+ expression, v, a, b = _normalize_integral_input(expression, v, a, b)
1104
+ if algorithm is not None:
1105
+ integrator = available_integrators.get(algorithm)
1106
+ if not integrator:
1107
+ raise ValueError("Unknown algorithm: %s" % algorithm)
1108
+ return integrator(expression, v, a, b)
1109
+ if a is None:
1110
+ return indefinite_integral(expression, v, hold=hold)
1111
+ else:
1112
+ return definite_integral(expression, v, a, b, hold=hold)
1113
+
1114
+
1115
+ integral = integrate