Rules for integrands of the form (((a+b Tan[c+d x]))^n)

1.  ∫(((b Tan[c+d x]))^n)dx

1:  ∫(((b Tan[c+d x]))^n)dx  when  n>1

Reference: G&R 2.510.1, CRC 423, A&S 4.3.129

Reference: G&R 2.510.4, CRC 427, A&S 4.3.130

Derivation: Algebraic expansion

Basis: (((b Tan[z]))^n)==b b ((Sec[z])^2)(((b Tan[z]))^(n-2))-(b^2)(((b Tan[z]))^(n-2))

Rule: If  n>1, then

∫(((b Tan[c+d x]))^n)dx  ⟶  ((b (((b Tan[c+d x]))^(n-1)))/(d (n-1)))-(b^2)∫(((b Tan[c+d x]))^(n-2))dx

Program code:

Int[(b_.*tan[c_.+d_.*x_])^n_,x_Symbol] :=
  b*(b*Tan[c+d*x])^(n-1)/(d*(n-1)) - 
  b^2*Int[(b*Tan[c+d*x])^(n-2),x] /;
FreeQ[{b,c,d},x] && GtQ[n,1]

2:  ∫(((b Tan[c+d x]))^n)dx  when  n<-1

Reference: G&R 2.510.4, CRC 427'

Reference: G&R 2.510.1, CRC 423'

Derivation: Algebraic expansion

Basis: (((b Tan[z]))^n)==((Sec[z])^2)(((b Tan[z]))^n)-(1/(b^2))(((b Tan[z]))^(n+2))

Rule: If  n<-1, then

∫(((b Tan[c+d x]))^n)dx  ⟶  ((((b Tan[c+d x]))^(n+1))/(b d(n+1)))-(1/(b^2))∫(((b Tan[c+d x]))^(n+2))dx

Program code:

Int[(b_.*tan[c_.+d_.*x_])^n_,x_Symbol] :=
  (b*Tan[c+d*x])^(n+1)/(b*d*(n+1)) - 
  1/b^2*Int[(b*Tan[c+d*x])^(n+2),x] /;
FreeQ[{b,c,d},x] && LtQ[n,-1]

3:  ∫Tan[c+d x]dx

Reference: G&R 2.526.17, CRC 292, A&S 4.3.115

Reference: G&R 2.526.33, CRC 293, A&S 4.3.118

Derivation: Integration by substitution

Basis: Tan[c+d x]==-(1/(d Cos[c+d x]))(∂_x)Cos[c+d x]

Rule:

∫Tan[c+d x]dx  ⟶  -((Log[Cos[c+d x]])/d)

Program code:

Int[tan[c_.+d_.*x_],x_Symbol] :=
  -Log[RemoveContent[Cos[c+d*x],x]]/d /;
FreeQ[{c,d},x]

x:  ∫(1/(Tan[c+d x]))dx

Note: This rule not necessary since Mathematica automatically simplifies (1/(Tan[z])) to Cot[z].

Rule:

∫(1/(Tan[c+d x]))dx  ⟶  ∫Cot[c+d x]dx  ⟶  ((Log[Sin[c+d x]])/d)

Program code:

(* Int[1/tan[c_.+d_.*x_],x_Symbol] :=
  Log[RemoveContent[Sin[c+d*x],x]]/d /;
FreeQ[{c,d},x] *)

4:  ∫(((b Tan[c+d x]))^n)dx  when  n∉ℤ

Derivation: Integration by substitution

Basis: (((b Tan[c+d x]))^n)==(b/d)Subst[((x^n)/((b^2)+(x^2))),x,b Tan[c+d x]] (∂_x)(b Tan[c+d x])

Rule: If  n∉ℤ, then

∫(((b Tan[c+d x]))^n)dx  ⟶  (b/d)Subst[∫((x^n)/((b^2)+(x^2)))dx,x,b Tan[c+d x]]

Program code:

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

2.  ∫(((a+b Tan[c+d x]))^n)dx  when  n∈(SuperPlus[ℤ])

1:  ∫(((a+b Tan[c+d x]))^2)dx

Derivation: Algebraic expansion

Basis: (((a+b Tan[c+d x]))^2)==(a^2)-(b^2)+(b^2) ((Sec[c+d x])^2)+2 a b Tan[c+d x]

Rule:

∫(((a+b Tan[c+d x]))^2)dx  ⟶  ((a^2)-(b^2))x+(((b^2) Tan[c+d x])/d)+2a b∫Tan[c+d x]dx

Program code:

Int[(a_+b_.*tan[c_.+d_.*x_])^2,x_Symbol] :=
  (a^2-b^2)*x + b^2*Tan[c+d*x]/d + 2*a*b*Int[Tan[c+d*x],x] /;
FreeQ[{a,b,c,d},x]

x:  ∫(((a+b Tan[c+d x]))^n)dx  when  n∈(SuperPlus[ℤ])

Derivation: Algebraic expansion

Note: If common powers of tangents are collected, this results in a compact antiderivative; but requires numerous steps because of fanout.

Rule: If  n∈(SuperPlus[ℤ]), then

∫(((a+b Tan[c+d x]))^n)dx  ⟶  ∫ExpandIntegrand[(((a+b Tan[c+d x]))^n),x]dx

Program code:

(* Int[(a_+b_.*tan[c_.+d_.*x_])^n_,x_Symbol] :=
  Int[ExpandIntegrand[(a+b*Tan[c+d*x])^n,x],x] /;
FreeQ[{a,b,c,d},x] && IGtQ[n,0] *)

3.  ∫(((a+b Tan[c+d x]))^n)dx  when  (a^2)+(b^2)==0

1:  ∫(((a+b Tan[c+d x]))^n)dx  when  (a^2)+(b^2)==0 ∧ n>1

Derivation: Symmetric tangent recurrence 1b with A->0,B->1,m->-1

Rule: If  (a^2)+(b^2)==0 ∧ n>1, then

∫(((a+b Tan[c+d x]))^n)dx  ⟶  ((b (((a+b Tan[c+d x]))^(n-1)))/(d (n-1)))+2 a∫(((a+b Tan[c+d x]))^(n-1))dx

Program code:

Int[(a_+b_.*tan[c_.+d_.*x_])^n_,x_Symbol] :=
  b*(a+b*Tan[c+d*x])^(n-1)/(d*(n-1)) + 
  2*a*Int[(a+b*Tan[c+d*x])^(n-1),x] /;
FreeQ[{a,b,c,d},x] && EqQ[a^2+b^2,0] && GtQ[n,1]

2:  ∫(((a+b Tan[c+d x]))^n)dx  when  (a^2)+(b^2)==0 ∧ n<0

Derivation: Symmetric tangent recurrence 2a with A->1,B->0,m->0

Rule: If  (a^2)+(b^2)==0 ∧ n<0, then

∫(((a+b Tan[c+d x]))^n)dx  ⟶  ((a (((a+b Tan[c+d x]))^n))/(2 b d n))+(1/(2 a))∫(((a+b Tan[c+d x]))^(n+1))dx

Program code:

Int[(a_+b_.*tan[c_.+d_.*x_])^n_,x_Symbol] :=
  a*(a+b*Tan[c+d*x])^n/(2*b*d*n) + 
  1/(2*a)*Int[(a+b*Tan[c+d*x])^(n+1),x] /;
FreeQ[{a,b,c,d},x] && EqQ[a^2+b^2,0] && LtQ[n,0]

3:  ∫(Sqrt[a+b Tan[c+d x]])dx  when  (a^2)+(b^2)==0

Derivation: Integration by substitution

Basis: If  (a^2)+(b^2)==0, then (Sqrt[a+b Tan[c+d x]])==-((2b)/d) Subst[(1/(2 a-(x^2))),x,(Sqrt[a+b Tan[c+d x]])] (∂_x)(Sqrt[a+b Tan[c+d x]])

Rule: If  (a^2)+(b^2)==0, then

∫(Sqrt[a+b Tan[c+d x]])dx  ⟶  -((2b)/d) Subst[∫(1/(2 a-(x^2)))dx,x,(Sqrt[a+b Tan[c+d x]])]

Program code:

Int[Sqrt[a_+b_.*tan[c_.+d_.*x_]],x_Symbol] :=
  -2*b/d*Subst[Int[1/(2*a-x^2),x],x,Sqrt[a+b*Tan[c+d*x]]] /;
FreeQ[{a,b,c,d},x] && EqQ[a^2+b^2,0]

4:  ∫(((a+b Tan[c+d x]))^n)dx  when  (a^2)+(b^2)==0

Derivation: Integration by substitution

Basis: If  (a^2)+(b^2)==0, then (((a+b Tan[c+d x]))^n)==-(b/d)Subst[((((a+x))^(n-1))/(a-x)),x,b Tan[c+d x]] (∂_x)(b Tan[c+d x])

Rule: If  (a^2)+(b^2)==0, then

∫(((a+b Tan[c+d x]))^n)dx  ⟶  -(b/d) Subst[∫((((a+x))^(n-1))/(a-x))dx,x,b Tan[c+d x]]

Program code:

Int[(a_+b_.*tan[c_.+d_.*x_])^n_,x_Symbol] :=
  -b/d*Subst[Int[(a+x)^(n-1)/(a-x),x],x,b*Tan[c+d*x]] /;
FreeQ[{a,b,c,d,n},x] && EqQ[a^2+b^2,0]

4.  ∫(((a+b Tan[c+d x]))^n)dx  when  (a^2)+(b^2)≠0

1:  ∫(((a+b Tan[c+d x]))^n)dx  when  (a^2)+(b^2)≠0 ∧ n>1

Reference: G&R 2.510.1, CRC 423, A&S 4.3.129

Reference: G&R 2.510.4, CRC 427, A&S 4.3.130

Rule: If  (a^2)+(b^2)≠0 ∧ n>1, then

∫(((a+b Tan[c+d x]))^n)dx  ⟶  ((b(((a+b Tan[c+d x]))^(n-1)))/(d(n-1)))+∫((a^2)-(b^2)+2 a b Tan[c+d x])(((a+b Tan[c+d x]))^(n-2))dx

Program code:

Int[(a_+b_.*tan[c_.+d_.*x_])^n_,x_Symbol] :=
  b*(a+b*Tan[c+d*x])^(n-1)/(d*(n-1)) + 
  Int[(a^2-b^2+2*a*b*Tan[c+d*x])*(a+b*Tan[c+d*x])^(n-2),x] /;
FreeQ[{a,b,c,d},x] && NeQ[a^2+b^2,0] && GtQ[n,1]

2:  ∫(((a+b Tan[c+d x]))^n)dx  when  (a^2)+(b^2)≠0 ∧ n<-1

Reference: G&R 2.510.4, CRC 427'

Reference: G&R 2.510.1, CRC 423'

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

∫(((a+b Tan[c+d x]))^n)dx  ⟶  ((b(((a+b Tan[c+d x]))^(n+1)))/(d(n+1)((a^2)+(b^2))))+(1/((a^2)+(b^2)))∫(a-b Tan[c+d x])(((a+b Tan[c+d x]))^(n+1))dx

Program code:

Int[(a_+b_.*tan[c_.+d_.*x_])^n_,x_Symbol] :=
  b*(a+b*Tan[c+d*x])^(n+1)/(d*(n+1)*(a^2+b^2)) + 
  1/(a^2+b^2)*Int[(a-b*Tan[c+d*x])*(a+b*Tan[c+d*x])^(n+1),x] /;
FreeQ[{a,b,c,d},x] && NeQ[a^2+b^2,0] && LtQ[n,-1]

3:  ∫(1/(a+b Tan[c+d x]))dx  when  (a^2)+(b^2)≠0

Derivation: Algebraic expansion

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

Rule: If  (a^2)+(b^2)≠0, then

∫(1/(a+b Tan[c+d x]))dx  ⟶  ((a x)/((a^2)+(b^2)))+(b/((a^2)+(b^2)))∫((b-a Tan[c+d x])/(a+b Tan[c+d x]))dx

Program code:

Int[1/(a_+b_.*tan[c_.+d_.*x_]),x_Symbol] :=
  a*x/(a^2+b^2) + b/(a^2+b^2)*Int[(b-a*Tan[c+d*x])/(a+b*Tan[c+d*x]),x] /;
FreeQ[{a,b,c,d},x] && NeQ[a^2+b^2,0]

4:  ∫(((a+b Tan[c+d x]))^n)dx  when  (a^2)+(b^2)≠0

Derivation: Integration by substitution

Basis: F[b Tan[c+d x]]==(b/d) Subst[((F[x])/((b^2)+(x^2))),x,b Tan[c+d x]] (∂_x)(b Tan[c+d x])

Rule: If  (a^2)+(b^2)≠0, then

∫(((a+b Tan[c+d x]))^n)dx  ⟶  (b/d) Subst[∫((((a+x))^n)/((b^2)+(x^2)))dx,x,b Tan[c+d x]]

Program code:

Int[(a_+b_.*tan[c_.+d_.*x_])^n_,x_Symbol] :=
  b/d*Subst[Int[(a+x)^n/(b^2+x^2),x],x,b*Tan[c+d*x]] /;
FreeQ[{a,b,c,d,n},x] && NeQ[a^2+b^2,0]