\(\int (-\cos (x)+\sec (x))^2 \, dx\) [324]

   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 = 22 \[ \int (-\cos (x)+\sec (x))^2 \, dx=-\frac {3 x}{2}+\frac {3 \tan (x)}{2}-\frac {1}{2} \sin ^2(x) \tan (x) \]

[Out]

-3/2*x+3/2*tan(x)-1/2*sin(x)^2*tan(x)

Rubi [A] (verified)

Time = 0.03 (sec) , antiderivative size = 22, normalized size of antiderivative = 1.00, number of steps used = 4, number of rules used = 3, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.333, Rules used = {294, 327, 209} \[ \int (-\cos (x)+\sec (x))^2 \, dx=-\frac {3 x}{2}+\frac {3 \tan (x)}{2}-\frac {1}{2} \sin ^2(x) \tan (x) \]

[In]

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

[Out]

(-3*x)/2 + (3*Tan[x])/2 - (Sin[x]^2*Tan[x])/2

Rule 209

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

Rule 294

Int[((c_.)*(x_))^(m_.)*((a_) + (b_.)*(x_)^(n_))^(p_), x_Symbol] :> Simp[c^(n - 1)*(c*x)^(m - n + 1)*((a + b*x^
n)^(p + 1)/(b*n*(p + 1))), x] - Dist[c^n*((m - n + 1)/(b*n*(p + 1))), Int[(c*x)^(m - n)*(a + b*x^n)^(p + 1), x
], x] /; FreeQ[{a, b, c}, x] && IGtQ[n, 0] && LtQ[p, -1] && GtQ[m + 1, n] &&  !ILtQ[(m + n*(p + 1) + 1)/n, 0]
&& IntBinomialQ[a, b, c, n, m, p, x]

Rule 327

Int[((c_.)*(x_))^(m_)*((a_) + (b_.)*(x_)^(n_))^(p_), x_Symbol] :> Simp[c^(n - 1)*(c*x)^(m - n + 1)*((a + b*x^n
)^(p + 1)/(b*(m + n*p + 1))), x] - Dist[a*c^n*((m - n + 1)/(b*(m + n*p + 1))), Int[(c*x)^(m - n)*(a + b*x^n)^p
, x], x] /; FreeQ[{a, b, c, p}, x] && IGtQ[n, 0] && GtQ[m, n - 1] && NeQ[m + n*p + 1, 0] && IntBinomialQ[a, b,
 c, n, m, p, x]

Rubi steps \begin{align*} \text {integral}& = \text {Subst}\left (\int \frac {x^4}{\left (1+x^2\right )^2} \, dx,x,\tan (x)\right ) \\ & = -\frac {1}{2} \sin ^2(x) \tan (x)+\frac {3}{2} \text {Subst}\left (\int \frac {x^2}{1+x^2} \, dx,x,\tan (x)\right ) \\ & = \frac {3 \tan (x)}{2}-\frac {1}{2} \sin ^2(x) \tan (x)-\frac {3}{2} \text {Subst}\left (\int \frac {1}{1+x^2} \, dx,x,\tan (x)\right ) \\ & = -\frac {3 x}{2}+\frac {3 \tan (x)}{2}-\frac {1}{2} \sin ^2(x) \tan (x) \\ \end{align*}

Mathematica [A] (verified)

Time = 0.02 (sec) , antiderivative size = 16, normalized size of antiderivative = 0.73 \[ \int (-\cos (x)+\sec (x))^2 \, dx=-\frac {3 x}{2}+\frac {1}{4} \sin (2 x)+\tan (x) \]

[In]

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

[Out]

(-3*x)/2 + Sin[2*x]/4 + Tan[x]

Maple [A] (verified)

Time = 0.98 (sec) , antiderivative size = 13, normalized size of antiderivative = 0.59

method result size
default \(\frac {\cos \left (x \right ) \sin \left (x \right )}{2}-\frac {3 x}{2}+\tan \left (x \right )\) \(13\)
parallelrisch \(-\frac {3 x}{2}+\frac {\sin \left (2 x \right )}{4}+\tan \left (x \right )\) \(13\)
parts \(\frac {\cos \left (x \right ) \sin \left (x \right )}{2}-\frac {3 x}{2}+\tan \left (x \right )\) \(13\)
risch \(-\frac {3 x}{2}-\frac {i {\mathrm e}^{2 i x}}{8}+\frac {i {\mathrm e}^{-2 i x}}{8}+\frac {2 i}{{\mathrm e}^{2 i x}+1}\) \(33\)
norman \(\frac {\frac {3 x}{2}-2 \tan \left (\frac {x}{2}\right )^{3}-3 \tan \left (\frac {x}{2}\right )^{5}+\frac {3 x \tan \left (\frac {x}{2}\right )^{2}}{2}-\frac {3 x \tan \left (\frac {x}{2}\right )^{4}}{2}-\frac {3 x \tan \left (\frac {x}{2}\right )^{6}}{2}-3 \tan \left (\frac {x}{2}\right )}{\left (1+\tan \left (\frac {x}{2}\right )^{2}\right )^{2} \left (\tan \left (\frac {x}{2}\right )^{2}-1\right )}\) \(75\)

[In]

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

[Out]

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

Fricas [A] (verification not implemented)

none

Time = 0.24 (sec) , antiderivative size = 22, normalized size of antiderivative = 1.00 \[ \int (-\cos (x)+\sec (x))^2 \, dx=-\frac {3 \, x \cos \left (x\right ) - {\left (\cos \left (x\right )^{2} + 2\right )} \sin \left (x\right )}{2 \, \cos \left (x\right )} \]

[In]

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

[Out]

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

Sympy [A] (verification not implemented)

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

[In]

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

[Out]

-3*x/2 + sin(2*x)/4 + tan(x)

Maxima [A] (verification not implemented)

none

Time = 0.22 (sec) , antiderivative size = 12, normalized size of antiderivative = 0.55 \[ \int (-\cos (x)+\sec (x))^2 \, dx=-\frac {3}{2} \, x + \frac {1}{4} \, \sin \left (2 \, x\right ) + \tan \left (x\right ) \]

[In]

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

[Out]

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

Giac [A] (verification not implemented)

none

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

[In]

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

[Out]

-3/2*x + 1/2*tan(x)/(tan(x)^2 + 1) + tan(x)

Mupad [B] (verification not implemented)

Time = 26.34 (sec) , antiderivative size = 49, normalized size of antiderivative = 2.23 \[ \int (-\cos (x)+\sec (x))^2 \, dx=-\frac {3\,x}{2}-\frac {3\,{\mathrm {tan}\left (\frac {x}{2}\right )}^5+2\,{\mathrm {tan}\left (\frac {x}{2}\right )}^3+3\,\mathrm {tan}\left (\frac {x}{2}\right )}{\left ({\mathrm {tan}\left (\frac {x}{2}\right )}^2-1\right )\,{\left ({\mathrm {tan}\left (\frac {x}{2}\right )}^2+1\right )}^2} \]

[In]

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

[Out]

- (3*x)/2 - (3*tan(x/2) + 2*tan(x/2)^3 + 3*tan(x/2)^5)/((tan(x/2)^2 - 1)*(tan(x/2)^2 + 1)^2)