\(\int (a \cot (x)+b \csc (x))^2 \, dx\) [286]

   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 = 11, antiderivative size = 29 \[ \int (a \cot (x)+b \csc (x))^2 \, dx=-a^2 x-(b+a \cos (x)) (a+b \cos (x)) \csc (x)-a b \sin (x) \]

[Out]

-a^2*x-(b+a*cos(x))*(a+b*cos(x))*csc(x)-a*b*sin(x)

Rubi [A] (verified)

Time = 0.06 (sec) , antiderivative size = 29, 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.273, Rules used = {4477, 2770, 2717} \[ \int (a \cot (x)+b \csc (x))^2 \, dx=a^2 (-x)-a b \sin (x)-\csc (x) (a \cos (x)+b) (a+b \cos (x)) \]

[In]

Int[(a*Cot[x] + b*Csc[x])^2,x]

[Out]

-(a^2*x) - (b + a*Cos[x])*(a + b*Cos[x])*Csc[x] - a*b*Sin[x]

Rule 2717

Int[sin[Pi/2 + (c_.) + (d_.)*(x_)], x_Symbol] :> Simp[Sin[c + d*x]/d, x] /; FreeQ[{c, d}, x]

Rule 2770

Int[(cos[(e_.) + (f_.)*(x_)]*(g_.))^(p_)*((a_) + (b_.)*sin[(e_.) + (f_.)*(x_)])^(m_), x_Symbol] :> Simp[(-(g*C
os[e + f*x])^(p + 1))*(a + b*Sin[e + f*x])^(m - 1)*((b + a*Sin[e + f*x])/(f*g*(p + 1))), x] + Dist[1/(g^2*(p +
 1)), Int[(g*Cos[e + f*x])^(p + 2)*(a + b*Sin[e + f*x])^(m - 2)*(b^2*(m - 1) + a^2*(p + 2) + a*b*(m + p + 1)*S
in[e + f*x]), x], x] /; FreeQ[{a, b, e, f, g}, x] && NeQ[a^2 - b^2, 0] && GtQ[m, 1] && LtQ[p, -1] && (Integers
Q[2*m, 2*p] || IntegerQ[m])

Rule 4477

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

Rubi steps \begin{align*} \text {integral}& = \int (b+a \cos (x))^2 \csc ^2(x) \, dx \\ & = -((b+a \cos (x)) (a+b \cos (x)) \csc (x))-\int \left (a^2+a b \cos (x)\right ) \, dx \\ & = -a^2 x-(b+a \cos (x)) (a+b \cos (x)) \csc (x)-(a b) \int \cos (x) \, dx \\ & = -a^2 x-(b+a \cos (x)) (a+b \cos (x)) \csc (x)-a b \sin (x) \\ \end{align*}

Mathematica [A] (verified)

Time = 0.16 (sec) , antiderivative size = 24, normalized size of antiderivative = 0.83 \[ \int (a \cot (x)+b \csc (x))^2 \, dx=-\left (\left (a^2+b^2\right ) \cot (x)\right )-a (a x+2 b \csc (x)) \]

[In]

Integrate[(a*Cot[x] + b*Csc[x])^2,x]

[Out]

-((a^2 + b^2)*Cot[x]) - a*(a*x + 2*b*Csc[x])

Maple [A] (verified)

Time = 1.12 (sec) , antiderivative size = 29, normalized size of antiderivative = 1.00

method result size
default \(-b^{2} \cot \left (x \right )-\frac {2 a b}{\sin \left (x \right )}+a^{2} \left (-\cot \left (x \right )-x \right )\) \(29\)
parts \(a^{2} \left (-\cot \left (x \right )+\frac {\pi }{2}-\operatorname {arccot}\left (\cot \left (x \right )\right )\right )-b^{2} \cot \left (x \right )-2 b \csc \left (x \right ) a\) \(32\)
risch \(-a^{2} x -\frac {2 i \left (2 a b \,{\mathrm e}^{i x}+a^{2}+b^{2}\right )}{{\mathrm e}^{2 i x}-1}\) \(36\)

[In]

int((a*cot(x)+b*csc(x))^2,x,method=_RETURNVERBOSE)

[Out]

-b^2*cot(x)-2*a*b/sin(x)+a^2*(-cot(x)-x)

Fricas [A] (verification not implemented)

none

Time = 0.24 (sec) , antiderivative size = 28, normalized size of antiderivative = 0.97 \[ \int (a \cot (x)+b \csc (x))^2 \, dx=-\frac {a^{2} x \sin \left (x\right ) + 2 \, a b + {\left (a^{2} + b^{2}\right )} \cos \left (x\right )}{\sin \left (x\right )} \]

[In]

integrate((a*cot(x)+b*csc(x))^2,x, algorithm="fricas")

[Out]

-(a^2*x*sin(x) + 2*a*b + (a^2 + b^2)*cos(x))/sin(x)

Sympy [A] (verification not implemented)

Time = 1.14 (sec) , antiderivative size = 31, normalized size of antiderivative = 1.07 \[ \int (a \cot (x)+b \csc (x))^2 \, dx=- a^{2} x - \frac {a^{2} \cos {\left (x \right )}}{\sin {\left (x \right )}} - 2 a b \csc {\left (x \right )} - b^{2} \cot {\left (x \right )} \]

[In]

integrate((a*cot(x)+b*csc(x))**2,x)

[Out]

-a**2*x - a**2*cos(x)/sin(x) - 2*a*b*csc(x) - b**2*cot(x)

Maxima [A] (verification not implemented)

none

Time = 0.32 (sec) , antiderivative size = 29, normalized size of antiderivative = 1.00 \[ \int (a \cot (x)+b \csc (x))^2 \, dx=-a^{2} {\left (x + \frac {1}{\tan \left (x\right )}\right )} - \frac {2 \, a b}{\sin \left (x\right )} - \frac {b^{2}}{\tan \left (x\right )} \]

[In]

integrate((a*cot(x)+b*csc(x))^2,x, algorithm="maxima")

[Out]

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

Giac [A] (verification not implemented)

none

Time = 0.28 (sec) , antiderivative size = 52, normalized size of antiderivative = 1.79 \[ \int (a \cot (x)+b \csc (x))^2 \, dx=-a^{2} x + \frac {1}{2} \, a^{2} \tan \left (\frac {1}{2} \, x\right ) - a b \tan \left (\frac {1}{2} \, x\right ) + \frac {1}{2} \, b^{2} \tan \left (\frac {1}{2} \, x\right ) - \frac {a^{2} + 2 \, a b + b^{2}}{2 \, \tan \left (\frac {1}{2} \, x\right )} \]

[In]

integrate((a*cot(x)+b*csc(x))^2,x, algorithm="giac")

[Out]

-a^2*x + 1/2*a^2*tan(1/2*x) - a*b*tan(1/2*x) + 1/2*b^2*tan(1/2*x) - 1/2*(a^2 + 2*a*b + b^2)/tan(1/2*x)

Mupad [B] (verification not implemented)

Time = 30.31 (sec) , antiderivative size = 30, normalized size of antiderivative = 1.03 \[ \int (a \cot (x)+b \csc (x))^2 \, dx=-\frac {\cos \left (x\right )\,a^2+2\,a\,b+\cos \left (x\right )\,b^2}{\sin \left (x\right )}-a^2\,x \]

[In]

int((b/sin(x) + a*cot(x))^2,x)

[Out]

- (2*a*b + a^2*cos(x) + b^2*cos(x))/sin(x) - a^2*x