Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/symbolic/integration/integral.py
4079 views
1
"""
2
Symbolic Integration
3
"""
4
5
##############################################################################
6
#
7
# Copyright (C) 2009 Golam Mortuza Hossain <[email protected]>
8
# Copyright (C) 2010 Burcin Erocal <[email protected]>
9
#
10
# Distributed under the terms of the GNU General Public License (GPL v2+)
11
# http://www.gnu.org/licenses/
12
#
13
##############################################################################
14
15
from sage.symbolic.ring import SR, is_SymbolicVariable
16
from sage.symbolic.function import BuiltinFunction, Function
17
18
##################################################################
19
# Table of available integration routines
20
##################################################################
21
22
# Add new integration routines to the dictionary below. This will make them
23
# accessible with the 'algorithm' keyword parameter of top level integrate().
24
available_integrators = {}
25
26
import sage.symbolic.integration.external as external
27
available_integrators['maxima'] = external.maxima_integrator
28
available_integrators['sympy'] = external.sympy_integrator
29
available_integrators['mathematica_free'] = external.mma_free_integrator
30
31
######################################################
32
#
33
# Class implementing symbolic integration
34
#
35
######################################################
36
37
class IndefiniteIntegral(BuiltinFunction):
38
def __init__(self):
39
"""
40
Class to represent an indefinite integral.
41
42
EXAMPLES::
43
44
sage: from sage.symbolic.integration.integral import indefinite_integral
45
sage: indefinite_integral(log(x), x) #indirect doctest
46
x*log(x) - x
47
sage: indefinite_integral(x^2, x)
48
1/3*x^3
49
sage: indefinite_integral(4*x*log(x), x)
50
2*x^2*log(x) - x^2
51
sage: indefinite_integral(exp(x), 2*x)
52
2*e^x
53
54
"""
55
# The automatic evaluation routine will try these integrators
56
# in the given order. This is an attribute of the class instead of
57
# a global variable in this module to enable customization by
58
# creating a subclasses which define a different set of integrators
59
self.integrators = [external.maxima_integrator]
60
61
BuiltinFunction.__init__(self, "integrate", nargs=2)
62
63
def _eval_(self, f, x):
64
"""
65
EXAMPLES::
66
67
sage: from sage.symbolic.integration.integral import indefinite_integral
68
sage: indefinite_integral(exp(x), x) # indirect doctest
69
e^x
70
sage: indefinite_integral(exp(x), x^2)
71
2*(x - 1)*e^x
72
"""
73
# Check for x
74
if not is_SymbolicVariable(x):
75
if len(x.variables()) == 1:
76
nx = x.variables()[0]
77
f = f*x.diff(nx)
78
x = nx
79
else:
80
return None
81
82
# we try all listed integration algorithms
83
for integrator in self.integrators:
84
res = integrator(f, x)
85
try:
86
return integrator(f, x)
87
except NotImplementedError:
88
pass
89
return None
90
91
def _tderivative_(self, f, x, diff_param=None):
92
"""
93
EXAMPLES::
94
95
sage: from sage.symbolic.integration.integral import indefinite_integral
96
sage: f = function('f'); a,b=var('a,b')
97
sage: h = indefinite_integral(f(x), x)
98
sage: h.diff(x) # indirect doctest
99
f(x)
100
sage: h.diff(a)
101
0
102
"""
103
if x.has(diff_param):
104
return f*x.derivative(diff_param)
105
else:
106
return f.derivative(diff_param).integral(x)
107
108
def _print_latex_(self, f, x):
109
"""
110
EXAMPLES::
111
112
sage: from sage.symbolic.integration.integral import indefinite_integral
113
sage: print_latex = indefinite_integral._print_latex_
114
sage: var('x,a,b')
115
(x, a, b)
116
sage: f = function('f')
117
sage: print_latex(f(x),x)
118
'\\int f\\left(x\\right)\\,{d x}'
119
"""
120
from sage.misc.latex import latex
121
if not is_SymbolicVariable(x):
122
dx_str = "{d \\left(%s\\right)}"%(latex(x))
123
else:
124
dx_str = "{d %s}"%(latex(x))
125
126
return "\\int %s\\,%s"%(latex(f), dx_str)
127
128
indefinite_integral = IndefiniteIntegral()
129
130
class DefiniteIntegral(BuiltinFunction):
131
def __init__(self):
132
"""
133
Symbolic function representing a definite integral.
134
135
EXAMPLES::
136
137
sage: from sage.symbolic.integration.integral import definite_integral
138
sage: definite_integral(sin(x),x,0,pi)
139
2
140
"""
141
# The automatic evaluation routine will try these integrators
142
# in the given order. This is an attribute of the class instead of
143
# a global variable in this module to enable customization by
144
# creating a subclasses which define a different set of integrators
145
self.integrators = [external.maxima_integrator]
146
147
BuiltinFunction.__init__(self, "integrate", nargs=4)
148
149
def _eval_(self, f, x, a, b):
150
"""
151
Returns the results of symbolic evaluation of the integral
152
153
EXAMPLES::
154
155
sage: from sage.symbolic.integration.integral import definite_integral
156
sage: definite_integral(exp(x),x,0,1) # indirect doctest
157
e - 1
158
"""
159
# Check for x
160
if not is_SymbolicVariable(x):
161
if len(x.variables()) == 1:
162
nx = x.variables()[0]
163
f = f*x.diff(nx)
164
x = nx
165
else:
166
return None
167
168
args = (f,x,a,b)
169
170
# we try all listed integration algorithms
171
for integrator in self.integrators:
172
try:
173
return integrator(*args)
174
except NotImplementedError:
175
pass
176
return None
177
178
def _evalf_(self, f, x, a, b, parent=None):
179
"""
180
Returns numerical approximation of the integral
181
182
EXAMPLES::
183
184
sage: from sage.symbolic.integration.integral import definite_integral
185
sage: h = definite_integral(sin(x)*log(x)/x^2, x, 1, 2); h
186
integrate(log(x)*sin(x)/x^2, x, 1, 2)
187
sage: h.n() # indirect doctest
188
0.14839875208053...
189
190
TESTS:
191
192
Check if #3863 is fixed::
193
194
sage: integrate(x^2.7 * e^(-2.4*x), x, 0, 3).n()
195
0.154572952320790
196
"""
197
from sage.gsl.integration import numerical_integral
198
# The gsl routine returns a tuple, which also contains the error.
199
# We only return the result.
200
return numerical_integral(f, a, b)[0]
201
202
def _tderivative_(self, f, x, a, b, diff_param=None):
203
"""
204
Returns derivative of symbolic integration
205
206
EXAMPLES::
207
208
sage: from sage.symbolic.integration.integral import definite_integral
209
sage: f = function('f'); a,b=var('a,b')
210
sage: h = definite_integral(f(x), x,a,b)
211
sage: h.diff(x) # indirect doctest
212
0
213
sage: h.diff(a)
214
-f(a)
215
sage: h.diff(b)
216
f(b)
217
"""
218
if not x.has(diff_param):
219
# integration variable != differentiation variable
220
ans = definite_integral(f.diff(diff_param), x, a, b)
221
else:
222
ans = SR(0)
223
return ans + f.subs(x==b)*b.diff(diff_param) \
224
- f.subs(x==a)*a.diff(diff_param)
225
226
def _print_latex_(self, f, x, a, b):
227
r"""
228
Returns LaTeX expression for integration of a symbolic function.
229
230
EXAMPLES::
231
232
sage: from sage.symbolic.integration.integral import definite_integral
233
sage: print_latex = definite_integral._print_latex_
234
sage: var('x,a,b')
235
(x, a, b)
236
sage: f = function('f')
237
sage: print_latex(f(x),x,0,1)
238
'\\int_{0}^{1} f\\left(x\\right)\\,{d x}'
239
sage: latex(integrate(1/(1+sqrt(x)),x,0,1))
240
\int_{0}^{1} \frac{1}{\sqrt{x} + 1}\,{d x}
241
"""
242
from sage.misc.latex import latex
243
if not is_SymbolicVariable(x):
244
dx_str = "{d \\left(%s\\right)}"%(latex(x))
245
else:
246
dx_str = "{d %s}"%(latex(x))
247
return "\\int_{%s}^{%s} %s\\,%s"%(latex(a), latex(b), latex(f), dx_str)
248
249
definite_integral = DefiniteIntegral()
250
251
252
def _normalize_integral_input(f, v=None, a=None, b=None):
253
r"""
254
Validate and return variable and endpoints for an integral.
255
256
INPUT:
257
258
- ``f`` -- an expression to integrate;
259
260
- ``v`` -- a variable of integration or a triple;
261
262
- ``a`` -- (optional) the left endpoint of integration;
263
264
- ``b`` -- (optional) the right endpoint of integration.
265
266
It is also possible to pass last three parameters in ``v`` as a triple.
267
268
OUPUT:
269
270
- a tuple of ``f``, ``v``, ``a``, and ``b``.
271
272
EXAMPLES::
273
274
sage: from sage.symbolic.integration.integral import \
275
... _normalize_integral_input
276
sage: _normalize_integral_input(x^2, x, 0, 3)
277
(x^2, x, 0, 3)
278
sage: _normalize_integral_input(x^2, [x, 0, 3], None, None)
279
(x^2, x, 0, 3)
280
sage: _normalize_integral_input(x^2, [0, 3], None, None)
281
doctest:...: DeprecationWarning:
282
Variable of integration should be specified explicitly.
283
(x^2, x, 0, 3)
284
sage: _normalize_integral_input(x^2, [x], None, None)
285
(x^2, x, None, None)
286
"""
287
if isinstance(v, (list, tuple)) and a is None and b is None:
288
if len(v) == 1: # bare variable in a tuple
289
v = v[0]
290
elif len(v) == 2: # endpoints only
291
a, b = v
292
v = None
293
elif len(v) == 3: # variable and endpoints
294
v, a, b = v
295
else:
296
raise ValueError("invalid input %s - please use variable, "
297
"with or without two endpoints" % repr(v))
298
elif b is None and a is not None:
299
# two arguments, must be endpoints
300
v, a, b = None, v, a
301
if v is None:
302
from sage.misc.misc import deprecation
303
deprecation("Variable of integration should be specified explicitly.")
304
v = f.default_variable()
305
if isinstance(f, Function): # a bare function like sin
306
f = f(v)
307
if (a is None) ^ (b is None):
308
raise TypeError('only one endpoint was given!')
309
return f, v, a, b
310
311
def integrate(expression, v=None, a=None, b=None, algorithm=None):
312
r"""
313
Returns the indefinite integral with respect to the variable
314
`v`, ignoring the constant of integration. Or, if endpoints
315
`a` and `b` are specified, returns the definite
316
integral over the interval `[a, b]`.
317
318
If ``self`` has only one variable, then it returns the
319
integral with respect to that variable.
320
321
If definite integration fails, it could be still possible to
322
evaluate the definite integral using indefinite integration with
323
the Newton - Leibniz theorem (however, the user has to ensure that the
324
indefinite integral is continuous on the compact interval `[a,b]` and
325
this theorem can be applied).
326
327
INPUT:
328
329
- ``v`` - a variable or variable name. This can also be a tuple of
330
the variable (optional) and endpoints (i.e., ``(x,0,1)`` or ``(0,1)``).
331
332
- ``a`` - (optional) lower endpoint of definite integral
333
334
- ``b`` - (optional) upper endpoint of definite integral
335
336
- ``algorithm`` - (default: 'maxima') one of
337
338
- 'maxima' - use maxima (the default)
339
340
- 'sympy' - use sympy (also in Sage)
341
342
- 'mathematica_free' - use http://integrals.wolfram.com/
343
344
EXAMPLES::
345
346
sage: x = var('x')
347
sage: h = sin(x)/(cos(x))^2
348
sage: h.integral(x)
349
1/cos(x)
350
351
::
352
353
sage: f = x^2/(x+1)^3
354
sage: f.integral(x)
355
1/2*(4*x + 3)/(x^2 + 2*x + 1) + log(x + 1)
356
357
::
358
359
sage: f = x*cos(x^2)
360
sage: f.integral(x, 0, sqrt(pi))
361
0
362
sage: f.integral(x, a=-pi, b=pi)
363
0
364
365
::
366
367
sage: f(x) = sin(x)
368
sage: f.integral(x, 0, pi/2)
369
1
370
371
The variable is required, but the endpoints are optional::
372
373
sage: y=var('y')
374
sage: integral(sin(x), x)
375
-cos(x)
376
sage: integral(sin(x), y)
377
y*sin(x)
378
sage: integral(sin(x), x, pi, 2*pi)
379
-2
380
sage: integral(sin(x), y, pi, 2*pi)
381
pi*sin(x)
382
sage: integral(sin(x), (x, pi, 2*pi))
383
-2
384
sage: integral(sin(x), (y, pi, 2*pi))
385
pi*sin(x)
386
387
Constraints are sometimes needed::
388
389
sage: var('x, n')
390
(x, n)
391
sage: integral(x^n,x)
392
Traceback (most recent call last):
393
...
394
ValueError: Computation failed since Maxima requested additional
395
constraints; using the 'assume' command before integral evaluation
396
*may* help (example of legal syntax is 'assume(n+1>0)', see `assume?`
397
for more details)
398
Is n+1 zero or nonzero?
399
sage: assume(n > 0)
400
sage: integral(x^n,x)
401
x^(n + 1)/(n + 1)
402
sage: forget()
403
404
Usually the constraints are of sign, but others are possible::
405
406
sage: assume(n==-1)
407
sage: integral(x^n,x)
408
log(x)
409
410
Note that an exception is raised when a definite integral is
411
divergent::
412
413
sage: forget() # always remember to forget assumptions you no longer need
414
sage: integrate(1/x^3,(x,0,1))
415
Traceback (most recent call last):
416
...
417
ValueError: Integral is divergent.
418
sage: integrate(1/x^3,x,-1,3)
419
Traceback (most recent call last):
420
...
421
ValueError: Integral is divergent.
422
423
But Sage can calculate the convergent improper integral of
424
this function::
425
426
sage: integrate(1/x^3,x,1,infinity)
427
1/2
428
429
The examples in the Maxima documentation::
430
431
sage: var('x, y, z, b')
432
(x, y, z, b)
433
sage: integral(sin(x)^3, x)
434
1/3*cos(x)^3 - cos(x)
435
sage: integral(x/sqrt(b^2-x^2), b)
436
x*log(2*b + 2*sqrt(b^2 - x^2))
437
sage: integral(x/sqrt(b^2-x^2), x)
438
-sqrt(b^2 - x^2)
439
sage: integral(cos(x)^2 * exp(x), x, 0, pi)
440
3/5*e^pi - 3/5
441
sage: integral(x^2 * exp(-x^2), x, -oo, oo)
442
1/2*sqrt(pi)
443
444
We integrate the same function in both Mathematica and Sage (via
445
Maxima)::
446
447
sage: _ = var('x, y, z')
448
sage: f = sin(x^2) + y^z
449
sage: g = mathematica(f) # optional -- requires mathematica
450
sage: print g # optional -- requires mathematica
451
z 2
452
y + Sin[x ]
453
sage: print g.Integrate(x) # optional -- requires mathematica
454
z Pi 2
455
x y + Sqrt[--] FresnelS[Sqrt[--] x]
456
2 Pi
457
sage: print f.integral(x)
458
y^z*x + 1/8*((I + 1)*sqrt(2)*erf((1/2*I + 1/2)*sqrt(2)*x) + (I - 1)*sqrt(2)*erf((1/2*I - 1/2)*sqrt(2)*x))*sqrt(pi)
459
460
Alternatively, just use algorithm='mathematica_free' to integrate via Mathematica
461
over the internet (does NOT require a Mathematica license!)::
462
463
sage: _ = var('x, y, z')
464
sage: f = sin(x^2) + y^z
465
sage: f.integrate(algorithm="mathematica_free") # optional -- requires internet
466
sqrt(pi)*sqrt(1/2)*fresnels(sqrt(2)*x/sqrt(pi)) + y^z*x
467
468
We can also use Sympy::
469
470
sage: _ = var('x, y, z')
471
sage: (x^y-z).integrate(y)
472
-y*z + x^y/log(x)
473
sage: (x^y-z).integrate(y,algorithm="sympy")
474
-y*z + x^y/log(x)
475
476
477
We integrate the above function in maple now::
478
479
sage: g = maple(f); g # optional -- requires maple
480
sin(x^2)+y^z
481
sage: g.integrate(x) # optional -- requires maple
482
1/2*2^(1/2)*Pi^(1/2)*FresnelS(2^(1/2)/Pi^(1/2)*x)+y^z*x
483
484
We next integrate a function with no closed form integral. Notice
485
that the answer comes back as an expression that contains an
486
integral itself.
487
488
::
489
490
sage: A = integral(1/ ((x-4) * (x^3+2*x+1)), x); A
491
1/73*log(x - 4) - 1/73*integrate((x^2 + 4*x + 18)/(x^3 + 2*x + 1), x)
492
493
We now show that floats are not converted to rationals
494
automatically since we by default have keepfloat: true in maxima.
495
496
::
497
498
sage: integral(e^(-x^2),(x, 0, 0.1))
499
0.0562314580091*sqrt(pi)
500
501
ALIASES: integral() and integrate() are the same.
502
503
EXAMPLES:
504
505
Here is an example where we have to use assume::
506
507
sage: a,b = var('a,b')
508
sage: integrate(1/(x^3 *(a+b*x)^(1/3)), x)
509
Traceback (most recent call last):
510
...
511
ValueError: Computation failed since Maxima requested additional
512
constraints; using the 'assume' command before integral evaluation
513
*may* help (example of legal syntax is 'assume(a>0)', see `assume?`
514
for more details)
515
Is a positive or negative?
516
517
So we just assume that `a>0` and the integral works::
518
519
sage: assume(a>0)
520
sage: integrate(1/(x^3 *(a+b*x)^(1/3)), x)
521
2/9*sqrt(3)*b^2*arctan(1/3*(2*(b*x + a)^(1/3) + a^(1/3))*sqrt(3)/a^(1/3))/a^(7/3) + 2/9*b^2*log((b*x + a)^(1/3) - a^(1/3))/a^(7/3) - 1/9*b^2*log((b*x + a)^(2/3) + (b*x + a)^(1/3)*a^(1/3) + a^(2/3))/a^(7/3) + 1/6*(4*(b*x + a)^(5/3)*b^2 - 7*(b*x + a)^(2/3)*a*b^2)/((b*x + a)^2*a^2 - 2*(b*x + a)*a^3 + a^4)
522
523
TESTS:
524
525
The following integral was broken prior to Maxima 5.15.0 -
526
see #3013::
527
528
sage: integrate(sin(x)*cos(10*x)*log(x), x)
529
1/198*(11*cos(9*x) - 9*cos(11*x))*log(x) + 1/44*Ei(-11*I*x) + 1/44*Ei(11*I*x) - 1/36*Ei(-9*I*x) - 1/36*Ei(9*I*x)
530
531
It is no longer possible to use certain functions without an
532
explicit variable. Instead, evaluate the function at a variable,
533
and then take the integral::
534
535
sage: integrate(sin)
536
Traceback (most recent call last):
537
...
538
TypeError
539
540
sage: integrate(sin(x), x)
541
-cos(x)
542
sage: integrate(sin(x), x, 0, 1)
543
-cos(1) + 1
544
545
Check if #780 is fixed::
546
547
sage: _ = var('x,y')
548
sage: f = log(x^2+y^2)
549
sage: res = integral(f,x,0.0001414, 1.); res
550
Traceback (most recent call last):
551
...
552
ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before integral evaluation *may* help (example of legal syntax is 'assume(50015104*y^2-50015103>0)', see `assume?` for more details)
553
Is 50015104*y^2-50015103 positive, negative, or zero?
554
sage: assume(y>1)
555
sage: res = integral(f,x,0.0001414, 1.); res
556
2*y*arctan(1/y) - 2*y*arctan(0.0001414/y) - 0.0001414*log(y^2 + 1.999396e-08) + log(y^2 + 1.0) - 1.9997172
557
sage: nres = numerical_integral(f.subs(y=2), 0.0001414, 1.); nres
558
(1.4638323264144..., 1.6251803529759...e-14)
559
sage: res.subs(y=2).n()
560
1.46383232641443
561
sage: nres = numerical_integral(f.subs(y=.5), 0.0001414, 1.); nres
562
(-0.669511708872807, 7.768678110854711e-15)
563
sage: res.subs(y=.5).n()
564
-0.669511708872807
565
566
Check if #6816 is fixed::
567
568
sage: var('t,theta')
569
(t, theta)
570
sage: integrate(t*cos(-theta*t),t,0,pi)
571
(pi*theta*sin(pi*theta) + cos(pi*theta))/theta^2 - 1/theta^2
572
sage: integrate(t*cos(-theta*t),(t,0,pi))
573
(pi*theta*sin(pi*theta) + cos(pi*theta))/theta^2 - 1/theta^2
574
sage: integrate(t*cos(-theta*t),t)
575
(t*theta*sin(t*theta) + cos(t*theta))/theta^2
576
sage: integrate(x^2,(x)) # this worked before
577
1/3*x^3
578
sage: integrate(x^2,(x,)) # this didn't
579
1/3*x^3
580
sage: integrate(x^2,(x,1,2))
581
7/3
582
sage: integrate(x^2,(x,1,2,3))
583
Traceback (most recent call last):
584
...
585
ValueError: invalid input (x, 1, 2, 3) - please use variable, with or without two endpoints
586
587
Note that this used to be the test, but it is
588
actually divergent (though Maxima as yet does
589
not say so)::
590
591
sage: integrate(t*cos(-theta*t),(t,-oo,oo))
592
integrate(t*cos(t*theta), t, -Infinity, +Infinity)
593
594
Check if #6189 is fixed (which, by the way, also
595
demonstrates it's not always good to expand)::
596
597
sage: n = N; n
598
<function numerical_approx at ...>
599
sage: F(x) = 1/sqrt(2*pi*1^2)*exp(-1/(2*1^2)*(x-0)^2)
600
sage: G(x) = 1/sqrt(2*pi*n(1)^2)*exp(-1/(2*n(1)^2)*(x-n(0))^2)
601
sage: integrate( (F(x)-F(x))^2, x, -infinity, infinity).n()
602
0.000000000000000
603
sage: integrate( ((F(x)-G(x))^2).expand(), x, -infinity, infinity).n()
604
-6.26376265908397e-17
605
sage: integrate( (F(x)-G(x))^2, x, -infinity, infinity).n()
606
-6.26376265908397e-17
607
608
This was broken before Maxima 5.20::
609
610
sage: exp(-x*i).integral(x,0,1)
611
I*e^(-I) - I
612
613
Test deprecation warning when variable is not specified::
614
615
sage: x.integral()
616
doctest:...: DeprecationWarning: Variable of integration should be specified explicitly.
617
1/2*x^2
618
619
Test that #8729 is fixed::
620
621
sage: t = var('t')
622
sage: a = sqrt((sin(t))^2 + (cos(t))^2)
623
sage: integrate(a, t, 0, 2*pi)
624
2*pi
625
sage: a.simplify_full().simplify_trig()
626
1
627
628
Maxima uses Cauchy Principal Value calculations to
629
integrate certain convergent integrals. Here we test
630
that this does not raise an error message (see #11987)::
631
632
sage: integrate(sin(x)*sin(x/3)/x^2, x, 0, oo)
633
1/6*pi
634
635
Maxima returned a negative value for this integral prior to
636
maxima-5.24 (trac #10923). Ideally we would get an answer in terms
637
of the gamma function; however, we get something equivalent::
638
639
sage: actual_result = integral(e^(-1/x^2), x, 0, 1)
640
sage: actual_result.full_simplify()
641
((e*erf(1) - e)*sqrt(pi) + 1)*e^(-1)
642
sage: ideal_result = 1/2*gamma(-1/2, 1)
643
sage: error = actual_result - ideal_result
644
sage: error.numerical_approx() # abs tol 1e-10
645
0
646
647
We won't get an evaluated answer here, which is better than
648
the previous (wrong) answer of zero. See :trac:`10914`::
649
650
sage: f = abs(sin(x))
651
sage: integrate(f, x, 0, 2*pi)
652
integrate(abs(sin(x)), x, 0, 2*pi)
653
654
Another incorrect integral fixed upstream in Maxima, from
655
:trac:`11233`::
656
657
sage: a,t = var('a,t')
658
sage: assume(a>0)
659
sage: assume(x>0)
660
sage: f = log(1 + a/(x * t)^2)
661
sage: F = integrate(f, t, 1, Infinity)
662
sage: F(x=1, a=7).numerical_approx() # abs tol 1e-10
663
4.32025625668262
664
665
Verify that MinusInfinity works with sympy (:trac:`12345`)::
666
667
sage: integral(1/x^2, x, -infinity, -1, algorithm='sympy')
668
1
669
670
"""
671
expression, v, a, b = _normalize_integral_input(expression, v, a, b)
672
if algorithm is not None:
673
integrator = available_integrators.get(algorithm)
674
if not integrator:
675
raise ValueError, "Unknown algorithm: %s" % algorithm
676
return integrator(expression, v, a, b)
677
if a is None:
678
return indefinite_integral(expression, v)
679
else:
680
return definite_integral(expression, v, a, b)
681
682
integral= integrate
683
684