ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 23 Dec 2011 05:08:54 -0600How do I understand the result of symbolic integralshttps://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/So now I know how to integrate, but when I type in
sage: deriv=diff((exp(x)-1)/x,x); deriv
e^x/x - (e^x - 1)/x^2
sage: deriv.integrate(x)
-1/x + Ei(x) - gamma(-1, -x)
why don't I get back `(exp(x)-1)/x +C `?
Wed, 18 Aug 2010 13:04:12 -0500https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/Answer by achrzesz for <p>So now I know how to integrate, but when I type in</p>
<pre><code>sage: deriv=diff((exp(x)-1)/x,x); deriv
e^x/x - (e^x - 1)/x^2
sage: deriv.integrate(x)
-1/x + Ei(x) - gamma(-1, -x)
</code></pre>
<p>why don't I get back <code>(exp(x)-1)/x +C</code>?</p>
https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?answer=13042#post-id-13042In one line:
sage: maxima('integrate(diff((exp(x)-1)/x,x),x),gamma_expand:true,factor').sage()
(e^x - 1)/x
Wed, 21 Dec 2011 20:54:00 -0600https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?answer=13042#post-id-13042Comment by kcrisman for <p>In one line:</p>
<p>sage: maxima('integrate(diff((exp(x)-1)/x,x),x),gamma_expand:true,factor').sage()</p>
<p>(e^x - 1)/x</p>
https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?comment=20644#post-id-20644Sounds like we might need to look at `gamma_expand:true` a little more closely!Fri, 23 Dec 2011 05:08:54 -0600https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?comment=20644#post-id-20644Answer by Robert Dodier for <p>So now I know how to integrate, but when I type in</p>
<pre><code>sage: deriv=diff((exp(x)-1)/x,x); deriv
e^x/x - (e^x - 1)/x^2
sage: deriv.integrate(x)
-1/x + Ei(x) - gamma(-1, -x)
</code></pre>
<p>why don't I get back <code>(exp(x)-1)/x +C</code>?</p>
https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?answer=11488#post-id-11488Maxima 5.21.1 gives -1/x-gamma\_incomplete(0,-x)-gamma\_incomplete(-1,-x) for integrate(diff((exp(x) - 1)/x, x), x) which is correct from what I can tell (agrees numerically with the original expression and has the same derivative).
The result isn't as simple as it could be because the integration algorithm is phrased in more general terms, such that the integrand you specified is a special case of some general form. Often that's the most effective way to calculate integrals, since you can cover a lot of special cases with one general form.
Fri, 20 Aug 2010 08:56:42 -0500https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?answer=11488#post-id-11488Answer by kcrisman for <p>So now I know how to integrate, but when I type in</p>
<pre><code>sage: deriv=diff((exp(x)-1)/x,x); deriv
e^x/x - (e^x - 1)/x^2
sage: deriv.integrate(x)
-1/x + Ei(x) - gamma(-1, -x)
</code></pre>
<p>why don't I get back <code>(exp(x)-1)/x +C</code>?</p>
https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?answer=11439#post-id-11439I wouldn't blame the integration code; these are really hard problems. The problem is that simplification of the integral doesn't work because of logs, so it's left alone. Wolfram Alpha, for instance, simplifies this expression to something that definitely only would work in certain circumstances. Maybe this is another symptom of whether we assume variables are real in our Maxima?Thu, 19 Aug 2010 08:14:38 -0500https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?answer=11439#post-id-11439Answer by achrzesz for <p>So now I know how to integrate, but when I type in</p>
<pre><code>sage: deriv=diff((exp(x)-1)/x,x); deriv
e^x/x - (e^x - 1)/x^2
sage: deriv.integrate(x)
-1/x + Ei(x) - gamma(-1, -x)
</code></pre>
<p>why don't I get back <code>(exp(x)-1)/x +C</code>?</p>
https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?answer=13058#post-id-13058sage: maxima('gamma_expand:true')
true
sage: maxima('deriv:diff((exp(x)-1)/x,x)')
%e^x/x-(%e^x-1)/x^2
sage: maxima('factor(integrate(deriv,x))')
(%e^x-1)/xWed, 21 Dec 2011 19:03:01 -0600https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?answer=13058#post-id-13058Answer by tririver for <p>So now I know how to integrate, but when I type in</p>
<pre><code>sage: deriv=diff((exp(x)-1)/x,x); deriv
e^x/x - (e^x - 1)/x^2
sage: deriv.integrate(x)
-1/x + Ei(x) - gamma(-1, -x)
</code></pre>
<p>why don't I get back <code>(exp(x)-1)/x +C</code>?</p>
https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?answer=13056#post-id-13056Incomplete Gamma function and the Ei function are indeed related. See the following pages for example.
http://en.wikipedia.org/wiki/Exponential_integral
http://en.wikipedia.org/wiki/Incomplete_gamma_function
In this sense, the result of the integration is correct.
There is indeed a subtly of brunch cut. Maxima / Sage defines the brunch cut of the function differently from Mathematica. I tested the Maxima result "-1/x + Ei(x) - gamma(-1, -x)" is indeed continuous on the complex plane (i.e. the result has no problem). But the same function in Mathematica is not continuous.Wed, 21 Dec 2011 15:55:20 -0600https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?answer=13056#post-id-13056Comment by kcrisman for <p>Incomplete Gamma function and the Ei function are indeed related. See the following pages for example.</p>
<p><a href="http://en.wikipedia.org/wiki/Exponential_integral">http://en.wikipedia.org/wiki/Exponent...</a>
<a href="http://en.wikipedia.org/wiki/Incomplete_gamma_function">http://en.wikipedia.org/wiki/Incomple...</a></p>
<p>In this sense, the result of the integration is correct.</p>
<p>There is indeed a subtly of brunch cut. Maxima / Sage defines the brunch cut of the function differently from Mathematica. I tested the Maxima result "-1/x + Ei(x) - gamma(-1, -x)" is indeed continuous on the complex plane (i.e. the result has no problem). But the same function in Mathematica is not continuous.</p>
https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?comment=20662#post-id-20662Yeah, see http://trac.sagemath.org/sage_trac/ticket/11164 for another example of how this relationship causes trouble in Maxima/Sage.Wed, 21 Dec 2011 16:12:59 -0600https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?comment=20662#post-id-20662Answer by William Stein for <p>So now I know how to integrate, but when I type in</p>
<pre><code>sage: deriv=diff((exp(x)-1)/x,x); deriv
e^x/x - (e^x - 1)/x^2
sage: deriv.integrate(x)
-1/x + Ei(x) - gamma(-1, -x)
</code></pre>
<p>why don't I get back <code>(exp(x)-1)/x +C</code>?</p>
https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?answer=11378#post-id-11378Maxima is responsible for default symbolic integration in Sage, and nobody understands how Maxima's integration code works. I just tried continuing your example above as follows:
sage: deriv=diff((exp(x)-1)/x,x); deriv
sage: f = integrate(deriv, x)
sage: g = f - (exp(x)-1)/x
sage: CDF(g(5))
-1.7776787288 + 2.08166817117e-17*I
sage: CDF(g(10))
-4.43650184726 + 2.22044604925e-16*I
sage: CDF(g(20))
-0.530325316824 + 2.27373675443e-12*I
So it doesn't even look like f differs from (exp(x)-1)/x by a constant. Branch cuts are probably relevant. I can't wait until we have our symbolic integration code that we actually understand.Wed, 18 Aug 2010 13:37:41 -0500https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?answer=11378#post-id-11378Comment by mmarco for <p>Maxima is responsible for default symbolic integration in Sage, and nobody understands how Maxima's integration code works. I just tried continuing your example above as follows:</p>
<pre><code> sage: deriv=diff((exp(x)-1)/x,x); deriv
sage: f = integrate(deriv, x)
sage: g = f - (exp(x)-1)/x
sage: CDF(g(5))
-1.7776787288 + 2.08166817117e-17*I
sage: CDF(g(10))
-4.43650184726 + 2.22044604925e-16*I
sage: CDF(g(20))
-0.530325316824 + 2.27373675443e-12*I
</code></pre>
<p>So it doesn't even look like f differs from (exp(x)-1)/x by a constant. Branch cuts are probably relevant. I can't wait until we have our symbolic integration code that we actually understand.</p>
https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?comment=20655#post-id-20655Is there any work on rewriting the whole integration functions in sage?Thu, 22 Dec 2011 03:22:22 -0600https://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/?comment=20655#post-id-20655