# Primitive of Reciprocal of p by Sine of a x plus q by Cosine of a x plus r

## Theorem

$\displaystyle \int \frac {\d x} {p \sin a x + q \cos a x + r} = \begin{cases} \displaystyle \frac 2 {a \sqrt {r^2 - p^2 - q^2} } \map \arctan {\frac {p + \paren {r - q} \tan \dfrac {a x} 2} {\sqrt {r^2 - p^2 - q^2} } } + C & : p^2 + q^2 < r^2 \\ \displaystyle \frac 1 {a \sqrt {p^2 + q^2 - r^2} } \ln \size {\frac {p - \sqrt {p^2 + q^2 - r^2} + \paren {r - q} \tan \dfrac {a x} 2} {p + \sqrt {p^2 + q^2 - r^2} + \paren {r - q} \tan \dfrac {a x} 2} } + C & : p^2 + q^2 > r^2 \end{cases}$

## Proof 1

Let $z = a x + \arctan \dfrac q p$.

Then:

 $\displaystyle \int \frac {\mathrm d x} {p \sin a x + q \cos a x + r}$ $=$ $\displaystyle \int \frac {\mathrm d x} {r + \sqrt {p^2 + q^2} \sin \left({a x + \arctan \dfrac q p}\right)}$ Multiple of Sine plus Multiple of Cosine $\displaystyle$ $=$ $\displaystyle \frac 1 a \int \frac {\mathrm d z} {r + \sqrt {p^2 + q^2} \sin z}$ Primitive of Function of $a x + b$

Let $d = \sqrt {p^2 + q^2}$.

Then:

 $\displaystyle$  $\displaystyle \int \frac {\mathrm d x} {p \sin a x + q \cos a x + r}$ $\displaystyle$ $=$ $\displaystyle \frac 1 a \int \frac {\mathrm d z} {r + d \sin z}$ $\displaystyle$ $=$ $\displaystyle \frac 1 a \begin{cases} \displaystyle \frac 2 {\sqrt {r^2 - d^2} } \arctan \left({\frac {r \tan \dfrac z 2 + d} {\sqrt {r^2 - d^2} } }\right) + C & : d^2 - r^2 < 0 \\ \displaystyle \frac 1 {\sqrt {d^2 - r^2} } \ln \left\vert{\frac {r \tan \dfrac z 2 + d - \sqrt {r^2 - d^2} } {r \tan \dfrac z 2 + d + \sqrt {r^2 - d^2} } }\right\vert + C & : r^2 - d^2 > 0 \\ \end{cases}$ Primitive of $\dfrac 1 {p + q \sin a x}$ $\displaystyle$ $=$ $\displaystyle \begin{cases} \displaystyle \frac 2 {a \sqrt {r^2 - p^2 - q^2} } \arctan \left({\frac {r \tan \dfrac z 2 + \sqrt {p^2 + q^2} } {\sqrt {r^2 - p^2 - q^2} } }\right) + C & : r^2 > p^2 + q^2 \\ \displaystyle \frac 1 {a \sqrt {p^2 + q^2 - r^2} } \ln \left\vert{\frac {r \tan \dfrac z 2 + \sqrt {p^2 + q^2} - \sqrt {r^2 - p^2 - q^2} } {r \tan \dfrac z 2 + \sqrt {p^2 + q^2} + \sqrt {r^2 - p^2 - q^2} } }\right\vert + C & : r^2 < p^2 + q^2 \\ \end{cases}$ substituting for $d$

Then:

 $\displaystyle \tan \frac z 2$ $=$ $\displaystyle \tan \left({\frac {a x} 2 + \frac 1 2 \arctan \frac q p}\right)$ substituting for $z$ $\displaystyle$ $=$ $\displaystyle \frac {\tan \dfrac {a x} 2 + \tan \left({\frac 1 2 \arctan \frac q p}\right)} {1 - \tan \dfrac {a x} 2 \tan \left({\frac 1 2 \arctan \frac q p}\right)}$ Tangent of Sum

Now let:

 $\displaystyle y$ $=$ $\displaystyle \tan \left({\frac 1 2 \arctan \frac q p}\right)$ $\displaystyle \implies \ \$ $\displaystyle \arctan y$ $=$ $\displaystyle \frac 1 2 \arctan \frac q p$ $\displaystyle \implies \ \$ $\displaystyle 2 \arctan y$ $=$ $\displaystyle \arctan \frac q p$ $\displaystyle \implies \ \$ $\displaystyle \tan \left({2 \arctan y}\right)$ $=$ $\displaystyle \frac q p$ $\displaystyle \implies \ \$ $\displaystyle \frac {2 \tan \left({\arctan y}\right)} {1 - \tan^2 \left({\arctan y}\right)}$ $=$ $\displaystyle \frac q p$ Double Angle Formula for Tangent $\displaystyle \implies \ \$ $\displaystyle \frac {2 y} {1 - y^2}$ $=$ $\displaystyle \frac q p$ Definition of Arctangent $\displaystyle \implies \ \$ $\displaystyle q y^2 + 2 p y - q$ $=$ $\displaystyle 0$ rearranging $\displaystyle \implies \ \$ $\displaystyle y$ $=$ $\displaystyle \frac {-2 p \pm \sqrt{4 p^2 + 4 q ^2} } {2 q}$ Quadratic Formula $\displaystyle$ $=$ $\displaystyle \frac {-p \pm \sqrt{p^2 + q^2} } q$ simplifying

Hence:

 $\displaystyle \tan \frac z 2$ $=$ $\displaystyle \frac {\tan \dfrac {a x} 2 + \dfrac {-p \pm \sqrt{p^2 + q^2} } q} {1 - \tan \dfrac {a x} 2 \left({\dfrac {-p \pm \sqrt{p^2 + q^2} } q}\right)}$ Tangent of Sum $\displaystyle$ $=$ $\displaystyle \frac {q \tan \dfrac {a x} 2 - p \pm \sqrt{p^2 + q^2} } {q - \tan \dfrac {a x} 2 \left({-p \pm \sqrt{p^2 + q^2} }\right)}$

## Proof 2

Let $z = a x + \arctan \dfrac {-p} q$.

Then:

 $\displaystyle \int \frac {\d x} {p \sin a x + q \cos a x + r}$ $=$ $\displaystyle \int \frac {\d x} {r + \sqrt {p^2 + q^2} \map \cos {a x + \arctan \dfrac {-p} q} }$ Multiple of Sine plus Multiple of Cosine $\displaystyle$ $=$ $\displaystyle \frac 1 a \int \frac {\d z} {r + \sqrt {p^2 + q^2} \cos z}$ Primitive of Function of $a x + b$

Let $d = \sqrt {p^2 + q^2}$.

Then:

 $\displaystyle$  $\displaystyle \int \frac {\d x} {p \sin a x + q \cos a x + r}$ $\displaystyle$ $=$ $\displaystyle \frac 1 a \int \frac {\d z} {r + d \cos z}$ $\displaystyle$ $=$ $\displaystyle \frac 1 a \begin{cases} \displaystyle \frac 2 {\sqrt {r^2 - d^2} } \map \arctan {\sqrt {\frac {r + d} {r - d} } \tan \dfrac z 2} + C & : r^2 > d^2 \\ \displaystyle \frac 1 {\sqrt {d^2 - r^2} } \ln \size {\frac {\tan \dfrac z 2 + \sqrt {\dfrac {d - r} {d + r} } } {\tan \dfrac z 2 - \sqrt {\dfrac {d - r} {d + r} } } } + C & : r^2 < d^2 \\ \end{cases}$ Primitive of $\dfrac 1 {p + q \cos a x}$ $\displaystyle$ $=$ $\displaystyle \begin{cases} \displaystyle \frac 2 {a \sqrt {r^2 - p^2 - q^2} } \map \arctan {\sqrt {\frac {r + d} {r - d} } \tan \dfrac z 2} + C & : r^2 > p^2 + q^2 \\ \displaystyle \frac 1 {a \sqrt {p^2 + q^2 - r^2} } \ln \size {\frac {\tan \dfrac z 2 + \sqrt {\dfrac {d - r} {d + r} } } {\tan \dfrac z 2 - \sqrt {\dfrac {d - r} {d + r} } } } + C & : r^2 < p^2 + q^2 \\ \end{cases}$ partly substituting for $d$

Then:

 $\displaystyle \sqrt {\frac {r + d} {r - d} } \tan \frac z 2$ $=$ $\displaystyle \sqrt {\frac {r + \sqrt {p^2 + q^2} } {r - \sqrt {p^2 - q^2} } } \tan \frac z 2$ substituting for $d$ $\displaystyle$ $=$ $\displaystyle \sqrt {\frac {\paren {r + \sqrt {p^2 + q^2} }^2} {\paren {r - \sqrt {p^2 + q^2} } \paren {r + \sqrt {p^2 + q^2} } } } \tan \frac z 2$ multiplying top and bottom by $r + \sqrt {p^2 + q^2}$ $\displaystyle$ $=$ $\displaystyle \frac {r + \sqrt {p^2 + q^2} } {\sqrt {r^2 - p^2 - q^2} } \tan \frac z 2$ Difference of Two Squares

Then:

 $\displaystyle \tan \frac z 2$ $=$ $\displaystyle \map \tan {\frac {a x} 2 + \frac 1 2 \arctan \frac {-p} q}$ substituting for $z$ $\displaystyle$ $=$ $\displaystyle \frac {\tan \dfrac {a x} 2 + \map \tan {\frac 1 2 \arctan \frac {-p} q} } {1 - \tan \dfrac {a x} 2 \map \tan {\frac 1 2 \arctan \frac {-p} q} }$ Tangent of Sum