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

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

Optimal result

Integrand size = 11, antiderivative size = 36 \[ \int \frac {1}{b \cos (x)+a \sin (x)} \, dx=-\frac {\text {arctanh}\left (\frac {a \cos (x)-b \sin (x)}{\sqrt {a^2+b^2}}\right )}{\sqrt {a^2+b^2}} \]

[Out]

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

Rubi [A] (verified)

Time = 0.02 (sec) , antiderivative size = 36, 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.182, Rules used = {3153, 212} \[ \int \frac {1}{b \cos (x)+a \sin (x)} \, dx=-\frac {\text {arctanh}\left (\frac {a \cos (x)-b \sin (x)}{\sqrt {a^2+b^2}}\right )}{\sqrt {a^2+b^2}} \]

[In]

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

[Out]

-(ArcTanh[(a*Cos[x] - b*Sin[x])/Sqrt[a^2 + b^2]]/Sqrt[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 3153

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

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

Mathematica [A] (verified)

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

[In]

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

[Out]

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

Maple [A] (verified)

Time = 0.28 (sec) , antiderivative size = 35, normalized size of antiderivative = 0.97

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

[In]

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

[Out]

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

Fricas [B] (verification not implemented)

Leaf count of result is larger than twice the leaf count of optimal. 98 vs. \(2 (32) = 64\).

Time = 0.27 (sec) , antiderivative size = 98, normalized size of antiderivative = 2.72 \[ \int \frac {1}{b \cos (x)+a \sin (x)} \, dx=\frac {\log \left (-\frac {2 \, a b \cos \left (x\right ) \sin \left (x\right ) - {\left (a^{2} - b^{2}\right )} \cos \left (x\right )^{2} - a^{2} - 2 \, b^{2} + 2 \, \sqrt {a^{2} + b^{2}} {\left (a \cos \left (x\right ) - b \sin \left (x\right )\right )}}{2 \, a b \cos \left (x\right ) \sin \left (x\right ) - {\left (a^{2} - b^{2}\right )} \cos \left (x\right )^{2} + a^{2}}\right )}{2 \, \sqrt {a^{2} + b^{2}}} \]

[In]

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

[Out]

1/2*log(-(2*a*b*cos(x)*sin(x) - (a^2 - b^2)*cos(x)^2 - a^2 - 2*b^2 + 2*sqrt(a^2 + b^2)*(a*cos(x) - b*sin(x)))/
(2*a*b*cos(x)*sin(x) - (a^2 - b^2)*cos(x)^2 + a^2))/sqrt(a^2 + b^2)

Sympy [C] (verification not implemented)

Result contains complex when optimal does not.

Time = 1.56 (sec) , antiderivative size = 121, normalized size of antiderivative = 3.36 \[ \int \frac {1}{b \cos (x)+a \sin (x)} \, dx=\begin {cases} \tilde {\infty } \left (- \log {\left (\tan {\left (\frac {x}{2} \right )} - 1 \right )} + \log {\left (\tan {\left (\frac {x}{2} \right )} + 1 \right )}\right ) & \text {for}\: a = 0 \wedge b = 0 \\\frac {\log {\left (\tan {\left (\frac {x}{2} \right )} \right )}}{a} & \text {for}\: b = 0 \\- \frac {i}{- i b \sin {\left (x \right )} + b \cos {\left (x \right )}} & \text {for}\: a = - i b \\\frac {i}{i b \sin {\left (x \right )} + b \cos {\left (x \right )}} & \text {for}\: a = i b \\- \frac {\log {\left (- \frac {a}{b} + \tan {\left (\frac {x}{2} \right )} - \frac {\sqrt {a^{2} + b^{2}}}{b} \right )}}{\sqrt {a^{2} + b^{2}}} + \frac {\log {\left (- \frac {a}{b} + \tan {\left (\frac {x}{2} \right )} + \frac {\sqrt {a^{2} + b^{2}}}{b} \right )}}{\sqrt {a^{2} + b^{2}}} & \text {otherwise} \end {cases} \]

[In]

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

[Out]

Piecewise((zoo*(-log(tan(x/2) - 1) + log(tan(x/2) + 1)), Eq(a, 0) & Eq(b, 0)), (log(tan(x/2))/a, Eq(b, 0)), (-
I/(-I*b*sin(x) + b*cos(x)), Eq(a, -I*b)), (I/(I*b*sin(x) + b*cos(x)), Eq(a, I*b)), (-log(-a/b + tan(x/2) - sqr
t(a**2 + b**2)/b)/sqrt(a**2 + b**2) + log(-a/b + tan(x/2) + sqrt(a**2 + b**2)/b)/sqrt(a**2 + b**2), True))

Maxima [A] (verification not implemented)

none

Time = 0.30 (sec) , antiderivative size = 61, normalized size of antiderivative = 1.69 \[ \int \frac {1}{b \cos (x)+a \sin (x)} \, dx=-\frac {\log \left (\frac {a - \frac {b \sin \left (x\right )}{\cos \left (x\right ) + 1} + \sqrt {a^{2} + b^{2}}}{a - \frac {b \sin \left (x\right )}{\cos \left (x\right ) + 1} - \sqrt {a^{2} + b^{2}}}\right )}{\sqrt {a^{2} + b^{2}}} \]

[In]

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

[Out]

-log((a - b*sin(x)/(cos(x) + 1) + sqrt(a^2 + b^2))/(a - b*sin(x)/(cos(x) + 1) - sqrt(a^2 + b^2)))/sqrt(a^2 + b
^2)

Giac [A] (verification not implemented)

none

Time = 0.30 (sec) , antiderivative size = 61, normalized size of antiderivative = 1.69 \[ \int \frac {1}{b \cos (x)+a \sin (x)} \, dx=-\frac {\log \left (\frac {{\left | 2 \, b \tan \left (\frac {1}{2} \, x\right ) - 2 \, a - 2 \, \sqrt {a^{2} + b^{2}} \right |}}{{\left | 2 \, b \tan \left (\frac {1}{2} \, x\right ) - 2 \, a + 2 \, \sqrt {a^{2} + b^{2}} \right |}}\right )}{\sqrt {a^{2} + b^{2}}} \]

[In]

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

[Out]

-log(abs(2*b*tan(1/2*x) - 2*a - 2*sqrt(a^2 + b^2))/abs(2*b*tan(1/2*x) - 2*a + 2*sqrt(a^2 + b^2)))/sqrt(a^2 + b
^2)

Mupad [B] (verification not implemented)

Time = 0.79 (sec) , antiderivative size = 31, normalized size of antiderivative = 0.86 \[ \int \frac {1}{b \cos (x)+a \sin (x)} \, dx=-\frac {2\,\mathrm {atanh}\left (\frac {a-b\,\mathrm {tan}\left (\frac {x}{2}\right )}{\sqrt {a^2+b^2}}\right )}{\sqrt {a^2+b^2}} \]

[In]

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

[Out]

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