Theorem: Primitive of Reciprocal of p squared minus square of q by Cosine of a x

:$\ds \int \frac {\rd x} {p^2 - q^2 \cos^2 a x} = \begin {cases}
\dfrac 1 {a p \sqrt {p^2 - q^2} } \arctan \dfrac {p \tan a x} {\sqrt {p^2 - q^2} } & : p^2 > q^2 \\
\dfrac 1 {2 a p \sqrt {q^2 - p^2} } \ln \size {\dfrac {p \tan a x - \sqrt {q^2 - p^2} } {p \tan a x + \sqrt {q^2 - p^2} } } & : p^2 < q^2
\end {cases}$

Proof:
{{begin-eqn}}
{{eqn | l = \int \frac {\d x} {p^2 - q^2 \cos^2 a x}
      | r = \int \frac {\csc^2 a x \rd x} {p^2 \csc^2 a x - q^2 \cot^2 a x}
      | c = multiplying numerator and denominator by $\csc^2 a x$
}}
{{eqn | r = \int \frac {\csc^2 a x \rd x} {p^2 \paren {1 + \cot^2 a x} - q^2 \cot^2 a x}
      | c = Difference of Squares of Cosecant and Cotangent
}}
{{eqn | r = \int \frac {\csc^2 a x \rd x} {p^2 + \paren {p^2 - q^2} \cot^2 a x}
      | c = simplifying
}}
{{end-eqn}}
Let:
{{begin-eqn}}
{{eqn | l = t
      | r = \cot a x
      | c = 
}}
{{eqn | ll= \leadsto
      | l = \d t
      | r = -a \csc^2 a x \rd x
      | c = Derivative of Cotangent Function
}}
{{eqn | ll= \leadsto
      | l = \int \frac {\d x} {p^2 - q^2 \cos^2 a x}
      | r = \frac 1 a \int \frac {-\d t} {p^2 + \paren {p^2 - q^2} t^2}
      | c = Integration by Substitution: substituting $t = \cot a x$
}}
{{eqn | n = 1
      | r = \frac {-1} {a \paren {p^2 - q^2} } \int \frac {\rd t} {t^2 + \tfrac {p^2} {p^2 - q^2} }
      | c = 
}}
{{end-eqn}}
There are two cases to address.
First, suppose $p^2 > q^2$.
Then we have that $p^2 - q^2 > 0$, and so:
{{begin-eqn}}
{{eqn | l = \int \frac {\d x} {p^2 - q^2 \cos^2 a x}
      | r = \frac {-1} {a \paren {p^2 - q^2} } \int \frac {\rd t} {t^2 + \paren {\tfrac p {\sqrt {p^2 - q^2} } }^2}
      | c = from $(1)$
}}
{{eqn | r = \frac {-1} {a \paren {p^2 - q^2} } \frac {\sqrt {p^2 - q^2} } p \map \arctan {\frac {\sqrt {p^2 - q^2} } p t} + C
      | c = Primitive of $\dfrac 1 {x^2 + a^2}$
}}
{{eqn | r = \frac {-1} {a p \sqrt {p^2 - q^2} } \map \arctan {\frac {\sqrt {p^2 - q^2} } p t} + C
      | c = 
}}
{{eqn | r = \frac {-1} {a p \sqrt {p^2 - q^2} } \map \arctan {\frac {\sqrt {p^2 - q^2} } p \cot a x} + C
      | c = substituting $t = \cot a x$
}}
{{eqn | r = \frac {-1} {a p \sqrt {p^2 - q^2} } \map \arctan {\frac {\sqrt {p^2 - q^2} } {p \tan a x} } + C
      | c = {{Defof|Real Cotangent Function}}
}}
{{eqn | r = \frac 1 {a p \sqrt {p^2 - q^2} } \map \arccot {\frac {p \tan a x} {\sqrt {p^2 - q^2} } } + C
      | c = Arctangent of Reciprocal equals Arccotangent
}}
{{eqn | r = \frac 1 {a p \sqrt {p^2 - q^2} } \paren {\map \arctan {\frac {p \tan a x} {\sqrt {p^2 - q^2} } } - \dfrac \pi 2} + C
      | c = Sum of Arctangent and Arccotangent
}}
{{eqn | r = \frac 1 {a p \sqrt {p^2 - q^2} } \map \arctan {\frac {p \tan a x} {\sqrt {p^2 - q^2} } } + C
      | c = subsuming $\dfrac \pi 2$ into constant
}}
{{end-eqn}}
Now suppose $p^2 < q^2$.
Then we have that $p^2 - q^2 < 0$, and so:
{{begin-eqn}}
{{eqn | l = \int \frac {\d x} {p^2 - q^2 \cos^2 a x}
      | r = \frac {-1} {a \paren {p^2 - q^2} } \int \frac {\rd t} {t^2 + \tfrac {p^2} {p^2 - q^2} }
      | c = from $(1)$
}}
{{eqn | r = \frac {-1} {a \paren {p^2 - q^2} } \int \frac {\rd t} {t^2 - \tfrac {p^2} {q^2 - p^2} }
      | c = 
}}
{{eqn | r = \frac {-1} {a \paren {p^2 - q^2} } \int \frac {\rd t} {t^2 - \paren {\tfrac p {\sqrt {q^2 - p^2} } }^2}
      | c = 
}}
{{eqn | r = \frac 1 {a \paren {q^2 - p^2} } \frac {\sqrt {q^2 - p^2} } {2 p} \ln \size {\frac {t - \tfrac p {\sqrt {q^2 - p^2} } } {t + \tfrac p {\sqrt {q^2 - p^2} } } } + C
      | c = Primitive of $\dfrac 1 {x^2 - a^2}$
}}
{{eqn | r = \frac 1 {2 a p \sqrt {q^2 - p^2} } \ln \size {\frac {\cot a x - \tfrac p {\sqrt {q^2 - p^2} } } {\cot a x + \tfrac p {\sqrt {q^2 - p^2} } } } + C
      | c = substituting $t = \cot a x$
}}
{{eqn | r = \frac 1 {2 a p \sqrt {q^2 - p^2} } \ln \size {\frac {\tfrac 1 {\tan a x} - \tfrac p {\sqrt {q^2 - p^2} } } {\tfrac 1 {\tan a x} + \tfrac p {\sqrt {q^2 - p^2} } } } + C
      | c = {{Defof|Real Cotangent Function}}
}}
{{eqn | r = \frac 1 {2 a p \sqrt {q^2 - p^2} } \ln \size {\frac {\sqrt {q^2 - p^2} - p \tan a x} {\sqrt {q^2 - p^2} + p \tan a x} } + C
      | c = multiplying top and bottom of argument of $\ln$ by $\sqrt {q^2 - p^2} \tan a x$
}}
{{eqn | r = \frac 1 {2 a p \sqrt {q^2 - p^2} } \ln \size {\frac {p \tan a x - \sqrt {q^2 - p^2} } {p \tan a x + \sqrt {q^2 - p^2} } } + C
      | c = as $\size {a - b} = \size {b - a}$
}}
{{end-eqn}}
{{qed}}