Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between definite and indefinite integration in Mathematica?

I have noticed that mathematica chokes out on certain definite integrals, but if I do an indeifinite integration and subtract the limiting values of the resulting function, it would readily give me an answer.

Are there different algorithms to compute the definite and indefinite integrals? Is there some reason the above procedure described isn't done by Mathematica manually?

Examples:

As people in the comment asked for examples, here are two.

Timing[Integrate[(r - c x)/(r^2 + c^2 - (2 r) c x)^(3/2), x]]
Out:={0.010452,(-c+r x)/(r^2 Sqrt[c^2+r^2-2 c r x])}

Gets the output immediately. While,

Integrate[(r - c x)/(r^2 + c^2 - (2 r) c x)^(3/2), {x, -1, 1}]

Keeps computing and slows my old computer down. After a bit of time it returns an unneccesarily long result with a lot of cases. This is Mathematica 7. There are no singularities in this integral or running into complex numbers etc. To get the value, let's abort the computation running for about a minutes now and find the value using the fundamental theorem of calculus manually.

g = (r - c x)/(r^2 + c^2 - (2 r) c x)^(3/2)
l = Integrate[g, x] /. x -> -1;
u = Integrate[g, x] /. x -> 1;
u - l
Out:= (-c+r)/(r^2 Sqrt[c^2-2 c r+r^2])-(-c-r)/(r^2 Sqrt[c^2+2 c r+r^2])
FullSimplify[%] 
Out:= ((-c+r)/Sqrt[(c-r)^2]+(c+r)/Sqrt[(c+r)^2])/r^2

Which is actually correct. Finally, for completeness, let's compare the output and the time for the definite integral:

Timing[Integrate[(r - c x)/(r^2 + c^2 - (2 r) c x)^(3/2), {x, -1, 
   1}]]
Out:= {174.52,If[(Re[c/r+r/c]>=2||2+Re[c/r+r/c]<=0||c/r+r/c\[NotElement]Reals)&&((Im[r] Re[c]+Im[c] Re[r]<=0&&((Im[c]+Im[r]) (Re[c]+Re[r])>=0||Im[c]^3 Re[r]+Im[r] Re[c] (Im[r]^2-Re[c]^2+Re[r]^2)>=Im[c] (Im[c] Im[r] Re[c]+Re[r] (Im[r]^2 ... blah blah half a page

Note the three minutes computation time and the very confused answer.

An actual example from my work, I noticed it and was puzzled but forgot about it after the deadline submission, until today when I faced the same problem again.

f = 1/((-I c + k^2/2 - 1/2 (a + k)^2) (I d + k^2/2 - 
    1/2 (-b + k)^2)) + 1/((I c + k^2/2 - 1/2 (-a + k)^2) (I c + I d + 
    k^2/2 - 1/2 (-a - b + k)^2)) + 1/((I d + k^2/2 - 
    1/2 (-b + k)^2) (I c + I d + k^2/2 - 
    1/2 (-a - b + k)^2)) + 1/((I c + k^2/2 - 1/2 (-a + k)^2) (-I d + 
    k^2/2 - 1/2 (b + k)^2)) + 1/((-I c + k^2/2 - 
    1/2 (a + k)^2) (-I c - I d + k^2/2 - 
    1/2 (a + b + k)^2)) + 1/((-I d + k^2/2 - 1/2 (b + k)^2) (-I c - 
    I d + k^2/2 - 1/2 (a + b + k)^2))

When I tried the definite integral, I waited and waited, after several hours (true!) I finally decided to try the workaround that worked in no time:

fl =  Integrate[f, k] /. k -> -1 ;
fu =  Integrate[f, k] /. k -> 1 ;
F = fu - fl;
F1 = F /. {a -> .01, c -> 0, d -> 1};

Please note that I am not talking about singularities as one comment suggested. Integrate[1/x, {x, -1, 1}] almost immediately returns Integrate::idiv: Integral of 1/x does not converge on {-1,1}. >> which is a perfectly reasonable output.

like image 650
yayu Avatar asked Sep 20 '11 21:09

yayu


1 Answers

I think Daniel is right in his comment above: "Most likely is the definite integration code is checking for singularities on the integration path"

Just look:

Timing@Integrate[(r - c x)/(r^2 + c^2 - (2 r) c x)^(3/2), {x, -1, 1}]

Result -> None, I got bored waiting and aborted the calc

While:

Timing@Integrate[(r - c x)/(r^2 + c^2 - (2 r) c x)^(3/2), {x, -1, 1},
          Assumptions -> {r ∈ Reals && c ∈ Reals && c != r && c != -r}]

->{3.688, (-Sign[c - r] + Sign[c + r])/r^2} 

So, it is a matter of which conditions you specify for your constants.

Another way is suggested in Simon's comment above:

Timing@Integrate[(r - c x)/(r^2 + c^2 - (2 r) c x)^(3/2), {x, -1, 1},  
                 GenerateConditions -> False]

{10.375, ((-c + r)/Sqrt[(c - r)^2] + (c + r)/Sqrt[(c + r)^2])/r^2}

And finally, you may also do:

Timing@Integrate[(r - c x)/(r^2 + c^2 - (2 r) c x)^(3/2), {x, -1, 1},  
                 GenerateConditions -> True]

{16.45, ConditionalExpression[.. A long expression ...., Re[c^2 + r^2] > 0]}
like image 68
Dr. belisarius Avatar answered Sep 28 '22 08:09

Dr. belisarius