\(\int (-\sec (x)+\tan (x))^2 \, dx\) [40]

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

Optimal result

Integrand size = 9, antiderivative size = 14 \[ \int (-\sec (x)+\tan (x))^2 \, dx=-x-\frac {2 \cos (x)}{1+\sin (x)} \]

[Out]

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

Rubi [A] (verified)

Time = 0.06 (sec) , antiderivative size = 14, normalized size of antiderivative = 1.00, number of steps used = 4, number of rules used = 4, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.444, Rules used = {4476, 2749, 2759, 8} \[ \int (-\sec (x)+\tan (x))^2 \, dx=-x-\frac {2 \cos (x)}{\sin (x)+1} \]

[In]

Int[(-Sec[x] + Tan[x])^2,x]

[Out]

-x - (2*Cos[x])/(1 + Sin[x])

Rule 8

Int[a_, x_Symbol] :> Simp[a*x, x] /; FreeQ[a, x]

Rule 2749

Int[(cos[(e_.) + (f_.)*(x_)]*(g_.))^(p_)*((a_) + (b_.)*sin[(e_.) + (f_.)*(x_)])^(m_), x_Symbol] :> Dist[(a/g)^
(2*m), Int[(g*Cos[e + f*x])^(2*m + p)/(a - b*Sin[e + f*x])^m, x], x] /; FreeQ[{a, b, e, f, g}, x] && EqQ[a^2 -
 b^2, 0] && IntegerQ[m] && LtQ[p, -1] && GeQ[2*m + p, 0]

Rule 2759

Int[(cos[(e_.) + (f_.)*(x_)]*(g_.))^(p_)*((a_) + (b_.)*sin[(e_.) + (f_.)*(x_)])^(m_), x_Symbol] :> Simp[2*g*(g
*Cos[e + f*x])^(p - 1)*((a + b*Sin[e + f*x])^(m + 1)/(b*f*(2*m + p + 1))), x] + Dist[g^2*((p - 1)/(b^2*(2*m +
p + 1))), Int[(g*Cos[e + f*x])^(p - 2)*(a + b*Sin[e + f*x])^(m + 2), x], x] /; FreeQ[{a, b, e, f, g}, x] && Eq
Q[a^2 - b^2, 0] && LeQ[m, -2] && GtQ[p, 1] && NeQ[2*m + p + 1, 0] &&  !ILtQ[m + p + 1, 0] && IntegersQ[2*m, 2*
p]

Rule 4476

Int[(u_.)*((b_.)*sec[(c_.) + (d_.)*(x_)]^(n_.) + (a_.)*tan[(c_.) + (d_.)*(x_)]^(n_.))^(p_), x_Symbol] :> Int[A
ctivateTrig[u]*Sec[c + d*x]^(n*p)*(b + a*Sin[c + d*x]^n)^p, x] /; FreeQ[{a, b, c, d}, x] && IntegersQ[n, p]

Rubi steps \begin{align*} \text {integral}& = \int \sec ^2(x) (-1+\sin (x))^2 \, dx \\ & = \int \frac {\cos ^2(x)}{(-1-\sin (x))^2} \, dx \\ & = -\frac {2 \cos (x)}{1+\sin (x)}-\int 1 \, dx \\ & = -x-\frac {2 \cos (x)}{1+\sin (x)} \\ \end{align*}

Mathematica [A] (verified)

Time = 0.01 (sec) , antiderivative size = 14, normalized size of antiderivative = 1.00 \[ \int (-\sec (x)+\tan (x))^2 \, dx=-\arctan (\tan (x))-2 \sec (x)+2 \tan (x) \]

[In]

Integrate[(-Sec[x] + Tan[x])^2,x]

[Out]

-ArcTan[Tan[x]] - 2*Sec[x] + 2*Tan[x]

Maple [A] (verified)

Time = 0.44 (sec) , antiderivative size = 15, normalized size of antiderivative = 1.07

method result size
default \(-x +2 \tan \left (x \right )-\frac {2}{\cos \left (x \right )}\) \(15\)
parts \(2 \tan \left (x \right )-\arctan \left (\tan \left (x \right )\right )-2 \sec \left (x \right )\) \(15\)
risch \(-x -\frac {4}{i+{\mathrm e}^{i x}}\) \(17\)

[In]

int((-sec(x)+tan(x))^2,x,method=_RETURNVERBOSE)

[Out]

-x+2*tan(x)-2/cos(x)

Fricas [A] (verification not implemented)

none

Time = 0.25 (sec) , antiderivative size = 25, normalized size of antiderivative = 1.79 \[ \int (-\sec (x)+\tan (x))^2 \, dx=-\frac {{\left (x + 2\right )} \cos \left (x\right ) + {\left (x - 2\right )} \sin \left (x\right ) + x + 2}{\cos \left (x\right ) + \sin \left (x\right ) + 1} \]

[In]

integrate((-sec(x)+tan(x))^2,x, algorithm="fricas")

[Out]

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

Sympy [A] (verification not implemented)

Time = 0.33 (sec) , antiderivative size = 10, normalized size of antiderivative = 0.71 \[ \int (-\sec (x)+\tan (x))^2 \, dx=- x + 2 \tan {\left (x \right )} - 2 \sec {\left (x \right )} \]

[In]

integrate((-sec(x)+tan(x))**2,x)

[Out]

-x + 2*tan(x) - 2*sec(x)

Maxima [A] (verification not implemented)

none

Time = 0.28 (sec) , antiderivative size = 14, normalized size of antiderivative = 1.00 \[ \int (-\sec (x)+\tan (x))^2 \, dx=-x - \frac {2}{\cos \left (x\right )} + 2 \, \tan \left (x\right ) \]

[In]

integrate((-sec(x)+tan(x))^2,x, algorithm="maxima")

[Out]

-x - 2/cos(x) + 2*tan(x)

Giac [A] (verification not implemented)

none

Time = 0.30 (sec) , antiderivative size = 14, normalized size of antiderivative = 1.00 \[ \int (-\sec (x)+\tan (x))^2 \, dx=-x - \frac {4}{\tan \left (\frac {1}{2} \, x\right ) + 1} \]

[In]

integrate((-sec(x)+tan(x))^2,x, algorithm="giac")

[Out]

-x - 4/(tan(1/2*x) + 1)

Mupad [B] (verification not implemented)

Time = 0.30 (sec) , antiderivative size = 14, normalized size of antiderivative = 1.00 \[ \int (-\sec (x)+\tan (x))^2 \, dx=-x-\frac {4}{\mathrm {tan}\left (\frac {x}{2}\right )+1} \]

[In]

int((tan(x) - 1/cos(x))^2,x)

[Out]

- x - 4/(tan(x/2) + 1)