\(\int (d \cot (e+f x))^n (a+b \tan (e+f x))^2 \, dx\) [881]

Optimal result
Mathematica [A] (verified)
Rubi [A] (verified)
Maple [F]
Fricas [F]
Sympy [F]
Maxima [F]
Giac [F]
Mupad [F(-1)]
Reduce [F]

Optimal result

Integrand size = 23, antiderivative size = 132 \[ \int (d \cot (e+f x))^n (a+b \tan (e+f x))^2 \, dx=\frac {a^2 d (d \cot (e+f x))^{-1+n}}{f (1-n)}-\frac {\left (a^2-b^2\right ) d (d \cot (e+f x))^{-1+n} \operatorname {Hypergeometric2F1}\left (1,\frac {1}{2} (-1+n),\frac {1+n}{2},-\cot ^2(e+f x)\right )}{f (1-n)}-\frac {2 a b (d \cot (e+f x))^n \operatorname {Hypergeometric2F1}\left (1,\frac {n}{2},\frac {2+n}{2},-\cot ^2(e+f x)\right )}{f n} \] Output:

a^2*d*(d*cot(f*x+e))^(-1+n)/f/(1-n)-(a^2-b^2)*d*(d*cot(f*x+e))^(-1+n)*hype 
rgeom([1, -1/2+1/2*n],[1/2+1/2*n],-cot(f*x+e)^2)/f/(1-n)-2*a*b*(d*cot(f*x+ 
e))^n*hypergeom([1, 1/2*n],[1+1/2*n],-cot(f*x+e)^2)/f/n
 

Mathematica [A] (verified)

Time = 0.35 (sec) , antiderivative size = 107, normalized size of antiderivative = 0.81 \[ \int (d \cot (e+f x))^n (a+b \tan (e+f x))^2 \, dx=-\frac {d (d \cot (e+f x))^{-1+n} \left (-\left (\left (a^2-b^2\right ) n \operatorname {Hypergeometric2F1}\left (1,\frac {1}{2} (-1+n),\frac {1+n}{2},-\cot ^2(e+f x)\right )\right )+a \left (a n+2 b (-1+n) \cot (e+f x) \operatorname {Hypergeometric2F1}\left (1,\frac {n}{2},\frac {2+n}{2},-\cot ^2(e+f x)\right )\right )\right )}{f (-1+n) n} \] Input:

Integrate[(d*Cot[e + f*x])^n*(a + b*Tan[e + f*x])^2,x]
 

Output:

-((d*(d*Cot[e + f*x])^(-1 + n)*(-((a^2 - b^2)*n*Hypergeometric2F1[1, (-1 + 
 n)/2, (1 + n)/2, -Cot[e + f*x]^2]) + a*(a*n + 2*b*(-1 + n)*Cot[e + f*x]*H 
ypergeometric2F1[1, n/2, (2 + n)/2, -Cot[e + f*x]^2])))/(f*(-1 + n)*n))
 

Rubi [A] (verified)

Time = 0.63 (sec) , antiderivative size = 143, normalized size of antiderivative = 1.08, number of steps used = 10, number of rules used = 9, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.391, Rules used = {3042, 4156, 3042, 4026, 3042, 4021, 3042, 3957, 278}

Below are the steps used by Rubi to obtain the solution. The rule number used for the transformation is given above next to the arrow. The rules definitions used are listed below.

\(\displaystyle \int (a+b \tan (e+f x))^2 (d \cot (e+f x))^n \, dx\)

\(\Big \downarrow \) 3042

\(\displaystyle \int (a+b \tan (e+f x))^2 (d \cot (e+f x))^ndx\)

\(\Big \downarrow \) 4156

\(\displaystyle d^2 \int (d \cot (e+f x))^{n-2} (b+a \cot (e+f x))^2dx\)

\(\Big \downarrow \) 3042

\(\displaystyle d^2 \int \left (-d \tan \left (e+f x+\frac {\pi }{2}\right )\right )^{n-2} \left (b-a \tan \left (e+f x+\frac {\pi }{2}\right )\right )^2dx\)

\(\Big \downarrow \) 4026

\(\displaystyle d^2 \left (\int (d \cot (e+f x))^{n-2} \left (-a^2+2 b \cot (e+f x) a+b^2\right )dx+\frac {a^2 (d \cot (e+f x))^{n-1}}{d f (1-n)}\right )\)

\(\Big \downarrow \) 3042

\(\displaystyle d^2 \left (\int \left (-d \tan \left (e+f x+\frac {\pi }{2}\right )\right )^{n-2} \left (-a^2-2 b \tan \left (e+f x+\frac {\pi }{2}\right ) a+b^2\right )dx+\frac {a^2 (d \cot (e+f x))^{n-1}}{d f (1-n)}\right )\)

\(\Big \downarrow \) 4021

\(\displaystyle d^2 \left (-\left (a^2-b^2\right ) \int (d \cot (e+f x))^{n-2}dx+\frac {2 a b \int (d \cot (e+f x))^{n-1}dx}{d}+\frac {a^2 (d \cot (e+f x))^{n-1}}{d f (1-n)}\right )\)

\(\Big \downarrow \) 3042

\(\displaystyle d^2 \left (-\left (a^2-b^2\right ) \int \left (-d \tan \left (e+f x+\frac {\pi }{2}\right )\right )^{n-2}dx+\frac {2 a b \int \left (-d \tan \left (e+f x+\frac {\pi }{2}\right )\right )^{n-1}dx}{d}+\frac {a^2 (d \cot (e+f x))^{n-1}}{d f (1-n)}\right )\)

\(\Big \downarrow \) 3957

\(\displaystyle d^2 \left (\frac {d \left (a^2-b^2\right ) \int \frac {(d \cot (e+f x))^{n-2}}{\cot ^2(e+f x) d^2+d^2}d(d \cot (e+f x))}{f}-\frac {2 a b \int \frac {(d \cot (e+f x))^{n-1}}{\cot ^2(e+f x) d^2+d^2}d(d \cot (e+f x))}{f}+\frac {a^2 (d \cot (e+f x))^{n-1}}{d f (1-n)}\right )\)

\(\Big \downarrow \) 278

\(\displaystyle d^2 \left (-\frac {\left (a^2-b^2\right ) (d \cot (e+f x))^{n-1} \operatorname {Hypergeometric2F1}\left (1,\frac {n-1}{2},\frac {n+1}{2},-\cot ^2(e+f x)\right )}{d f (1-n)}+\frac {a^2 (d \cot (e+f x))^{n-1}}{d f (1-n)}-\frac {2 a b (d \cot (e+f x))^n \operatorname {Hypergeometric2F1}\left (1,\frac {n}{2},\frac {n+2}{2},-\cot ^2(e+f x)\right )}{d^2 f n}\right )\)

Input:

Int[(d*Cot[e + f*x])^n*(a + b*Tan[e + f*x])^2,x]
 

Output:

d^2*((a^2*(d*Cot[e + f*x])^(-1 + n))/(d*f*(1 - n)) - ((a^2 - b^2)*(d*Cot[e 
 + f*x])^(-1 + n)*Hypergeometric2F1[1, (-1 + n)/2, (1 + n)/2, -Cot[e + f*x 
]^2])/(d*f*(1 - n)) - (2*a*b*(d*Cot[e + f*x])^n*Hypergeometric2F1[1, n/2, 
(2 + n)/2, -Cot[e + f*x]^2])/(d^2*f*n))
 

Defintions of rubi rules used

rule 278
Int[((c_.)*(x_))^(m_.)*((a_) + (b_.)*(x_)^2)^(p_), x_Symbol] :> Simp[a^p*(( 
c*x)^(m + 1)/(c*(m + 1)))*Hypergeometric2F1[-p, (m + 1)/2, (m + 1)/2 + 1, ( 
-b)*(x^2/a)], x] /; FreeQ[{a, b, c, m, p}, x] &&  !IGtQ[p, 0] && (ILtQ[p, 0 
] || GtQ[a, 0])
 

rule 3042
Int[u_, x_Symbol] :> Int[DeactivateTrig[u, x], x] /; FunctionOfTrigOfLinear 
Q[u, x]
 

rule 3957
Int[((b_.)*tan[(c_.) + (d_.)*(x_)])^(n_), x_Symbol] :> Simp[b/d   Subst[Int 
[x^n/(b^2 + x^2), x], x, b*Tan[c + d*x]], x] /; FreeQ[{b, c, d, n}, x] && 
!IntegerQ[n]
 

rule 4021
Int[((b_.)*tan[(e_.) + (f_.)*(x_)])^(m_)*((c_) + (d_.)*tan[(e_.) + (f_.)*(x 
_)]), x_Symbol] :> Simp[c   Int[(b*Tan[e + f*x])^m, x], x] + Simp[d/b   Int 
[(b*Tan[e + f*x])^(m + 1), x], x] /; FreeQ[{b, c, d, e, f, m}, x] && NeQ[c^ 
2 + d^2, 0] &&  !IntegerQ[2*m]
 

rule 4026
Int[((a_.) + (b_.)*tan[(e_.) + (f_.)*(x_)])^(m_)*((c_.) + (d_.)*tan[(e_.) + 
 (f_.)*(x_)])^2, x_Symbol] :> Simp[d^2*((a + b*Tan[e + f*x])^(m + 1)/(b*f*( 
m + 1))), x] + Int[(a + b*Tan[e + f*x])^m*Simp[c^2 - d^2 + 2*c*d*Tan[e + f* 
x], x], x] /; FreeQ[{a, b, c, d, e, f, m}, x] && NeQ[b*c - a*d, 0] &&  !LeQ 
[m, -1] &&  !(EqQ[m, 2] && EqQ[a, 0])
 

rule 4156
Int[(cot[(e_.) + (f_.)*(x_)]*(d_.))^(m_)*((a_) + (b_.)*tan[(e_.) + (f_.)*(x 
_)]^(n_.))^(p_.), x_Symbol] :> Simp[d^(n*p)   Int[(d*Cot[e + f*x])^(m - n*p 
)*(b + a*Cot[e + f*x]^n)^p, x], x] /; FreeQ[{a, b, d, e, f, m, n, p}, x] && 
  !IntegerQ[m] && IntegersQ[n, p]
 
Maple [F]

\[\int \left (d \cot \left (f x +e \right )\right )^{n} \left (a +b \tan \left (f x +e \right )\right )^{2}d x\]

Input:

int((d*cot(f*x+e))^n*(a+b*tan(f*x+e))^2,x)
 

Output:

int((d*cot(f*x+e))^n*(a+b*tan(f*x+e))^2,x)
 

Fricas [F]

\[ \int (d \cot (e+f x))^n (a+b \tan (e+f x))^2 \, dx=\int { {\left (b \tan \left (f x + e\right ) + a\right )}^{2} \left (d \cot \left (f x + e\right )\right )^{n} \,d x } \] Input:

integrate((d*cot(f*x+e))^n*(a+b*tan(f*x+e))^2,x, algorithm="fricas")
 

Output:

integral((b^2*tan(f*x + e)^2 + 2*a*b*tan(f*x + e) + a^2)*(d*cot(f*x + e))^ 
n, x)
 

Sympy [F]

\[ \int (d \cot (e+f x))^n (a+b \tan (e+f x))^2 \, dx=\int \left (d \cot {\left (e + f x \right )}\right )^{n} \left (a + b \tan {\left (e + f x \right )}\right )^{2}\, dx \] Input:

integrate((d*cot(f*x+e))**n*(a+b*tan(f*x+e))**2,x)
 

Output:

Integral((d*cot(e + f*x))**n*(a + b*tan(e + f*x))**2, x)
 

Maxima [F]

\[ \int (d \cot (e+f x))^n (a+b \tan (e+f x))^2 \, dx=\int { {\left (b \tan \left (f x + e\right ) + a\right )}^{2} \left (d \cot \left (f x + e\right )\right )^{n} \,d x } \] Input:

integrate((d*cot(f*x+e))^n*(a+b*tan(f*x+e))^2,x, algorithm="maxima")
 

Output:

integrate((b*tan(f*x + e) + a)^2*(d*cot(f*x + e))^n, x)
 

Giac [F]

\[ \int (d \cot (e+f x))^n (a+b \tan (e+f x))^2 \, dx=\int { {\left (b \tan \left (f x + e\right ) + a\right )}^{2} \left (d \cot \left (f x + e\right )\right )^{n} \,d x } \] Input:

integrate((d*cot(f*x+e))^n*(a+b*tan(f*x+e))^2,x, algorithm="giac")
 

Output:

integrate((b*tan(f*x + e) + a)^2*(d*cot(f*x + e))^n, x)
 

Mupad [F(-1)]

Timed out. \[ \int (d \cot (e+f x))^n (a+b \tan (e+f x))^2 \, dx=\int {\left (d\,\mathrm {cot}\left (e+f\,x\right )\right )}^n\,{\left (a+b\,\mathrm {tan}\left (e+f\,x\right )\right )}^2 \,d x \] Input:

int((d*cot(e + f*x))^n*(a + b*tan(e + f*x))^2,x)
 

Output:

int((d*cot(e + f*x))^n*(a + b*tan(e + f*x))^2, x)
 

Reduce [F]

\[ \int (d \cot (e+f x))^n (a+b \tan (e+f x))^2 \, dx=d^{n} \left (\left (\int \cot \left (f x +e \right )^{n}d x \right ) a^{2}+\left (\int \cot \left (f x +e \right )^{n} \tan \left (f x +e \right )^{2}d x \right ) b^{2}+2 \left (\int \cot \left (f x +e \right )^{n} \tan \left (f x +e \right )d x \right ) a b \right ) \] Input:

int((d*cot(f*x+e))^n*(a+b*tan(f*x+e))^2,x)
                                                                                    
                                                                                    
 

Output:

d**n*(int(cot(e + f*x)**n,x)*a**2 + int(cot(e + f*x)**n*tan(e + f*x)**2,x) 
*b**2 + 2*int(cot(e + f*x)**n*tan(e + f*x),x)*a*b)