# Computing a definite integral is taking forever

Consider the following definite integral:

Integrate[
Sin[θ]/((A1 Cos[θ] + A2) (A3 Cos[θ] + A4 Sin[θ] + A5)), {θ, 0, π},
Assumptions -> (A1 | A2 | A3 | A4 | A5) ϵ Reals]


It takes forever to evaluate. On the contrary, when computing the corresponding indefinite integral Mathematica doesn't break any sweat:

Integrate[Sin[θ]/((A1 Cos[θ] + A2) (A3 Cos[θ] + A4 Sin[θ] + A5)), θ]


Given that the indefinite integral works, I went ahead to use it to evaluate the value of the integral at the limits of the definite integral. For the upper limit of $\pi$, it turns out one has to take a limit(otherwise one gets indeterminate result).

So, I tried Limit[%, θ -> π] and even this one takes forever.

How to get around this problem?

• Using Series[ArcTanh[((-A1 + A2) Tan[θ/2])/Sqrt[A1^2 - A2^2]], {θ, π, 0}] suggests that θ == π is a branch point. – bbgodfrey Aug 9 '18 at 13:53
• @bbgodfrey Yes, possibly so. But the sum of the two inverse tan hyperbolic terms could be finite. – Subho Aug 9 '18 at 14:07
• The issue may be whether the function is single-valued, not whether it is finite. – bbgodfrey Aug 9 '18 at 14:10
• @bbgodfrey Yeah, but the reason it would be multivalued is because of some branch-point, at which the function may blow up(or is undefined). – Subho Aug 9 '18 at 14:15

There may be singularities of the integrand in the range of integration. In order to avoid these, additional assumptions should be imposed. Unfortunately,

Integrate[ Sin[\[Theta]]/((a2 + a1 Cos[\[Theta]]) (a5 + a3 Cos[\[Theta]] +
a4 Sin[\[Theta]])), {\[Theta], 0, \[Pi]},Assumptions ->
a1 \[Element] Reals && a2 \[Element] Reals && a3 \[Element] Reals && a4 \[Element] Reals &&
a5 \[Element] Reals && RealAbs[a1] < RealAbs[a2] &&
Sqrt[a3^2 + a4^2] < RealAbs[a5]]


fails on my comp, returning the input.

It should be noticed that Mathematica cracks it for concrete values of the constants, eg

Integrate[ Sin[\[Theta]]/((2 + Cos[\[Theta]]) (6 + 3 Cos[\[Theta]] +
4 Sin[\[Theta]])), {\[Theta], 0, \[Pi]}]


1/132 (11 Sqrt[3] [Pi] - 9 Sqrt[11] [Pi] + 18 Sqrt[11] ArcTan[4/Sqrt[11]])

Integrate[ Sin[\[Theta]]/((2 + 3 Cos[\[Theta]]) (6 + 3 Cos[\[Theta]] +
4 Sin[\[Theta]])), {\[Theta], 0, \[Pi]}, PrincipalValue -> True]


PossibleZeroQ::ztest1: Unable to decide whether numeric quantity [Pi]/2-I (Log[1-I Sqrt[5]]-Log[1+I Power[<<2>>]])+I Log[-((2 I)/3)+Sqrt[5]/3] is equal to zero. Assuming it is.
1/176 (-3 Sqrt[11] [Pi] + 6 Sqrt[11] ArcTan[4/Sqrt[11]] + 33 Log[5/3])

Addition. In order to answer the request of OP, my best is

Integrate[Sin[\[Theta]]/((1 + a1 Cos[\[Theta]]) (1 + a2 Cos[\[Theta]] +
a3 Sin[\[Theta]])), {\[Theta], 0, \[Pi]}, Assumptions -> a1  > 1 && a2 > 0 && a3 > 0 && a2 + a3 <= 1/2,  PrincipalValue -> True]


Beep. The kernel Local has quit (exited) during the course of an evaluation.

• Is there a way to get the principal value symbolically? – Subho Aug 9 '18 at 15:01
• @Subho95: I will think about that. – user64494 Aug 9 '18 at 15:05
• If you want the principal value, you will need the option PrincipalValue->True. – John Doty Aug 14 '18 at 19:22
• Was initially confused by the OP's use of a pattern match function,|,in a boolean expression, but realized it meant all the params are real. So in your last int, I assume you're trying to apply the conditions a1 \[Element] Reals && a2 \[Element] Reals && a3 \[Element] Reals. But I don't see how your current syntax accomplishes that, since it uses\[Epsilon] instead of \[Element]; in addition, I don't think, | can be used in that way in a boolean expression....[continued] – theorist Aug 15 '18 at 23:39
• Happy to be of use! Please note that what I wrote also applies to your last code block. When I edited that code to give the conditions in standard form, it ran for a long time w/o giving an output. Same thing when I deleted the conditions. Deleting both the conditions and PrincipalValue->True makes it equivalent to the code in Alex Trounev's answer (except that you use different names for your parameters), giving an equivalent result – theorist Aug 16 '18 at 15:41

Here you do not need 5 constants. Can be divided into A2, A5, then the integral is calculated without any assumptions

    Integrate[
Sin[\[Theta]]/((A1 Cos[\[Theta]] + 1)*(A3 Cos[\[Theta]] +
A4 Sin[\[Theta]] + 1)), {\[Theta], 0, \[Pi]}]


The result of integration

    ConditionalExpression[((-A1 + A3) Sqrt[-1 + A3^2 + A4^2]
Log[1 - A1] + (A1 - A3) Sqrt[-1 + A3^2 + A4^2] Log[1 + A1] +
Sqrt[-1 + A1^2] A4 Sqrt[-1 + A3^2 + A4^2]
Log[(1 - A1)/Sqrt[-1 + A1^2]] -
Sqrt[-1 + A1^2] A4 Sqrt[-1 + A3^2 + A4^2]
Log[(-1 + A1)/Sqrt[-1 + A1^2]] +
A1 Sqrt[-1 + A3^2 + A4^2] Log[1 - A3] -
A3 Sqrt[-1 + A3^2 + A4^2] Log[1 - A3] -
A1 Sqrt[-1 + A3^2 + A4^2] Log[1 + A3] +
A3 Sqrt[-1 + A3^2 + A4^2] Log[1 + A3] +
A4 Log[(1 - A3)/Sqrt[-1 + A3^2 + A4^2]] -
A1 A3 A4 Log[(1 - A3)/Sqrt[-1 + A3^2 + A4^2]] -
A4 Log[(-1 + A3)/Sqrt[-1 + A3^2 + A4^2]] +
A1 A3 A4 Log[(-1 + A3)/Sqrt[-1 + A3^2 + A4^2]] +
A4 Log[1 - A4/Sqrt[-1 + A3^2 + A4^2]] -
A1 A3 A4 Log[1 - A4/Sqrt[-1 + A3^2 + A4^2]] -
A4 Log[1 + A4/Sqrt[-1 + A3^2 + A4^2]] +
A1 A3 A4 Log[1 + A4/Sqrt[-1 + A3^2 + A4^2]])/(Sqrt[-1 + A3^2 +
A4^2] (-2 A1 A3 + A3^2 + A4^2 - A1^2 (-1 + A4^2))),
Re[A3] <= 1 &&
1 + Re[A3] >=
0 && (Re[ArcCos[-(1/A1)]] > \[Pi] || Re[ArcCos[-(1/A1)]] < 0 ||
ArcCos[-(1/A1)] \[NotElement]
Reals) && (2 ArcTan[
Im[A4]/Im[A3] + Sqrt[Im[A3]^2 + Im[A4]^2]/
Abs[Im[A3]]] >= \[Pi] ||
ArcTan[Im[A4]/Im[A3] + Sqrt[Im[A3]^2 + Im[A4]^2]/Abs[Im[A3]]] <=
0 || 1 +
Cos[2 ArcTan[
Im[A4]/Im[A3] + Sqrt[Im[A3]^2 + Im[A4]^2]/Abs[Im[A3]]]] Re[
A3] + Re[A4] Sin[
2 ArcTan[
Im[A4]/Im[A3] + Sqrt[Im[A3]^2 + Im[A4]^2]/Abs[Im[A3]]]] >=
0) && (-1 < Re[A1] < 0 || 0 < Re[A1] < 1 ||
A1 \[NotElement] Reals)]

• Alex, could you please explain how you are able to reduce the five parameters to three? Also, you may want to edit the format of your answer, to separate the input code from the output. Currently, you have both your input and your output displayed as input. – theorist Aug 16 '18 at 17:31
• We transform the denominator ((A1 Cos[θ] + A2) (A3 Cos[θ] + A4 Sin[θ] + A5))=A2*A5*((A1 Cos[θ]/ A2+1) (A3 Cos[θ]/A5 + A4 Sin[θ]/A5 +1))', Let's make a replacement 'A1/A2->A1,A3/A5->A3,A4/A5->A4'. We take A2 * A5  from the integrals as a normalizing factor 1/ (A2 * A5). We finally have in the denominator  ((A1 Cos[[Theta]] + 1)*(A3 Cos[[Theta]] + A4 Sin[[Theta]] + 1)) – Alex Trounev Aug 16 '18 at 17:53

Since your expression indicates that all the parameters are real, you can get Mathematica to provide a conditional expression for the definite integral by giving it explicit numerical ranges for each of the them. You can make these ranges arbitrarily large—sufficient to cover the expected range of parameter values. For instance, if we constrain A1...A5 to be positive real numbers < 10^10, we obtain:

expr = Sin[θ]/((A1 Cos[θ] + A2) (A3 Cos[θ] + A4 Sin[θ] + A5));
int = Integrate[expr, {θ, 0, Pi}, Assumptions -> 0 < A1 < 10^10 && 0 < A2 < 10^10 && 0 < A3 < 10^10 && 0 < A4 < 10^10 && 0 < A5 < 10^10]


$\frac{\pi \text{A4} \sqrt{-\left(\text{A1}^2-\text{A2}^2\right) \left(\text{A3}^2+\text{A4}^2-\text{A5}^2\right)}+\log (\text{A2}-\text{A1}) \sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2} (\text{A2} \text{A3}-\text{A1} \text{A5})+\sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2} \log (\text{A5}-\text{A3}) (\text{A1} \text{A5}-\text{A2} \text{A3})-\text{A2} \text{A3} \sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2} \log \left(\frac{\text{A1}+\text{A2}}{\text{A3}+\text{A5}}\right)+\text{A1} \text{A5} \sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2} \log \left(\frac{\text{A1}+\text{A2}}{\text{A3}+\text{A5}}\right)-\text{A1} \text{A3} \text{A4} \log \left(1-\frac{\text{A4}}{\sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2}}\right)+\text{A1} \text{A3} \text{A4} \log \left(\frac{\text{A4}}{\sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2}}+1\right)+i \pi \text{A1} \text{A3} \text{A4}+\text{A2} \text{A4} \text{A5} \log \left(1-\frac{\text{A4}}{\sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2}}\right)-\text{A2} \text{A4} \text{A5} \log \left(\frac{\text{A4}}{\sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2}}+1\right)-i \pi \text{A2} \text{A4} \text{A5}}{\sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2} \left(\text{A1}^2 \left(\text{A5}^2-\text{A4}^2\right)-2 \text{A1} \text{A2} \text{A3} \text{A5}+\text{A2}^2 \left(\text{A3}^2+\text{A4}^2\right)\right)}$

Where: $\text{A1}<\text{A2}\land \text{A3}\leq \text{A5}$

Alternately, if we wish to allow A1...A5 to be positive or negative reals, between -10^10 and 10^10, we obtain:

int = Integrate[expr, {θ, 0, Pi}, Assumptions -> -10^10 < A1 < 10^10 && -10^10 < A2 < 10^10 && -10^10 < A3 < 10^10 && -10^10 < A4 < 10^10 && -10^10 < A5 < 10^10]
`

$\frac{2 \pi \text{A4} \sqrt{-\left(\text{A1}^2-\text{A2}^2\right) \left(\text{A3}^2+\text{A4}^2-\text{A5}^2\right)}+2 \log (\text{A2}-\text{A1}) \sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2} (\text{A2} \text{A3}-\text{A1} \text{A5})-2 \text{A2} \text{A3} \sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2} \log \left(\frac{\text{A1}+\text{A2}}{\text{A3}+\text{A5}}\right)+2 \text{A1} \text{A5} \sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2} \log \left(\frac{\text{A1}+\text{A2}}{\text{A3}+\text{A5}}\right)+2 \text{A4} \log (\text{A3}-\text{A5}) (\text{A1} \text{A3}-\text{A2} \text{A5})-2 \text{A1} \text{A3} \text{A4} \log \left(\frac{\text{A5}-\text{A3}}{\sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2}}\right)-\text{A1} \text{A3} \text{A4} \log \left(\text{A3}^2+\text{A4}^2-\text{A5}^2\right)-2 \text{A1} \text{A3} \text{A4} \log \left(1-\frac{\text{A4}}{\sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2}}\right)+2 \text{A1} \text{A3} \text{A4} \log \left(\frac{\text{A4}}{\sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2}}+1\right)+2 \text{A1} \text{A5} \sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2} \log (\text{A5}-\text{A3})+2 \text{A2} \text{A4} \text{A5} \log \left(\frac{\text{A5}-\text{A3}}{\sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2}}\right)+\text{A2} \text{A4} \text{A5} \log \left(\text{A3}^2+\text{A4}^2-\text{A5}^2\right)+2 \text{A2} \text{A4} \text{A5} \log \left(1-\frac{\text{A4}}{\sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2}}\right)-2 \text{A2} \text{A4} \text{A5} \log \left(\frac{\text{A4}}{\sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2}}+1\right)-2 \text{A2} \text{A3} \sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2} \log (\text{A5}-\text{A3})}{2 \sqrt{\text{A3}^2+\text{A4}^2-\text{A5}^2} \left(\text{A1}^2 \left(\text{A5}^2-\text{A4}^2\right)-2 \text{A1} \text{A2} \text{A3} \text{A5}+\text{A2}^2 \left(\text{A3}^2+\text{A4}^2\right)\right)}$

Where: $(0<\text{A1}<\text{A2}\lor -\text{A2}<\text{A1}<0)\land \text{A3}+\text{A5}\geq 0\land \text{A2}>0$

Assuming you know the actual numerical constraints on the parameters, you can apply those to obtain a conditional expression appropriate for your system.

• Something to adjust: if $A3^2+A4^2>A5^2$, then the Riemann integral under consideration may not exist. Your answer does not take that cicircumstance into account. – user64494 Aug 14 '18 at 17:49
• It is not so simple. Also the term $-i \pi{A2}A4A5$ in the first result looks very strange. Isn't that result a Mathematica bug? – user64494 Aug 14 '18 at 17:58
• Did you try to verify your results? – user64494 Aug 14 '18 at 18:16
• I did try comparing my approach to yours, and got the same results after substituting in values for the parameters we have in common. It's too long to put into a comment, so I'll add it to my answer. – theorist Aug 14 '18 at 18:48
• Not exactly: eg int /. {A1 -> 3, A2 -> 2, A5 -> 6, A4 -> 4, A3 -> 3} performs Undefined ( I have in mind your first int.). Therefore, the principal value is not calculated. – user64494 Aug 14 '18 at 19:09