Rules for integrands of the form (((a+b Tan[e+f x]))^m)(A+B Tan[e+f x]+C ((Tan[e+f x])^2))

1:  ∫(((a+b Tan[e+f x]))^m)(A+A ((Tan[e+f x])^2))dx

Derivation: Integration by substitution

Basis: F[b Tan[e+f x]](A+A ((Tan[e+f x])^2))==(A/(b f))Subst[F[x],x,b Tan[e+f x]](∂_x)(b Tan[e+f x])

Rule:

∫(((a+b Tan[e+f x]))^m)(A+A ((Tan[e+f x])^2))dx  ⟶  (A/(b f)) Subst[∫(((a+x))^m)dx,x,b Tan[e+f x]]

Program code:

Int[(a_.+b_.*tan[e_.+f_.*x_])^m_.*(A_+C_.*tan[e_.+f_.*x_]^2),x_Symbol] :=
  A/(b*f)*Subst[Int[(a+x)^m,x],x,b*Tan[e+f*x]] /;
FreeQ[{a,b,e,f,A,C,m},x] && EqQ[A,C]

Int[(a_.+b_.*cot[e_.+f_.*x_])^m_.*(A_+C_.*cot[e_.+f_.*x_]^2),x_Symbol] :=
  -A/(b*f)*Subst[Int[(a+x)^m,x],x,b*Cot[e+f*x]] /;
FreeQ[{a,b,e,f,A,C,m},x] && EqQ[A,C]

2:  ∫(((a+b Tan[e+f x]))^m)(A+B Tan[e+f x]+C ((Tan[e+f x])^2))dx  when  A (b^2)-a b B+(a^2) C==0

Derivation: Algebraic simplification

Basis:  If  A (b^2)-a b B+(a^2) C==0, then A+B z+C (z^2)==(1/(b^2))(a+b z)(b B-a C+b C z)

Rule: If  A (b^2)-a b B+(a^2) C==0, then

∫(((a+b Tan[e+f x]))^m)(A+B Tan[e+f x]+C ((Tan[e+f x])^2))dx  ⟶  (1/(b^2)) ∫(((a+b Tan[e+f x]))^(m+1))(b B-a C+b C Tan[e+f x])dx

Program code:

Int[(a_.+b_.*tan[e_.+f_.*x_])^m_.*(A_.+B_.*tan[e_.+f_.*x_]+C_.*tan[e_.+f_.*x_]^2),x_Symbol] :=
  1/b^2*Int[(a+b*Tan[e+f*x])^(m+1)*Simp[b*B-a*C+b*C*Tan[e+f*x],x],x] /;
FreeQ[{a,b,e,f,A,B,C,m},x] && EqQ[A*b^2-a*b*B+a^2*C,0]

Int[(a_.+b_.*tan[e_.+f_.*x_])^m_.*(A_.+C_.*tan[e_.+f_.*x_]^2),x_Symbol] :=
  -C/b^2*Int[(a+b*Tan[e+f*x])^(m+1)*(a-b*Tan[e+f*x]),x] /;
FreeQ[{a,b,e,f,A,C,m},x] && EqQ[A*b^2+a^2*C,0]

3.  ∫(((a+b Tan[e+f x]))^m)(A+B Tan[e+f x]+C ((Tan[e+f x])^2))dx  when  A (b^2)-a b B+(a^2) C≠0

1.  ∫(((a+b Tan[e+f x]))^m)(A+B Tan[e+f x]+C ((Tan[e+f x])^2))dx  when  A (b^2)-a b B+(a^2) C≠0 ∧ m≤-1

1:  ∫(((a+b Tan[e+f x]))^m)(A+B Tan[e+f x]+C ((Tan[e+f x])^2))dx  when  A (b^2)-a b B+(a^2) C≠0 ∧ m≤-1 ∧ (a^2)+(b^2)==0

Derivation: Algebraic expansion, symmetric tangent recurrence 2b with m->0 and symmetric tangent recurrence 2a with A->0,B->1,m->1

Rule: If  A (b^2)-a b B+(a^2) C≠0 ∧ m≤-1 ∧ (a^2)+(b^2)==0, then

∫(((a+b Tan[e+f x]))^m)(A+B Tan[e+f x]+C ((Tan[e+f x])^2))dx  ⟶  
∫(((a+b Tan[e+f x]))^m)(A+B Tan[e+f x])dx+C∫(((a+b Tan[e+f x]))^m)((Tan[e+f x])^2)dx   ⟶  
-(((a A+b B-a C)Tan[e+f x](((a+b Tan[e+f x]))^m))/(2 a f m))+(1/(2(a^2) m))∫(((a+b Tan[e+f x]))^(m+1))((b B -a C)+a A (2 m+1)-(b C (m-1)+(A b-a B) (m+1)) Tan[e+f x])dx

Program code:

Int[(a_.+b_.*tan[e_.+f_.*x_])^m_.*(A_.+B_.*tan[e_.+f_.*x_]+C_.*tan[e_.+f_.*x_]^2),x_Symbol] :=
  -(a*A+b*B-a*C)*Tan[e+f*x]*(a+b*Tan[e+f*x])^m/(2*a*f*m) + 
  1/(2*a^2*m)*Int[(a+b*Tan[e+f*x])^(m+1)*Simp[(b*B-a*C)+a*A*(2*m+1)-(b*C*(m-1)+(A*b-a*B)*(m+1))*Tan[e+f*x],x],x] /;
FreeQ[{a,b,e,f,A,B,C},x] && NeQ[A*b^2-a*b*B+a^2*C,0] && LeQ[m,-1] && EqQ[a^2+b^2,0]

Int[(a_.+b_.*tan[e_.+f_.*x_])^m_.*(A_.+C_.*tan[e_.+f_.*x_]^2),x_Symbol] :=
  -(a*A-a*C)*Tan[e+f*x]*(a+b*Tan[e+f*x])^m/(2*a*f*m) + 
  1/(2*a^2*m)*Int[(a+b*Tan[e+f*x])^(m+1)*Simp[-a*C+a*A*(2*m+1)-(b*C*(m-1)+A*b*(m+1))*Tan[e+f*x],x],x] /;
FreeQ[{a,b,e,f,A,C},x] && NeQ[A*b^2+a^2*C,0] && LeQ[m,-1] && EqQ[a^2+b^2,0]

2.  ∫(((a+b Tan[e+f x]))^m)(A+B Tan[e+f x]+C ((Tan[e+f x])^2))dx  when  A (b^2)-a b B+(a^2) C≠0 ∧ m≤-1 ∧ (a^2)+(b^2)≠0

1.  ∫((A+B Tan[e+f x]+C ((Tan[e+f x])^2))/(a+b Tan[e+f x]))dx  when  A (b^2)-a b B+(a^2) C≠0 ∧ (a^2)+(b^2)≠0

1:  ∫((A+B Tan[e+f x]+C ((Tan[e+f x])^2))/(a+b Tan[e+f x]))dx  when  (a^2)+(b^2)≠0 ∧ A b-a B-b C==0

Derivation: Algebraic expansion

Basis: If  A b-a B-b C==0, then ((A+B z+C (z^2))/(a+b z))==((a A+b B-a C)/((a^2)+(b^2)))+(((A (b^2)-a b B+(a^2) C) (1+(z^2)))/(((a^2)+(b^2)) (a+b z)))

Note: If  (a^2)+(b^2)≠0 ∧ A b-a B-b C==0, then A (b^2)-a b B+(a^2) C≠0.

Rule: If  (a^2)+(b^2)≠0 ∧ A b-a B-b C==0, then

∫((A+B Tan[e+f x]+C ((Tan[e+f x])^2))/(a+b Tan[e+f x]))dx  ⟶  (((a A+b B-a C)x)/((a^2)+(b^2)))+((A (b^2)-a b B+(a^2) C)/((a^2)+(b^2)))∫((1+((Tan[e+f x])^2))/(a+b Tan[e+f x]))dx

Program code:

Int[(A_+B_.*tan[e_.+f_.*x_]+C_.*tan[e_.+f_.*x_]^2)/(a_.+b_.*tan[e_.+f_.*x_]),x_Symbol] :=
  (a*A+b*B-a*C)*x/(a^2+b^2) + 
  (A*b^2-a*b*B+a^2*C)/(a^2+b^2)*Int[(1+Tan[e+f*x]^2)/(a+b*Tan[e+f*x]),x] /;
FreeQ[{a,b,e,f,A,B,C},x] && NeQ[a^2+b^2,0] && EqQ[A*b-a*B-b*C,0]

2.  ∫((A+B Tan[e+f x]+C ((Tan[e+f x])^2))/(a+b Tan[e+f x]))dx  when  A (b^2)-a b B+(a^2) C≠0 ∧ (a^2)+(b^2)≠0 ∧ A b-a B-b C≠0

1:  ∫((A+B Tan[e+f x]+C ((Tan[e+f x])^2))/(Tan[e+f x]))dx  when  A-C≠0

Derivation: Algebraic expansion

Rule: If  A-C≠0, then

∫((A+B Tan[e+f x]+C ((Tan[e+f x])^2))/(Tan[e+f x]))dx  ⟶  B x+A∫(1/(Tan[e+f x]))dx+C∫Tan[e+f x]dx

Program code:

Int[(A_+B_.*tan[e_.+f_.*x_]+C_.*tan[e_.+f_.*x_]^2)/tan[e_.+f_.*x_],x_Symbol] :=
  B*x+A*Int[1/Tan[e+f*x],x] + C*Int[Tan[e+f*x],x] /;
FreeQ[{e,f,A,B,C},x] && NeQ[A,C]

Int[(A_+C_.*tan[e_.+f_.*x_]^2)/tan[e_.+f_.*x_],x_Symbol] :=
  A*Int[1/Tan[e+f*x],x] + C*Int[Tan[e+f*x],x] /;
FreeQ[{e,f,A,C},x] && NeQ[A,C]

2:  ∫((A+B Tan[e+f x]+C ((Tan[e+f x])^2))/(a+b Tan[e+f x]))dx  when  A (b^2)-a b B+(a^2) C≠0 ∧ (a^2)+(b^2)≠0 ∧ A b-a B-b C≠0

Derivation: Algebraic expansion

Basis: ((A+B z+C (z^2))/(a+b z))==((a A+b B-a C)/((a^2)+(b^2)))-(((A b-a B-b C) z)/((a^2)+(b^2)))+(((A (b^2)-a b B+(a^2) C) (1+(z^2)))/(((a^2)+(b^2)) (a+b z)))

Rule: If  A (b^2)-a b B+(a^2) C≠0 ∧ (a^2)+(b^2)≠0 ∧ A b-a B-b C≠0, then

∫((A+B Tan[e+f x]+C ((Tan[e+f x])^2))/(a+b Tan[e+f x]))dx  ⟶  (((a A+b B-a C)x)/((a^2)+(b^2)))-((A b-a B-b C)/((a^2)+(b^2)))∫Tan[e+f x]dx+((A (b^2)-a b B+(a^2) C)/((a^2)+(b^2)))∫((1+((Tan[e+f x])^2))/(a+b Tan[e+f x]))dx

Program code:

Int[(A_+B_.*tan[e_.+f_.*x_]+C_.*tan[e_.+f_.*x_]^2)/(a_.+b_.*tan[e_.+f_.*x_]),x_Symbol] :=
  (a*A+b*B-a*C)*x/(a^2+b^2) - 
  (A*b-a*B-b*C)/(a^2+b^2)*Int[Tan[e+f*x],x] + 
  (A*b^2-a*b*B+a^2*C)/(a^2+b^2)*Int[(1+Tan[e+f*x]^2)/(a+b*Tan[e+f*x]),x] /;
FreeQ[{a,b,e,f,A,B,C},x] && NeQ[A*b^2-a*b*B+a^2*C,0] && NeQ[a^2+b^2,0] && NeQ[A*b-a*B-b*C,0]

Int[(A_+C_.*tan[e_.+f_.*x_]^2)/(a_+b_.*tan[e_.+f_.*x_]),x_Symbol] :=
  a*(A-C)*x/(a^2+b^2) - 
  b*(A-C)/(a^2+b^2)*Int[Tan[e+f*x],x] + 
  (a^2*C+A*b^2)/(a^2+b^2)*Int[(1+Tan[e+f*x]^2)/(a+b*Tan[e+f*x]),x] /;
FreeQ[{a,b,e,f,A,C},x] && NeQ[a^2*C+A*b^2,0] && NeQ[a^2+b^2,0] && NeQ[A,C]

2:  ∫(((a+b Tan[e+f x]))^m)(A+B Tan[e+f x]+C ((Tan[e+f x])^2))dx  when  A (b^2)-a b B+(a^2) C≠0 ∧ m<-1 ∧ (a^2)+(b^2)≠0

Derivation: Nondegenerate tangent recurrence 1a with n->0,p->0

Rule: If  A (b^2)-a b B+(a^2) C≠0 ∧ n<-1 ∧ (a^2)+(b^2)≠0, then

∫(((a+b Tan[e+f x]))^m)(A+B Tan[e+f x]+C ((Tan[e+f x])^2))dx  ⟶  
(((A (b^2)-a b B+(a^2) C)(((a+b Tan[e+f x]))^(m+1)))/(b f (m+1) ((a^2)+(b^2))))+(1/((a^2)+(b^2)))∫(((a+b Tan[e+f x]))^(m+1))(b B+a (A-C)-(A b-a B-b C) Tan[e+f x])dx

Program code:

Int[(a_.+b_.*tan[e_.+f_.*x_])^m_*(A_.+B_.*tan[e_.+f_.*x_]+C_.*tan[e_.+f_.*x_]^2),x_Symbol] :=
  (A*b^2-a*b*B+a^2*C)*(a+b*Tan[e+f*x])^(m+1)/(b*f*(m+1)*(a^2+b^2)) + 
  1/(a^2+b^2)*Int[(a+b*Tan[e+f*x])^(m+1)*Simp[b*B+a*(A-C)-(A*b-a*B-b*C)*Tan[e+f*x],x],x] /;
FreeQ[{a,b,e,f,A,B,C},x] && NeQ[A*b^2-a*b*B+a^2*C,0] && LtQ[m,-1] && NeQ[a^2+b^2,0]

Int[(a_.+b_.*tan[e_.+f_.*x_])^m_*(A_.+C_.*tan[e_.+f_.*x_]^2),x_Symbol] :=
  (A*b^2+a^2*C)*(a+b*Tan[e+f*x])^(m+1)/(b*f*(m+1)*(a^2+b^2)) + 
  1/(a^2+b^2)*Int[(a+b*Tan[e+f*x])^(m+1)*Simp[a*(A-C)-(A*b-b*C)*Tan[e+f*x],x],x] /;
FreeQ[{a,b,e,f,A,C},x] && NeQ[A*b^2+a^2*C,0] && LtQ[m,-1] && NeQ[a^2+b^2,0]

2:  ∫(((a+b Tan[e+f x]))^m)(A+B Tan[e+f x]+C ((Tan[e+f x])^2))dx  when  A (b^2)-a b B+(a^2) C≠0 ∧ m≰-1

Derivation: Nondegenerate tangent recurrence 1b with m->0,p->0

Rule: If  A (b^2)-a b B+(a^2) C≠0 ∧ m≰-1, then

∫(((a+b Tan[e+f x]))^m)(A+B Tan[e+f x]+C ((Tan[e+f x])^2))dx  ⟶  ((C(((a+b Tan[e+f x]))^(m+1)))/(b f (m+1)))+∫(((a+b Tan[e+f x]))^m)(A-C+B Tan[e+f x])dx

Program code:

Int[(a_.+b_.*tan[e_.+f_.*x_])^m_.*(A_.+B_.*tan[e_.+f_.*x_]+C_.*tan[e_.+f_.*x_]^2),x_Symbol] :=
  C*(a+b*Tan[e+f*x])^(m+1)/(b*f*(m+1)) + Int[(a+b*Tan[e+f*x])^m*Simp[A-C+B*Tan[e+f*x],x],x] /;
FreeQ[{a,b,e,f,A,B,C,m},x] && NeQ[A*b^2-a*b*B+a^2*C,0] && Not[LeQ[m,-1]]

Int[(a_.+b_.*tan[e_.+f_.*x_])^m_.*(A_.+C_.*tan[e_.+f_.*x_]^2),x_Symbol] :=
  C*(a+b*Tan[e+f*x])^(m+1)/(b*f*(m+1)) + (A-C)*Int[(a+b*Tan[e+f*x])^m,x] /;
FreeQ[{a,b,e,f,A,C,m},x] && NeQ[A*b^2+a^2*C,0] && Not[LeQ[m,-1]]