# 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?

edit retag close merge delete

Sort by » oldest newest most voted

Incomplete Gamma function and the Ei function are indeed related. See the following pages for example.

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.

more

Yeah, see http://trac.sagemath.org/sage_trac/ticket/11164 for another example of how this relationship causes trouble in Maxima/Sage.

( 2011-12-21 16:12:59 -0500 )edit

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:

   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.

more

Is there any work on rewriting the whole integration functions in sage?

( 2011-12-22 03:22:22 -0500 )edit

I 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?

more

In one line:

sage: maxima('integrate(diff((exp(x)-1)/x,x),x),gamma_expand:true,factor').sage()

(e^x - 1)/x

more

Sounds like we might need to look at gamma_expand:true a little more closely!

( 2011-12-23 05:08:54 -0500 )edit

sage: 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)/x

more

Maxima 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.

more