\(\int \frac {1}{1+a \cos (x)} \, dx\) [141]

   Optimal result
   Rubi [A] (verified)
   Mathematica [A] (verified)
   Maple [A] (verified)
   Fricas [A] (verification not implemented)
   Sympy [B] (verification not implemented)
   Maxima [F(-2)]
   Giac [A] (verification not implemented)
   Mupad [B] (verification not implemented)

Optimal result

Integrand size = 8, antiderivative size = 37 \[ \int \frac {1}{1+a \cos (x)} \, dx=\frac {2 \arctan \left (\frac {\sqrt {1-a} \tan \left (\frac {x}{2}\right )}{\sqrt {1+a}}\right )}{\sqrt {1-a^2}} \]

[Out]

2*arctan((1-a)^(1/2)*tan(1/2*x)/(1+a)^(1/2))/(-a^2+1)^(1/2)

Rubi [A] (verified)

Time = 0.03 (sec) , antiderivative size = 37, normalized size of antiderivative = 1.00, number of steps used = 2, number of rules used = 2, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.250, Rules used = {2738, 211} \[ \int \frac {1}{1+a \cos (x)} \, dx=\frac {2 \arctan \left (\frac {\sqrt {1-a} \tan \left (\frac {x}{2}\right )}{\sqrt {a+1}}\right )}{\sqrt {1-a^2}} \]

[In]

Int[(1 + a*Cos[x])^(-1),x]

[Out]

(2*ArcTan[(Sqrt[1 - a]*Tan[x/2])/Sqrt[1 + a]])/Sqrt[1 - a^2]

Rule 211

Int[((a_) + (b_.)*(x_)^2)^(-1), x_Symbol] :> Simp[(Rt[a/b, 2]/a)*ArcTan[x/Rt[a/b, 2]], x] /; FreeQ[{a, b}, x]
&& PosQ[a/b]

Rule 2738

Int[((a_) + (b_.)*sin[Pi/2 + (c_.) + (d_.)*(x_)])^(-1), x_Symbol] :> With[{e = FreeFactors[Tan[(c + d*x)/2], x
]}, Dist[2*(e/d), Subst[Int[1/(a + b + (a - b)*e^2*x^2), x], x, Tan[(c + d*x)/2]/e], x]] /; FreeQ[{a, b, c, d}
, x] && NeQ[a^2 - b^2, 0]

Rubi steps \begin{align*} \text {integral}& = 2 \text {Subst}\left (\int \frac {1}{1+a+(1-a) x^2} \, dx,x,\tan \left (\frac {x}{2}\right )\right ) \\ & = \frac {2 \arctan \left (\frac {\sqrt {1-a} \tan \left (\frac {x}{2}\right )}{\sqrt {1+a}}\right )}{\sqrt {1-a^2}} \\ \end{align*}

Mathematica [A] (verified)

Time = 0.02 (sec) , antiderivative size = 31, normalized size of antiderivative = 0.84 \[ \int \frac {1}{1+a \cos (x)} \, dx=\frac {2 \text {arctanh}\left (\frac {(-1+a) \tan \left (\frac {x}{2}\right )}{\sqrt {-1+a^2}}\right )}{\sqrt {-1+a^2}} \]

[In]

Integrate[(1 + a*Cos[x])^(-1),x]

[Out]

(2*ArcTanh[((-1 + a)*Tan[x/2])/Sqrt[-1 + a^2]])/Sqrt[-1 + a^2]

Maple [A] (verified)

Time = 0.11 (sec) , antiderivative size = 30, normalized size of antiderivative = 0.81

method result size
default \(\frac {2 \,\operatorname {arctanh}\left (\frac {\left (a -1\right ) \tan \left (\frac {x}{2}\right )}{\sqrt {\left (1+a \right ) \left (a -1\right )}}\right )}{\sqrt {\left (1+a \right ) \left (a -1\right )}}\) \(30\)
risch \(\frac {\ln \left ({\mathrm e}^{i x}+\frac {i a^{2}+\sqrt {a^{2}-1}-i}{a \sqrt {a^{2}-1}}\right )}{\sqrt {a^{2}-1}}-\frac {\ln \left ({\mathrm e}^{i x}+\frac {-i a^{2}+\sqrt {a^{2}-1}+i}{a \sqrt {a^{2}-1}}\right )}{\sqrt {a^{2}-1}}\) \(87\)

[In]

int(1/(1+a*cos(x)),x,method=_RETURNVERBOSE)

[Out]

2/((1+a)*(a-1))^(1/2)*arctanh((a-1)*tan(1/2*x)/((1+a)*(a-1))^(1/2))

Fricas [A] (verification not implemented)

none

Time = 0.28 (sec) , antiderivative size = 111, normalized size of antiderivative = 3.00 \[ \int \frac {1}{1+a \cos (x)} \, dx=\left [\frac {\log \left (-\frac {{\left (a^{2} - 2\right )} \cos \left (x\right )^{2} - 2 \, \sqrt {a^{2} - 1} {\left (a + \cos \left (x\right )\right )} \sin \left (x\right ) - 2 \, a^{2} - 2 \, a \cos \left (x\right ) + 1}{a^{2} \cos \left (x\right )^{2} + 2 \, a \cos \left (x\right ) + 1}\right )}{2 \, \sqrt {a^{2} - 1}}, -\frac {\sqrt {-a^{2} + 1} \arctan \left (\frac {\sqrt {-a^{2} + 1} {\left (a + \cos \left (x\right )\right )}}{{\left (a^{2} - 1\right )} \sin \left (x\right )}\right )}{a^{2} - 1}\right ] \]

[In]

integrate(1/(1+a*cos(x)),x, algorithm="fricas")

[Out]

[1/2*log(-((a^2 - 2)*cos(x)^2 - 2*sqrt(a^2 - 1)*(a + cos(x))*sin(x) - 2*a^2 - 2*a*cos(x) + 1)/(a^2*cos(x)^2 +
2*a*cos(x) + 1))/sqrt(a^2 - 1), -sqrt(-a^2 + 1)*arctan(sqrt(-a^2 + 1)*(a + cos(x))/((a^2 - 1)*sin(x)))/(a^2 -
1)]

Sympy [B] (verification not implemented)

Leaf count of result is larger than twice the leaf count of optimal. 110 vs. \(2 (29) = 58\).

Time = 1.45 (sec) , antiderivative size = 110, normalized size of antiderivative = 2.97 \[ \int \frac {1}{1+a \cos (x)} \, dx=\begin {cases} \tan {\left (\frac {x}{2} \right )} & \text {for}\: a = 1 \\- \frac {1}{\tan {\left (\frac {x}{2} \right )}} & \text {for}\: a = -1 \\- \frac {\log {\left (- \sqrt {\frac {a}{a - 1} + \frac {1}{a - 1}} + \tan {\left (\frac {x}{2} \right )} \right )}}{a \sqrt {\frac {a}{a - 1} + \frac {1}{a - 1}} - \sqrt {\frac {a}{a - 1} + \frac {1}{a - 1}}} + \frac {\log {\left (\sqrt {\frac {a}{a - 1} + \frac {1}{a - 1}} + \tan {\left (\frac {x}{2} \right )} \right )}}{a \sqrt {\frac {a}{a - 1} + \frac {1}{a - 1}} - \sqrt {\frac {a}{a - 1} + \frac {1}{a - 1}}} & \text {otherwise} \end {cases} \]

[In]

integrate(1/(1+a*cos(x)),x)

[Out]

Piecewise((tan(x/2), Eq(a, 1)), (-1/tan(x/2), Eq(a, -1)), (-log(-sqrt(a/(a - 1) + 1/(a - 1)) + tan(x/2))/(a*sq
rt(a/(a - 1) + 1/(a - 1)) - sqrt(a/(a - 1) + 1/(a - 1))) + log(sqrt(a/(a - 1) + 1/(a - 1)) + tan(x/2))/(a*sqrt
(a/(a - 1) + 1/(a - 1)) - sqrt(a/(a - 1) + 1/(a - 1))), True))

Maxima [F(-2)]

Exception generated. \[ \int \frac {1}{1+a \cos (x)} \, dx=\text {Exception raised: ValueError} \]

[In]

integrate(1/(1+a*cos(x)),x, algorithm="maxima")

[Out]

Exception raised: ValueError >> Computation failed since Maxima requested additional constraints; using the 'a
ssume' command before evaluation *may* help (example of legal syntax is 'assume(a^2-1.0>0)', see `assume?` for
 more detail

Giac [A] (verification not implemented)

none

Time = 0.27 (sec) , antiderivative size = 53, normalized size of antiderivative = 1.43 \[ \int \frac {1}{1+a \cos (x)} \, dx=-\frac {2 \, {\left (\pi \left \lfloor \frac {x}{2 \, \pi } + \frac {1}{2} \right \rfloor \mathrm {sgn}\left (2 \, a - 2\right ) + \arctan \left (\frac {a \tan \left (\frac {1}{2} \, x\right ) - \tan \left (\frac {1}{2} \, x\right )}{\sqrt {-a^{2} + 1}}\right )\right )}}{\sqrt {-a^{2} + 1}} \]

[In]

integrate(1/(1+a*cos(x)),x, algorithm="giac")

[Out]

-2*(pi*floor(1/2*x/pi + 1/2)*sgn(2*a - 2) + arctan((a*tan(1/2*x) - tan(1/2*x))/sqrt(-a^2 + 1)))/sqrt(-a^2 + 1)

Mupad [B] (verification not implemented)

Time = 0.34 (sec) , antiderivative size = 28, normalized size of antiderivative = 0.76 \[ \int \frac {1}{1+a \cos (x)} \, dx=\frac {2\,\mathrm {atanh}\left (\frac {\mathrm {tan}\left (\frac {x}{2}\right )\,\sqrt {a-1}}{\sqrt {a+1}}\right )}{\sqrt {a-1}\,\sqrt {a+1}} \]

[In]

int(1/(a*cos(x) + 1),x)

[Out]

(2*atanh((tan(x/2)*(a - 1)^(1/2))/(a + 1)^(1/2)))/((a - 1)^(1/2)*(a + 1)^(1/2))