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

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

Optimal result

Integrand size = 7, antiderivative size = 21 \[ \int \frac {1}{\cos (x)+\sin (x)} \, dx=-\frac {\text {arctanh}\left (\frac {\cos (x)-\sin (x)}{\sqrt {2}}\right )}{\sqrt {2}} \]

[Out]

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

Rubi [A] (verified)

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

[In]

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

[Out]

-(ArcTanh[(Cos[x] - Sin[x])/Sqrt[2]]/Sqrt[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}{2-x^2} \, dx,x,\cos (x)-\sin (x)\right ) \\ & = -\frac {\text {arctanh}\left (\frac {\cos (x)-\sin (x)}{\sqrt {2}}\right )}{\sqrt {2}} \\ \end{align*}

Mathematica [C] (verified)

Result contains complex when optimal does not.

Time = 0.02 (sec) , antiderivative size = 24, normalized size of antiderivative = 1.14 \[ \int \frac {1}{\cos (x)+\sin (x)} \, dx=(-1-i) (-1)^{3/4} \text {arctanh}\left (\frac {-1+\tan \left (\frac {x}{2}\right )}{\sqrt {2}}\right ) \]

[In]

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

[Out]

(-1 - I)*(-1)^(3/4)*ArcTanh[(-1 + Tan[x/2])/Sqrt[2]]

Maple [A] (verified)

Time = 0.11 (sec) , antiderivative size = 19, normalized size of antiderivative = 0.90

method result size
default \(\sqrt {2}\, \operatorname {arctanh}\left (\frac {\left (2 \tan \left (\frac {x}{2}\right )-2\right ) \sqrt {2}}{4}\right )\) \(19\)
risch \(\frac {\sqrt {2}\, \ln \left ({\mathrm e}^{i x}-\frac {\sqrt {2}}{2}+\frac {i \sqrt {2}}{2}\right )}{2}-\frac {\sqrt {2}\, \ln \left ({\mathrm e}^{i x}+\frac {\sqrt {2}}{2}-\frac {i \sqrt {2}}{2}\right )}{2}\) \(48\)

[In]

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

[Out]

2^(1/2)*arctanh(1/4*(2*tan(1/2*x)-2)*2^(1/2))

Fricas [B] (verification not implemented)

Leaf count of result is larger than twice the leaf count of optimal. 38 vs. \(2 (18) = 36\).

Time = 0.25 (sec) , antiderivative size = 38, normalized size of antiderivative = 1.81 \[ \int \frac {1}{\cos (x)+\sin (x)} \, dx=\frac {1}{4} \, \sqrt {2} \log \left (\frac {2 \, {\left (\sqrt {2} - \cos \left (x\right )\right )} \sin \left (x\right ) - 2 \, \sqrt {2} \cos \left (x\right ) + 3}{2 \, \cos \left (x\right ) \sin \left (x\right ) + 1}\right ) \]

[In]

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

[Out]

1/4*sqrt(2)*log((2*(sqrt(2) - cos(x))*sin(x) - 2*sqrt(2)*cos(x) + 3)/(2*cos(x)*sin(x) + 1))

Sympy [A] (verification not implemented)

Time = 0.24 (sec) , antiderivative size = 39, normalized size of antiderivative = 1.86 \[ \int \frac {1}{\cos (x)+\sin (x)} \, dx=\frac {\sqrt {2} \log {\left (\tan {\left (\frac {x}{2} \right )} - 1 + \sqrt {2} \right )}}{2} - \frac {\sqrt {2} \log {\left (\tan {\left (\frac {x}{2} \right )} - \sqrt {2} - 1 \right )}}{2} \]

[In]

integrate(1/(cos(x)+sin(x)),x)

[Out]

sqrt(2)*log(tan(x/2) - 1 + sqrt(2))/2 - sqrt(2)*log(tan(x/2) - sqrt(2) - 1)/2

Maxima [B] (verification not implemented)

Leaf count of result is larger than twice the leaf count of optimal. 39 vs. \(2 (18) = 36\).

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

[In]

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

[Out]

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

Giac [B] (verification not implemented)

Leaf count of result is larger than twice the leaf count of optimal. 37 vs. \(2 (18) = 36\).

Time = 0.31 (sec) , antiderivative size = 37, normalized size of antiderivative = 1.76 \[ \int \frac {1}{\cos (x)+\sin (x)} \, dx=-\frac {1}{2} \, \sqrt {2} \log \left (\frac {{\left | -2 \, \sqrt {2} + 2 \, \tan \left (\frac {1}{2} \, x\right ) - 2 \right |}}{{\left | 2 \, \sqrt {2} + 2 \, \tan \left (\frac {1}{2} \, x\right ) - 2 \right |}}\right ) \]

[In]

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

[Out]

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

Mupad [B] (verification not implemented)

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

[In]

int(1/(cos(x) + sin(x)),x)

[Out]

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