<s>[INST] Indefinite integral $\displaystyle \int \frac 1 {p \sin ax + q \cos ax + \sqrt {p^2 + q^2} }\mathrm{d}x$ Working on $\displaystyle \int \frac 1 {p \sin ax + q \cos ax + \sqrt {p^2 + q^2} }\mathrm{d}x$.
According to Spiegel's "Mathematical Handbook of Formulas and Tables" (Schaum, 1968) item $14.422$ it should work out as:
$$\frac {-1} {a \sqrt {p^2 + q^2} } \tan \left({\frac \pi 4 - \frac {ax + \arctan (q/p)} 2}\right)$$
First thing I do is a Weierstrass substitution: $u = \tan \dfrac {a x} 2$ which leads (after algebra) to the expression:
$$\dfrac 2 {a (\sqrt {p^2 + q^2} - q) } \int \frac {\mathrm d u} {\left({u + \dfrac p {\sqrt {p^2 + q^2} - q} }\right)^2}$$
This is a standard integral, giving (again after algebra):
$$\frac {-2} {(\sqrt {p^2 + q^2} - q) u + p}$$
Replacing $u = \tan \dfrac {a x} 2$ gives us:
$$\frac {-2} {(\sqrt {p^2 + q^2} - q) \tan \dfrac {a x} 2 + p}$$
which is worlds away from what the book gives.
I can't reconcile the two expressions. I'm fairly sure of the exactness of the square on the bottom, because it's the result of a quadratic in $u$ with a discriminant of zero. Fiddly and messy, but ultimately tractable.
I have tried deriving the expression in the book w.r.t. $x$ but all I get is a complicated and daunting squared-secant expression which may work out in the end to what I started with, but eugh.
How on earth does one arrive at Spiegel's result?
(Sidenote: It's a special case of this integral:
$$\displaystyle \int \frac {\mathrm d x} {p \sin a x + q \cos a x + r} = \begin{cases}
\dfrac 2 {a \sqrt {r^2 - p^2 - q^2} } \arctan \left({\dfrac {p + (r - q) \tan \dfrac {a x} 2} {\sqrt {r^2 - p^2 - q^2} } }\right) + C & : p^2 + q^2 < r^2 \\
\dfrac 1 {a \sqrt {p^2 + q^2 - r^2} } \ln \left| {\dfrac {p - \sqrt {p^2 + q^2 - r^2} + (r - q) \tan \dfrac {a x} 2} {p + \sqrt {p^2 + q^2 - r^2} + (r - q) \tan \dfrac {a x} 2} }\right| + C & : p^2 + q^2 > r^2
\end{cases}$$
but where the discriminant equals zero and so cannot be used.)
 [/INST] Integrate as follows
\begin{align}
& \int \frac {dx} {p \sin ax + q \cos ax + \sqrt {p^2 + q^2} }\\
=&\frac1{\sqrt {p^2 + q^2}  } \int \frac {dx} {\cos(\tan^{-1}\frac pq -ax)+1 }\\
 =&\frac1{\sqrt {p^2 + q^2}  } \int \frac {dx} {\cos(\frac\pi2-ax -\tan^{-1}\frac qp  )+1 }\\
 =&\frac1{2\sqrt {p^2 + q^2}  } \int  \sec^2\left(\frac\pi4-\frac {ax+\tan^{-1}\frac qp}2\right)dx\\
 =&-\frac1{a\sqrt {p^2 + q^2}  }   \tan\left(\frac\pi4- \frac {ax+\tan^{-1}\frac qp}2\right)+C\\
\end{align}
</s>