2
$\begingroup$

I have a question about an integral. I wanna integrate this:

-((cA Log[1 + mgl^2/sa1])/(-1 + x)) + (
cA Log[-(sa1/(-mgl^2 - sa1))])/(1 - x) + (cA cF Log[-1 + 1/x])/(
1 - x) - (2 cF^2 Log[-1 + 1/x])/(1 - x) + (2 cF Log[1 - x])/(
1 - x) + 1/
2 cA (2/(-1 + x) + sa1^2/(
2 mgl^4 + 4 mgl^2 sa1 + 2 sa1^2 - 4 mgl^2 sa1 x - 4 sa1^2 x + 
 2 sa1^2 x^2) - (sa1^2 x)/(
 2 mgl^4 + 4 mgl^2 sa1 + 2 sa1^2 - 4 mgl^2 sa1 x - 4 sa1^2 x + 
 2 sa1^2 x^2) + (2 Log[1 + mgl^2/sa1 - x])/(-1 + x))

over x from 0 to z. Every part in the integral is real. When I do this:

Integrate[Kqq1P, {x, 0, z}, Assumptions -> {0 < z < 1, x \[Element] Real, Kqq1P \[Element] Real}]

It seems to take years. Does anyone know how to speed up that integration. By the way Kqq1P is that expression above.

Thanks in advance!

Cheers,

Marcel

$\endgroup$
  • 1
    $\begingroup$ There are a number of parameters and telling it that the entire expression is real (which is done incorrectly above, should use Reals where you have Real) is not sufficient to unravel possible branch cut crossings. This is an issue for the subexpression Log[1 + mgl^2/sa1 - x]. $\endgroup$ – Daniel Lichtblau May 21 '15 at 15:05
7
$\begingroup$

The "trick" which works frequently when Mathematica refuses to calculate a definite integral is to calculate first the indefinite integral, then take the limits at the ends of the integration interval and subtract the results.

Here we go.

Let the integrand be

f = -((cA Log[1 + mgl^2/sa1])/(-1 + x)) + (cA Log[-(sa1/(-mgl^2 - sa1))])/(1 - x) + (cA cF Log[-1 + 1/x])/(1 - x) - (2 cF^2 Log[-1 + 1/x])/(1 - 
     x) + (2 cF Log[1 - x])/(1 - x) + 
  1/2 cA (2/(-1 + x) + 
     sa1^2/(2 mgl^4 + 4 mgl^2 sa1 + 2 sa1^2 - 4 mgl^2 sa1 x - 4 sa1^2 x + 
        2 sa1^2 x^2) - (sa1^2 x)/(2 mgl^4 + 4 mgl^2 sa1 + 2 sa1^2 - 
        4 mgl^2 sa1 x - 4 sa1^2 x + 
        2 sa1^2 x^2) + (2 Log[1 + mgl^2/sa1 - x])/(-1 + x));

Now take the indefinte integral

f1 = Integrate[f, x]

(*
Out[6]= (cA mgl^2)/(4 (-mgl^2 - sa1 + sa1 x)) + cA Log[1 - x] - 
 cA Log[sa1/(mgl^2 + sa1)] Log[1 - x] - cA Log[(mgl^2 + sa1)/sa1] Log[1 - x] -
  cF Log[1 - x]^2 - 1/2 cA cF Log[-1 + x]^2 + cF^2 Log[-1 + x]^2 - 
 cA cF Log[-1 + x] (Log[-1 + 1/x] - Log[-1 + x] + Log[x]) + 
 2 cF^2 Log[-1 + x] (Log[-1 + 1/x] - Log[-1 + x] + Log[x]) - 
 1/4 cA Log[mgl^2 + sa1 - sa1 x] - cA cF PolyLog[2, 1 - x] + 
 2 cF^2 PolyLog[2, 1 - x] + 
 cA (Log[1 - (sa1 (1 + mgl^2/sa1 - x))/mgl^2] Log[1 + mgl^2/sa1 - x] + 
    PolyLog[2, (sa1 (1 + mgl^2/sa1 - x))/mgl^2])
*)

Calculate the limit at the lower end of the interval

fi0 = Limit[f1, x -> 0]

(*
Out[23]= -(2/3) cA cF \[Pi]^2 + (4 cF^2 \[Pi]^2)/3 - (cA mgl^2)/(4 (mgl^2 + sa1)) - 
 1/4 cA Log[mgl^2 + sa1] + cA Log[-(sa1/mgl^2)] Log[(mgl^2 + sa1)/sa1] + 
 cA PolyLog[2, 1 + sa1/mgl^2]
*)

and similarly for the limit at the upper end of the interval

fi1 = Limit[f1, x -> z]

(*
Out[24]= -((cA mgl^2)/(4 (mgl^2 + sa1 - sa1 z))) + cA Log[1 - z] - 
 cA Log[sa1/mgl^2] Log[1 - z] - cA Log[(mgl^2 + sa1)/sa1] Log[1 - z] + 
 cA Log[1 + sa1/mgl^2] Log[1 - z] - cF Log[1 - z]^2 - 
 cA cF Log[-1 + 1/z] Log[-1 + z] + 2 cF^2 Log[-1 + 1/z] Log[-1 + z] + 
 1/2 cA cF Log[-1 + z]^2 - cF^2 Log[-1 + z]^2 + 
 cA Log[1 + mgl^2/sa1 - z] Log[(sa1 (-1 + z))/mgl^2] - 
 cA cF Log[-1 + z] Log[z] + 2 cF^2 Log[-1 + z] Log[z] - 
 1/4 cA Log[mgl^2 + sa1 - sa1 z] + cF (-cA + 2 cF) PolyLog[2, 1 - z] + 
 cA PolyLog[2, (mgl^2 + sa1 - sa1 z)/mgl^2]
*)

The difference should be the value of the definite integral:

fd = fi1 - fi0 // Simplify

(*
Out[25]= 2/3 cA cF \[Pi]^2 - (4 cF^2 \[Pi]^2)/3 + (cA mgl^2)/(4 (mgl^2 + sa1)) - (
 cA mgl^2)/(4 (mgl^2 + sa1 - sa1 z)) + 1/4 cA Log[mgl^2 + sa1] - 
 cA Log[-(sa1/mgl^2)] Log[(mgl^2 + sa1)/sa1] + cA Log[1 - z] - 
 cA Log[sa1/mgl^2] Log[1 - z] - cA Log[(mgl^2 + sa1)/sa1] Log[1 - z] + 
 cA Log[1 + sa1/mgl^2] Log[1 - z] - cF Log[1 - z]^2 - 
 cA cF Log[-1 + 1/z] Log[-1 + z] + 2 cF^2 Log[-1 + 1/z] Log[-1 + z] + 
 1/2 cA cF Log[-1 + z]^2 - cF^2 Log[-1 + z]^2 + 
 cA Log[1 + mgl^2/sa1 - z] Log[(sa1 (-1 + z))/mgl^2] - 
 cA cF Log[-1 + z] Log[z] + 2 cF^2 Log[-1 + z] Log[z] - 
 1/4 cA Log[mgl^2 + sa1 - sa1 z] - cA PolyLog[2, 1 + sa1/mgl^2] + 
 cF (-cA + 2 cF) PolyLog[2, 1 - z] + 
 cA PolyLog[2, (mgl^2 + sa1 - sa1 z)/mgl^2]
*)

All these calculations are done by MMA in almost no time.

It should be mentioned that, stricly speaking, we should check if the indefinite integral is a continuous function of x. If not, the result obatined may be wrong. But continuity depends of the parameters of the problem, and therefore is not easily checked.

$\endgroup$
  • $\begingroup$ helped. Thanks. But why is that faster? $\endgroup$ – Marcel May 21 '15 at 10:08
  • 1
    $\begingroup$ @Marcel: I can't say because I don't know the details of the very complicated and comprehensive internal code of Integrate[]. Finding the indefinite integral (a so called antiderivative) is a fairly quick procedure while the next step, the limits, can take much longer, and the continuity check (which we skipped here) even longer. $\endgroup$ – Dr. Wolfgang Hintze May 21 '15 at 10:26
  • 1
    $\begingroup$ As a sanity check, one could compare the results from the numerical evaluation of the closed form with the corresponding result from NIntegrate[]. $\endgroup$ – J. M. will be back soon May 21 '15 at 11:48
  • $\begingroup$ @ Guess who it is: yes, this is a good idea. To justify a posteriori not having done the complicated analyses. $\endgroup$ – Dr. Wolfgang Hintze May 21 '15 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.