3.40 \(\int (-\sec (x)+\tan (x))^2 \, dx\)

Optimal. Leaf size=14 \[ -x-\frac{2 \cos (x)}{\sin (x)+1} \]

[Out]

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

________________________________________________________________________________________

Rubi [A]  time = 0.0631115, antiderivative size = 14, normalized size of antiderivative = 1., number of steps used = 4, number of rules used = 4, integrand size = 9, \(\frac{\text{number of rules}}{\text{integrand size}}\) = 0.444, Rules used = {4391, 2670, 2680, 8} \[ -x-\frac{2 \cos (x)}{\sin (x)+1} \]

Antiderivative was successfully verified.

[In]

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

[Out]

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

Rule 4391

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]

Rule 2670

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 2680

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 8

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

Rubi steps

\begin{align*} \int (-\sec (x)+\tan (x))^2 \, dx &=\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]  time = 0.0067543, size = 12, normalized size = 0.86 \[ -x+2 \tan (x)-2 \sec (x) \]

Antiderivative was successfully verified.

[In]

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

[Out]

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

________________________________________________________________________________________

Maple [A]  time = 0.013, size = 15, normalized size = 1.1 \begin{align*} 2\,\tan \left ( x \right ) -x-2\, \left ( \cos \left ( x \right ) \right ) ^{-1} \end{align*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

int((-sec(x)+tan(x))^2,x)

[Out]

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

________________________________________________________________________________________

Maxima [A]  time = 1.47501, size = 19, normalized size = 1.36 \begin{align*} -x - \frac{2}{\cos \left (x\right )} + 2 \, \tan \left (x\right ) \end{align*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

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

[Out]

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

________________________________________________________________________________________

Fricas [A]  time = 2.04946, size = 89, normalized size = 6.36 \begin{align*} -\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} \end{align*}

Verification of antiderivative is not currently implemented for this CAS.

[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]  time = 1.11767, size = 10, normalized size = 0.71 \begin{align*} - x + 2 \tan{\left (x \right )} - 2 \sec{\left (x \right )} \end{align*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

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

[Out]

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

________________________________________________________________________________________

Giac [A]  time = 1.06971, size = 19, normalized size = 1.36 \begin{align*} -x - \frac{4}{\tan \left (\frac{1}{2} \, x\right ) + 1} \end{align*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

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

[Out]

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