Primitive of Reciprocal of Root of a x + b by Root of p x + q/Completing the Square

Lemma for Primitive of $\frac 1 {\sqrt {\paren {a x + b} \paren {p x + q} } }$
Let $a, b, p, q \in \R$ such that $a p \ne b q$.

Then:
 * $\ds \int \frac {\d x} {\sqrt {\paren {a x + b} \paren {p x + q} } } = \begin {cases}

\ds \frac 1 {\sqrt {a p} } \int \frac {\d u} {\sqrt {u^2 - \paren {b p - a q}^2} } & : a p > 0 \\ \ds \frac 1 {\sqrt {-a p} } \int \frac {\d u} {\sqrt {\paren {b p - a q}^2 - u^2} } & : a p < 0 \end {cases}$

where:
 * $u := 2 a p x + b p + a q$

Proof
Let us make the substitution:


 * Case $1: \quad a p > 0$


 * Case $2: \quad a p < 0$