3.2.23 \(\int \frac {1}{a+\cos (x)+b \sin (x)} \, dx\) [123]

Optimal. Leaf size=47 \[ -\frac {2 \tanh ^{-1}\left (\frac {b-(1-a) \tan \left (\frac {x}{2}\right )}{\sqrt {1-a^2+b^2}}\right )}{\sqrt {1-a^2+b^2}} \]

[Out]

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

________________________________________________________________________________________

Rubi [A]
time = 0.05, antiderivative size = 47, normalized size of antiderivative = 1.00, number of steps used = 3, number of rules used = 3, integrand size = 10, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.300, Rules used = {3203, 632, 212} \begin {gather*} -\frac {2 \tanh ^{-1}\left (\frac {b-(1-a) \tan \left (\frac {x}{2}\right )}{\sqrt {-a^2+b^2+1}}\right )}{\sqrt {-a^2+b^2+1}} \end {gather*}

Antiderivative was successfully verified.

[In]

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

[Out]

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

Rule 212

Int[((a_) + (b_.)*(x_)^2)^(-1), x_Symbol] :> Simp[(1/(Rt[a, 2]*Rt[-b, 2]))*ArcTanh[Rt[-b, 2]*(x/Rt[a, 2])], x]
 /; FreeQ[{a, b}, x] && NegQ[a/b] && (GtQ[a, 0] || LtQ[b, 0])

Rule 632

Int[((a_.) + (b_.)*(x_) + (c_.)*(x_)^2)^(-1), x_Symbol] :> Dist[-2, Subst[Int[1/Simp[b^2 - 4*a*c - x^2, x], x]
, x, b + 2*c*x], x] /; FreeQ[{a, b, c}, x] && NeQ[b^2 - 4*a*c, 0]

Rule 3203

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

Rubi steps

\begin {align*} \int \frac {1}{a+\cos (x)+b \sin (x)} \, dx &=2 \text {Subst}\left (\int \frac {1}{1+a+2 b x+(-1+a) x^2} \, dx,x,\tan \left (\frac {x}{2}\right )\right )\\ &=-\left (4 \text {Subst}\left (\int \frac {1}{4 \left (1-a^2+b^2\right )-x^2} \, dx,x,2 b+2 (-1+a) \tan \left (\frac {x}{2}\right )\right )\right )\\ &=-\frac {2 \tanh ^{-1}\left (\frac {b-(1-a) \tan \left (\frac {x}{2}\right )}{\sqrt {1-a^2+b^2}}\right )}{\sqrt {1-a^2+b^2}}\\ \end {align*}

________________________________________________________________________________________

Mathematica [A]
time = 0.04, size = 44, normalized size = 0.94 \begin {gather*} \frac {2 \tan ^{-1}\left (\frac {b+(-1+a) \tan \left (\frac {x}{2}\right )}{\sqrt {-1+a^2-b^2}}\right )}{\sqrt {-1+a^2-b^2}} \end {gather*}

Antiderivative was successfully verified.

[In]

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

[Out]

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

________________________________________________________________________________________

Maple [A]
time = 0.09, size = 43, normalized size = 0.91

method result size
default \(\frac {2 \arctan \left (\frac {2 \left (a -1\right ) \tan \left (\frac {x}{2}\right )+2 b}{2 \sqrt {a^{2}-b^{2}-1}}\right )}{\sqrt {a^{2}-b^{2}-1}}\) \(43\)
risch \(-\frac {\ln \left ({\mathrm e}^{i x}+\frac {i a b \sqrt {-a^{2}+b^{2}+1}+i a^{2}-i b^{2}-a^{2} b +b^{3}+a \sqrt {-a^{2}+b^{2}+1}-i+b}{\left (b^{2}+1\right ) \sqrt {-a^{2}+b^{2}+1}}\right )}{\sqrt {-a^{2}+b^{2}+1}}+\frac {\ln \left ({\mathrm e}^{i x}+\frac {i a b \sqrt {-a^{2}+b^{2}+1}-i a^{2}+i b^{2}+a^{2} b -b^{3}+a \sqrt {-a^{2}+b^{2}+1}+i-b}{\left (b^{2}+1\right ) \sqrt {-a^{2}+b^{2}+1}}\right )}{\sqrt {-a^{2}+b^{2}+1}}\) \(198\)

Verification of antiderivative is not currently implemented for this CAS.

[In]

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

[Out]

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

________________________________________________________________________________________

Maxima [F(-2)]
time = 0.00, size = 0, normalized size = 0.00 \begin {gather*} \text {Exception raised: ValueError} \end {gather*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

integrate(1/(a+cos(x)+b*sin(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(b^2-a^2+1>0)', see `assume?` f
or more deta

________________________________________________________________________________________

Fricas [A]
time = 0.99, size = 287, normalized size = 6.11 \begin {gather*} \left [-\frac {\sqrt {-a^{2} + b^{2} + 1} \log \left (-\frac {b^{4} + {\left (a^{2} + 3\right )} b^{2} - {\left (2 \, a^{2} b^{2} - b^{4} - 2 \, a^{2} + 1\right )} \cos \left (x\right )^{2} - a^{2} + 2 \, {\left (a b^{2} + a\right )} \cos \left (x\right ) + 2 \, {\left (a b^{3} + a b - {\left (b^{3} - {\left (2 \, a^{2} - 1\right )} b\right )} \cos \left (x\right )\right )} \sin \left (x\right ) - 2 \, {\left (2 \, a b \cos \left (x\right )^{2} - a b + {\left (b^{3} + b\right )} \cos \left (x\right ) - {\left (b^{2} - {\left (a b^{2} - a\right )} \cos \left (x\right ) + 1\right )} \sin \left (x\right )\right )} \sqrt {-a^{2} + b^{2} + 1} + 2}{{\left (b^{2} - 1\right )} \cos \left (x\right )^{2} - a^{2} - b^{2} - 2 \, a \cos \left (x\right ) - 2 \, {\left (a b + b \cos \left (x\right )\right )} \sin \left (x\right )}\right )}{2 \, {\left (a^{2} - b^{2} - 1\right )}}, \frac {\arctan \left (-\frac {{\left (a b \sin \left (x\right ) + b^{2} + a \cos \left (x\right ) + 1\right )} \sqrt {a^{2} - b^{2} - 1}}{{\left (b^{3} - {\left (a^{2} - 1\right )} b\right )} \cos \left (x\right ) + {\left (a^{2} - b^{2} - 1\right )} \sin \left (x\right )}\right )}{\sqrt {a^{2} - b^{2} - 1}}\right ] \end {gather*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

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

[Out]

[-1/2*sqrt(-a^2 + b^2 + 1)*log(-(b^4 + (a^2 + 3)*b^2 - (2*a^2*b^2 - b^4 - 2*a^2 + 1)*cos(x)^2 - a^2 + 2*(a*b^2
 + a)*cos(x) + 2*(a*b^3 + a*b - (b^3 - (2*a^2 - 1)*b)*cos(x))*sin(x) - 2*(2*a*b*cos(x)^2 - a*b + (b^3 + b)*cos
(x) - (b^2 - (a*b^2 - a)*cos(x) + 1)*sin(x))*sqrt(-a^2 + b^2 + 1) + 2)/((b^2 - 1)*cos(x)^2 - a^2 - b^2 - 2*a*c
os(x) - 2*(a*b + b*cos(x))*sin(x)))/(a^2 - b^2 - 1), arctan(-(a*b*sin(x) + b^2 + a*cos(x) + 1)*sqrt(a^2 - b^2
- 1)/((b^3 - (a^2 - 1)*b)*cos(x) + (a^2 - b^2 - 1)*sin(x)))/sqrt(a^2 - b^2 - 1)]

________________________________________________________________________________________

Sympy [B] Leaf count of result is larger than twice the leaf count of optimal. 1872 vs. \(2 (37) = 74\).
time = 210.90, size = 1872, normalized size = 39.83 \begin {gather*} \text {Too large to display} \end {gather*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

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

[Out]

Piecewise((2*b**4*sqrt(b**2 + 1)/(b**6*tan(x/2) - b**5*sqrt(b**2 + 1) - 5*b**5 + 6*b**4*sqrt(b**2 + 1)*tan(x/2
) + 18*b**4*tan(x/2) - 12*b**3*sqrt(b**2 + 1) - 20*b**3 + 32*b**2*sqrt(b**2 + 1)*tan(x/2) + 48*b**2*tan(x/2) -
 16*b*sqrt(b**2 + 1) - 16*b + 32*sqrt(b**2 + 1)*tan(x/2) + 32*tan(x/2)) + 10*b**4/(b**6*tan(x/2) - b**5*sqrt(b
**2 + 1) - 5*b**5 + 6*b**4*sqrt(b**2 + 1)*tan(x/2) + 18*b**4*tan(x/2) - 12*b**3*sqrt(b**2 + 1) - 20*b**3 + 32*
b**2*sqrt(b**2 + 1)*tan(x/2) + 48*b**2*tan(x/2) - 16*b*sqrt(b**2 + 1) - 16*b + 32*sqrt(b**2 + 1)*tan(x/2) + 32
*tan(x/2)) + 24*b**2*sqrt(b**2 + 1)/(b**6*tan(x/2) - b**5*sqrt(b**2 + 1) - 5*b**5 + 6*b**4*sqrt(b**2 + 1)*tan(
x/2) + 18*b**4*tan(x/2) - 12*b**3*sqrt(b**2 + 1) - 20*b**3 + 32*b**2*sqrt(b**2 + 1)*tan(x/2) + 48*b**2*tan(x/2
) - 16*b*sqrt(b**2 + 1) - 16*b + 32*sqrt(b**2 + 1)*tan(x/2) + 32*tan(x/2)) + 40*b**2/(b**6*tan(x/2) - b**5*sqr
t(b**2 + 1) - 5*b**5 + 6*b**4*sqrt(b**2 + 1)*tan(x/2) + 18*b**4*tan(x/2) - 12*b**3*sqrt(b**2 + 1) - 20*b**3 +
32*b**2*sqrt(b**2 + 1)*tan(x/2) + 48*b**2*tan(x/2) - 16*b*sqrt(b**2 + 1) - 16*b + 32*sqrt(b**2 + 1)*tan(x/2) +
 32*tan(x/2)) + 32*sqrt(b**2 + 1)/(b**6*tan(x/2) - b**5*sqrt(b**2 + 1) - 5*b**5 + 6*b**4*sqrt(b**2 + 1)*tan(x/
2) + 18*b**4*tan(x/2) - 12*b**3*sqrt(b**2 + 1) - 20*b**3 + 32*b**2*sqrt(b**2 + 1)*tan(x/2) + 48*b**2*tan(x/2)
- 16*b*sqrt(b**2 + 1) - 16*b + 32*sqrt(b**2 + 1)*tan(x/2) + 32*tan(x/2)) + 32/(b**6*tan(x/2) - b**5*sqrt(b**2
+ 1) - 5*b**5 + 6*b**4*sqrt(b**2 + 1)*tan(x/2) + 18*b**4*tan(x/2) - 12*b**3*sqrt(b**2 + 1) - 20*b**3 + 32*b**2
*sqrt(b**2 + 1)*tan(x/2) + 48*b**2*tan(x/2) - 16*b*sqrt(b**2 + 1) - 16*b + 32*sqrt(b**2 + 1)*tan(x/2) + 32*tan
(x/2)), Eq(a, -sqrt(b**2 + 1))), (-2*b**4*sqrt(b**2 + 1)/(b**6*tan(x/2) + b**5*sqrt(b**2 + 1) - 5*b**5 - 6*b**
4*sqrt(b**2 + 1)*tan(x/2) + 18*b**4*tan(x/2) + 12*b**3*sqrt(b**2 + 1) - 20*b**3 - 32*b**2*sqrt(b**2 + 1)*tan(x
/2) + 48*b**2*tan(x/2) + 16*b*sqrt(b**2 + 1) - 16*b - 32*sqrt(b**2 + 1)*tan(x/2) + 32*tan(x/2)) + 10*b**4/(b**
6*tan(x/2) + b**5*sqrt(b**2 + 1) - 5*b**5 - 6*b**4*sqrt(b**2 + 1)*tan(x/2) + 18*b**4*tan(x/2) + 12*b**3*sqrt(b
**2 + 1) - 20*b**3 - 32*b**2*sqrt(b**2 + 1)*tan(x/2) + 48*b**2*tan(x/2) + 16*b*sqrt(b**2 + 1) - 16*b - 32*sqrt
(b**2 + 1)*tan(x/2) + 32*tan(x/2)) - 24*b**2*sqrt(b**2 + 1)/(b**6*tan(x/2) + b**5*sqrt(b**2 + 1) - 5*b**5 - 6*
b**4*sqrt(b**2 + 1)*tan(x/2) + 18*b**4*tan(x/2) + 12*b**3*sqrt(b**2 + 1) - 20*b**3 - 32*b**2*sqrt(b**2 + 1)*ta
n(x/2) + 48*b**2*tan(x/2) + 16*b*sqrt(b**2 + 1) - 16*b - 32*sqrt(b**2 + 1)*tan(x/2) + 32*tan(x/2)) + 40*b**2/(
b**6*tan(x/2) + b**5*sqrt(b**2 + 1) - 5*b**5 - 6*b**4*sqrt(b**2 + 1)*tan(x/2) + 18*b**4*tan(x/2) + 12*b**3*sqr
t(b**2 + 1) - 20*b**3 - 32*b**2*sqrt(b**2 + 1)*tan(x/2) + 48*b**2*tan(x/2) + 16*b*sqrt(b**2 + 1) - 16*b - 32*s
qrt(b**2 + 1)*tan(x/2) + 32*tan(x/2)) - 32*sqrt(b**2 + 1)/(b**6*tan(x/2) + b**5*sqrt(b**2 + 1) - 5*b**5 - 6*b*
*4*sqrt(b**2 + 1)*tan(x/2) + 18*b**4*tan(x/2) + 12*b**3*sqrt(b**2 + 1) - 20*b**3 - 32*b**2*sqrt(b**2 + 1)*tan(
x/2) + 48*b**2*tan(x/2) + 16*b*sqrt(b**2 + 1) - 16*b - 32*sqrt(b**2 + 1)*tan(x/2) + 32*tan(x/2)) + 32/(b**6*ta
n(x/2) + b**5*sqrt(b**2 + 1) - 5*b**5 - 6*b**4*sqrt(b**2 + 1)*tan(x/2) + 18*b**4*tan(x/2) + 12*b**3*sqrt(b**2
+ 1) - 20*b**3 - 32*b**2*sqrt(b**2 + 1)*tan(x/2) + 48*b**2*tan(x/2) + 16*b*sqrt(b**2 + 1) - 16*b - 32*sqrt(b**
2 + 1)*tan(x/2) + 32*tan(x/2)), Eq(a, sqrt(b**2 + 1))), (log(tan(x/2) + 1/b)/b, Eq(a, 1)), (log(b/(a - 1) + ta
n(x/2) - sqrt(-a**2 + b**2 + 1)/(a - 1))/sqrt(-a**2 + b**2 + 1) - log(b/(a - 1) + tan(x/2) + sqrt(-a**2 + b**2
 + 1)/(a - 1))/sqrt(-a**2 + b**2 + 1), True))

________________________________________________________________________________________

Giac [A]
time = 1.10, size = 60, normalized size = 1.28 \begin {gather*} \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 ) + b - \tan \left (\frac {1}{2} \, x\right )}{\sqrt {a^{2} - b^{2} - 1}}\right )\right )}}{\sqrt {a^{2} - b^{2} - 1}} \end {gather*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

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

[Out]

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

________________________________________________________________________________________

Mupad [B]
time = 0.26, size = 58, normalized size = 1.23 \begin {gather*} \left \{\begin {array}{cl} \frac {\ln \left (b\,\mathrm {tan}\left (\frac {x}{2}\right )+1\right )}{b} & \text {\ if\ \ }a=1\\ \frac {2\,\mathrm {atan}\left (\frac {b+\mathrm {tan}\left (\frac {x}{2}\right )\,\left (a-1\right )}{\sqrt {a^2-b^2-1}}\right )}{\sqrt {a^2-b^2-1}} & \text {\ if\ \ }a\neq 1 \end {array}\right . \end {gather*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

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

[Out]

piecewise(a == 1, log(b*tan(x/2) + 1)/b, a ~= 1, (2*atan((b + tan(x/2)*(a - 1))/(a^2 - b^2 - 1)^(1/2)))/(a^2 -
 b^2 - 1)^(1/2))

________________________________________________________________________________________