\(\int (-\cot (x)+\tan (x))^2 \, dx\) [39]

   Optimal result
   Rubi [A] (verified)
   Mathematica [C] (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 = 10 \[ \int (-\cot (x)+\tan (x))^2 \, dx=-4 x-\cot (x)+\tan (x) \]

[Out]

-4*x-cot(x)+tan(x)

Rubi [A] (verified)

Time = 0.03 (sec) , antiderivative size = 10, normalized size of antiderivative = 1.00, number of steps used = 4, number of rules used = 2, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.222, Rules used = {472, 209} \[ \int (-\cot (x)+\tan (x))^2 \, dx=-4 x+\tan (x)-\cot (x) \]

[In]

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

[Out]

-4*x - Cot[x] + Tan[x]

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 472

Int[(((e_.)*(x_))^(m_.)*((a_) + (b_.)*(x_)^(n_))^(p_))/((c_) + (d_.)*(x_)^(n_)), x_Symbol] :> Int[ExpandIntegr
and[(e*x)^m*((a + b*x^n)^p/(c + d*x^n)), x], x] /; FreeQ[{a, b, c, d, e, m}, x] && NeQ[b*c - a*d, 0] && IGtQ[n
, 0] && IGtQ[p, 0] && (IntegerQ[m] || IGtQ[2*(m + 1), 0] ||  !RationalQ[m])

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

Mathematica [C] (verified)

Result contains higher order function than in optimal. Order 5 vs. order 3 in optimal.

Time = 0.01 (sec) , antiderivative size = 29, normalized size of antiderivative = 2.90 \[ \int (-\cot (x)+\tan (x))^2 \, dx=-2 x-\arctan (\tan (x))-\cot (x) \operatorname {Hypergeometric2F1}\left (-\frac {1}{2},1,\frac {1}{2},-\tan ^2(x)\right )+\tan (x) \]

[In]

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

[Out]

-2*x - ArcTan[Tan[x]] - Cot[x]*Hypergeometric2F1[-1/2, 1, 1/2, -Tan[x]^2] + Tan[x]

Maple [A] (verified)

Time = 0.18 (sec) , antiderivative size = 11, normalized size of antiderivative = 1.10

method result size
default \(-4 x -\cot \left (x \right )+\tan \left (x \right )\) \(11\)
parallelrisch \(-4 x -\cot \left (x \right )+\tan \left (x \right )\) \(11\)
norman \(\frac {-1+\tan ^{2}\left (x \right )-4 x \tan \left (x \right )}{\tan \left (x \right )}\) \(17\)
parts \(-\cot \left (x \right )+\frac {\pi }{2}-\operatorname {arccot}\left (\cot \left (x \right )\right )+\tan \left (x \right )-\arctan \left (\tan \left (x \right )\right )-2 x\) \(24\)
risch \(-4 x -\frac {4 i}{\left ({\mathrm e}^{2 i x}+1\right ) \left ({\mathrm e}^{2 i x}-1\right )}\) \(26\)

[In]

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

[Out]

-4*x-cot(x)+tan(x)

Fricas [A] (verification not implemented)

none

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

[In]

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

[Out]

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

Sympy [A] (verification not implemented)

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

[In]

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

[Out]

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

Maxima [A] (verification not implemented)

none

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

[In]

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

[Out]

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

Giac [A] (verification not implemented)

none

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

[In]

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

[Out]

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

Mupad [B] (verification not implemented)

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

[In]

int((cot(x) - tan(x))^2,x)

[Out]

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