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

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

Proof:
{{begin-eqn}}
{{eqn | l = \int \frac {\d x} {p^2 - q^2 \sin^2 a x}
      | r = \int \frac {\sec^2 a x \rd x} {p^2 \sec^2 a x - q^2 \tan^2 a x}
      | c = multiplying numerator and denominator by $\sec^2 a x$
}}
{{eqn | r = \int \frac {\sec^2 a x \rd x} {p^2 \paren {1 + \tan^2 a x} - q^2 \tan^2 a x}
      | c = Difference of Squares of Secant and Tangent
}}
{{eqn | r = \int \frac {\sec^2 a x \rd x} {p^2 + \paren {p^2 - q^2} \tan^2 a x}
      | c = simplifying
}}
{{end-eqn}}
Let:
{{begin-eqn}}
{{eqn | l = t
      | r = \tan a x
      | c = 
}}
{{eqn | ll= \leadsto
      | l = \d t
      | r = a \sec^2 a x \rd x
      | c = Derivative of Tangent Function
}}
{{eqn | ll= \leadsto
      | l = \int \frac {\d x} {p^2 - q^2 \sin^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 = \tan 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 = rearranging into a standard form
}}
{{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 \sin^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} \tan a x} p} + C
      | c = substituting $t = \tan a x$
}}
{{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 \sin^2 a x}
      | r = \frac 1 {a \paren {p^2 - q^2} } \int \frac {\rd t} {t^2 - \tfrac {p^2} {q^2 - p^2} }
      | c = from $(1)$
}}
{{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 {\sqrt {q^2 - p^2} t - p} {\sqrt {q^2 - p^2} t + p} } + C
      | c = 
}}
{{eqn | r = \frac 1 {2 a p \sqrt {q^2 - p^2} } \ln \size {\frac {\sqrt {q^2 - p^2} t + p} {\sqrt {q^2 - p^2} t - p} } + C
      | c = Logarithm of Reciprocal
}}
{{eqn | r = \frac 1 {2 a p \sqrt {q^2 - p^2} } \ln \size {\frac {\sqrt {q^2 - p^2} \tan a x + p} {\sqrt {q^2 - p^2} \tan a x - p} } + C
      | c = substituting $t = \tan a x$
}}
{{end-eqn}}
{{qed}}