che
01-20-08, 12:22 PM
Mathematica and the Fundamental Theorem of Calculus
January 19, 2008
Oleksandr Pavlyk, Kernel Technology
Most calculus students might think that if one could compute indefinite integrals,
it would always be easy to compute definite ones. After all, they might think, the
Fundamental Theorem of Calculus (http://mathworld.wolfram.com/FundamentalTheoremsofCalculus.html) says that one just has to subtract the values of
the indefinite integral at the end points to get the definite integral.
So how come inside Mathematica there are thousands of pages of code devoted
to working out definite integrals--beyond just subtracting indefinite ones?
The answer, as is often the case, is that in the real world of mathematical computation,
things are more complicated than one learns in basic mathematics courses.
And to get the correct answer one needs to be considerably more sophisticated.
In a simple case, subtracting indefinite integrals works just fine.
Consider computing the area under a sine curve, which equals http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_1.gif
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_2.gif
We work out the indefinite integral:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_3.gif
Then we can just subtract its value at each end point, and correctly find a definite
integral such as http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_4.gif
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_5.gif
But consider a more complicated case:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_6.gif
We can verify that this indefinite integral at least formally differentiates correctly:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_7.gif
Now let's compute the definite integral http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_8.gif by subtracting values of
our indefinite one:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_9.gif
But this cannot be correct. After all, if we plot the integrand, we can see that it is
positive throughout the range 0 to 2π:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_10.gif
Mathematica's built-in definite integration of course gives exactly the correct
answer:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_11.gif
So what went wrong with subtracting the end points? The issue is that the
Fundamental Theorem of Calculus isn't directly applicable here. Because,
when you state it fully, the theorem requires that the antiderivative that is
going to be subtracted be continuous throughout the interval.
But the antiderivative we have here looks like this:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_12.gif
It has a discontinuity right in the middle of the interval.
So how does Mathematica get its answer? It has to be more careful. Sometimes it works
by detecting discontinuities in the antiderivative, and then breaking up the integration region
into parts, and carefully taking directional limits at the discontinuity points:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_13.gif
Another thing it can do is to make use of ambiguity in the antiderivative. Every calculus
student knows that antiderivatives can contain an arbitrary additive constant. But in fact,
there's more arbitrariness than that: one can add different constants on different parts of
the interval.
Often it's not obvious from the algebraic form that one has added a piecewise
constant like this. For example, consider:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_14.gif
Differentiating this shows that it is indeed an antiderivative of the same function as above.
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_15.gif
It doesn't happen to be the antiderivative that Mathematica generates by default.
But it is a perfectly valid one. And it turns out to be continuous over the region of integration:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_16.gif
So if one uses it, one can now directly apply the Fundamental Theorem of Calculus
and get the correct result:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_17.gif
Even though their algebraic forms look different, one can verify that the antiderivatives
differ by a piecewise constant:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_18.gif
So how come Mathematica doesn't always generate the "better" antiderivative, so that
the Fundamental Theorem of Calculus applies directly?
The problem is that there's actually no way to produce an antiderivative that has
this property for all definite integrals one might want to compute. Here's the formal
situation.
The Fundamental Theorem of Calculus states that an antiderivative continuous
along a chosen path always exists. It is defined as http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_19.gif where the
integration is performed along the path. Its existence is of theoretical
importance--though in practice http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_20.gif cannot always be expressed in terms of any
predetermined set of elementary and special functions.
Moreover, if a meromorphic integrand http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_21.gif has simple poles in the complex plane,
it is impossible to choose an antiderivative http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_23.gif continuous along every
imaginable path in the complex plane--because of branch cuts in http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_23.gif.
Our integrand http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_24.gif has simple poles at http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_25.gif:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_26.gif
But now consider how our two antiderivatives behave in the complex plane.
Here are the real parts of these functions:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_27.gif
Looking on the real axis,http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_28.gif is not continuous, so the Fundamental Theorem
cannot directly be applied. But http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_29.gifs continuous, so the Fundamental Theorem will work.
However, look now at the line from http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_30.gif indicated in the picture
by a black line. Along this line,http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_31.gif is continuous, so the Fundamental
Theorem will work fine for it. But now http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_32.gif is not continuous, so the Fundamental Theorem
will not work:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_33.gif
And indeed one can show that there is no single choice of antiderivative for which
the Fundamental Theorem will always work.
So Mathematica has to go to more effort to get the correct answer for the definite
integral.
This may seem subtle--but actually it is just the tip of the iceberg of the issues that
crop up in doing definite integration correctly in Mathematica--and in mathematics.
It's the job of our group at Wolfram Research to understand all these issues and figure
out good algorithms for handling them. It's a fascinating exercise not only in algorithm
development but also in mathematics itself.
More Infos (http://blog.wolfram.com/2008/01/mathematica_and_the_fundamental_theorem_of_calculu s.html)
January 19, 2008
Oleksandr Pavlyk, Kernel Technology
Most calculus students might think that if one could compute indefinite integrals,
it would always be easy to compute definite ones. After all, they might think, the
Fundamental Theorem of Calculus (http://mathworld.wolfram.com/FundamentalTheoremsofCalculus.html) says that one just has to subtract the values of
the indefinite integral at the end points to get the definite integral.
So how come inside Mathematica there are thousands of pages of code devoted
to working out definite integrals--beyond just subtracting indefinite ones?
The answer, as is often the case, is that in the real world of mathematical computation,
things are more complicated than one learns in basic mathematics courses.
And to get the correct answer one needs to be considerably more sophisticated.
In a simple case, subtracting indefinite integrals works just fine.
Consider computing the area under a sine curve, which equals http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_1.gif
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_2.gif
We work out the indefinite integral:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_3.gif
Then we can just subtract its value at each end point, and correctly find a definite
integral such as http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_4.gif
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_5.gif
But consider a more complicated case:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_6.gif
We can verify that this indefinite integral at least formally differentiates correctly:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_7.gif
Now let's compute the definite integral http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_8.gif by subtracting values of
our indefinite one:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_9.gif
But this cannot be correct. After all, if we plot the integrand, we can see that it is
positive throughout the range 0 to 2π:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_10.gif
Mathematica's built-in definite integration of course gives exactly the correct
answer:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_11.gif
So what went wrong with subtracting the end points? The issue is that the
Fundamental Theorem of Calculus isn't directly applicable here. Because,
when you state it fully, the theorem requires that the antiderivative that is
going to be subtracted be continuous throughout the interval.
But the antiderivative we have here looks like this:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_12.gif
It has a discontinuity right in the middle of the interval.
So how does Mathematica get its answer? It has to be more careful. Sometimes it works
by detecting discontinuities in the antiderivative, and then breaking up the integration region
into parts, and carefully taking directional limits at the discontinuity points:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_13.gif
Another thing it can do is to make use of ambiguity in the antiderivative. Every calculus
student knows that antiderivatives can contain an arbitrary additive constant. But in fact,
there's more arbitrariness than that: one can add different constants on different parts of
the interval.
Often it's not obvious from the algebraic form that one has added a piecewise
constant like this. For example, consider:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_14.gif
Differentiating this shows that it is indeed an antiderivative of the same function as above.
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_15.gif
It doesn't happen to be the antiderivative that Mathematica generates by default.
But it is a perfectly valid one. And it turns out to be continuous over the region of integration:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_16.gif
So if one uses it, one can now directly apply the Fundamental Theorem of Calculus
and get the correct result:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_17.gif
Even though their algebraic forms look different, one can verify that the antiderivatives
differ by a piecewise constant:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_18.gif
So how come Mathematica doesn't always generate the "better" antiderivative, so that
the Fundamental Theorem of Calculus applies directly?
The problem is that there's actually no way to produce an antiderivative that has
this property for all definite integrals one might want to compute. Here's the formal
situation.
The Fundamental Theorem of Calculus states that an antiderivative continuous
along a chosen path always exists. It is defined as http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_19.gif where the
integration is performed along the path. Its existence is of theoretical
importance--though in practice http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_20.gif cannot always be expressed in terms of any
predetermined set of elementary and special functions.
Moreover, if a meromorphic integrand http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_21.gif has simple poles in the complex plane,
it is impossible to choose an antiderivative http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_23.gif continuous along every
imaginable path in the complex plane--because of branch cuts in http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_23.gif.
Our integrand http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_24.gif has simple poles at http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_25.gif:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_26.gif
But now consider how our two antiderivatives behave in the complex plane.
Here are the real parts of these functions:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_27.gif
Looking on the real axis,http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_28.gif is not continuous, so the Fundamental Theorem
cannot directly be applied. But http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_29.gifs continuous, so the Fundamental Theorem will work.
However, look now at the line from http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_30.gif indicated in the picture
by a black line. Along this line,http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_31.gif is continuous, so the Fundamental
Theorem will work fine for it. But now http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_32.gif is not continuous, so the Fundamental Theorem
will not work:
http://wanxpon.free.fr/Noobsters2/Calculus/pavlyk_33.gif
And indeed one can show that there is no single choice of antiderivative for which
the Fundamental Theorem will always work.
So Mathematica has to go to more effort to get the correct answer for the definite
integral.
This may seem subtle--but actually it is just the tip of the iceberg of the issues that
crop up in doing definite integration correctly in Mathematica--and in mathematics.
It's the job of our group at Wolfram Research to understand all these issues and figure
out good algorithms for handling them. It's a fascinating exercise not only in algorithm
development but also in mathematics itself.
More Infos (http://blog.wolfram.com/2008/01/mathematica_and_the_fundamental_theorem_of_calculu s.html)