avewright/proofwiki-math huggingface dataset:
Theorem: Primitive of Reciprocal of Sine of a x by 1 minus Cosine of a x

:$\ds \int \frac {\d x} {\sin a x \paren {1 - \cos a x} } = \frac {-1} {2 a \paren {1 - \cos a x} } + \frac 1 {2 a} \ln \size {\tan \frac {a x} 2} + C$

Proof:
Let:
{{begin-eqn}}
{{eqn | l = u
      | r = \cos a x
      | c = 
}}
{{eqn | l = \frac {\d u} {\d x}
      | r = -a \sin a x
      | c = Derivative of $\cos a x$
}}
{{end-eqn}}
Then:
{{begin-eqn}}
{{eqn | l = \int \frac {\d x} {\sin a x \paren {1 - \cos a x} }
      | r = \int \frac {\sin a x \rd x} {\sin^2 a x \paren {1 - \cos a x} }
      | c = multiplying top and bottom by $\sin a x$
}}
{{eqn | r = \int \frac {\sin a x \rd x} {\paren {1 - \cos^2 a x} \paren {1 - \cos a x} }
      | c = Sum of Squares of Sine and Cosine
}}
{{eqn | r = \frac {-1} a \int \frac {\d u} {\paren {1 - u^2} \paren {1 - u} }
      | c = Integration by Substitution
}}
{{eqn | r = \frac {-1} a \int \frac {\d u} {\paren {1 + u} \paren {1 - u}^2}
      | c = Difference of Two Squares
}}
{{eqn | r = \frac {-1} a \paren {\frac 1 2 \paren {frac 1 {1 - u} + \frac 1 2 \ln \size {\frac {1 + u} {1 - u} } } } + C
      | c = Primitive of $\dfrac 1 {\paren {a x + b}^2 \paren {p x + q} }$
}}
{{eqn | r = \frac {-1} {2 a \paren {1 - u} } - \frac 1 {4 a} \ln \size {\frac {1 + u} {1 - u} } + C
      | c = simplifying
}}
{{eqn | r = \frac {-1} {2 a \paren {1 - u} } + \frac 1 {4 a} \ln \size {\frac {1 - u} {1 + u} } + C
      | c = Logarithm of Power
}}
{{eqn | r = \frac {-1} {2 a \paren {1 - \cos a x} } + \frac 1 {4 a} \ln \size {\frac {1 - \cos a x} {1 + \cos a x} } + C
      | c = substituting for $u$
}}
{{eqn | r = \frac {-1} {2 a \paren {1 - \cos a x} } + \frac 1 {4 a} \ln \size {\frac {\frac 1 2 \sec^2 \frac {a x} 2} {\frac 1 2 \csc^2 \frac {a x} 2} } + C
      | c = Reciprocal of $1 - \cos$ and Reciprocal of $1 + \cos$
}}
{{eqn | r = \frac {-1} {2 a \paren {1 - \cos a x} } + \frac 1 {4 a} \ln \size {\frac {\sin^2 \frac {a x} 2} {\cos^2 \frac {a x} 2} } + C
      | c = Secant is Reciprocal of Cosine
}}
{{eqn | r = \frac {-1} {2 a \paren {1 - \cos a x} } + \frac 1 {4 a} \ln \size {\tan^2 \frac {a x} 2} + C
      | c = Tangent is Sine divided by Cosine
}}
{{eqn | r = \frac {-1} {2 a \paren {1 - \cos a x} } + \frac 1 {2 a} \ln \size {\tan \frac {a x} 2} + C
      | c = Logarithm of Power
}}
{{end-eqn}}
{{qed}}
Theorem: Primitive of Reciprocal of Sine of a x plus Cosine of a x

:$\ds \int \frac {\d x} {\sin a x + \cos a x} = \frac 1 {a \sqrt 2} \ln \size {\map \tan {\frac {a x} 2 + \frac \pi 8} } + C$

Proof:
{{begin-eqn}}
{{eqn | l = \int \frac {\d x} {\sin a x + \cos a x}
      | r = \int \frac {\d x} {\sqrt 2 \map \cos {a x - \dfrac \pi 4} }
      | c = Sine of x plus Cosine of x: Cosine Form
}}
{{eqn | r = \frac 1 {\sqrt 2} \int \map \sec {a x - \dfrac \pi 4} \rd x
      | c = Secant is Reciprocal of Cosine
}}
{{end-eqn}}
Let:
{{begin-eqn}}
{{eqn | l = z
      | r = a x - \dfrac \pi 4
      | c = 
}}
{{eqn | ll= \leadsto
      | l = \frac {\d z} {\d x}
      | r = a
      | c = Derivative of Identity Function <br/>and Derivatives of Function of $a x + b$
}}
{{eqn | ll= \leadsto
      | l = \frac 1 {\sqrt 2} \int \map \sec {a x - \dfrac \pi 4} \rd x
      | r = \frac 1 {a \sqrt 2} \int \sec z \rd z
      | c = Integration by Substitution
}}
{{eqn | r = \frac 1 {a \sqrt 2} \ln \size {\map \tan {\frac z 2 + \frac \pi 4} } + C
      | c = Primitive of $\sec a x$
}}
{{eqn | r = \frac 1 {a \sqrt 2} \ln \size {\map \tan {\frac 1 2 \paren {a x - \dfrac \pi 4} + \frac \pi 4} } + C
      | c = substituting for $z$
}}
{{eqn | r = \frac 1 {a \sqrt 2} \ln \size {\map \tan {\frac {a x} 2 + \frac \pi 8} } + C
      | c = simplifying
}}
{{end-eqn}}
{{qed}}
Theorem: Primitive of Reciprocal of Sine of a x plus Cosine of a x

:$\ds \int \frac {\d x} {\sin a x + \cos a x} = \frac 1 {a \sqrt 2} \ln \size {\map \tan {\frac {a x} 2 + \frac \pi 8} } + C$

Proof:
{{begin-eqn}}
{{eqn | l = \int \frac {\d x} {\sin a x + \cos a x}
      | r = \frac 1 a \int \frac {\dfrac {2 \rd u} {1 + u^2} } {\dfrac {2 u} {1 + u^2} + \dfrac {1 - u^2} {1 + u^2} }
      | c = Weierstrass Substitution: $u = \tan \dfrac {a x} 2$
}}
{{eqn | r = \frac 2 a \int \frac {\d u} {- u^2 + 2 u + 1}
      | c = simplifying
}}
{{eqn | r = \frac 2 a \paren {\frac 1 {\sqrt 8} \ln \size {\frac {-2 u + 2 - \sqrt 8} {-2 u + 2 + \sqrt 8} } } + C
      | c = Primitive of $\dfrac 1 {a x^2 + b x + c}$
}}
{{eqn | r = \frac 1 {a \sqrt 2} \ln \size {\frac {u - 1 + \sqrt 2} {u - 1 - \sqrt 2} } + C
      | c = simplifying
}}
{{eqn | r = \frac 1 {a \sqrt 2} \ln \size {\frac {\tan \dfrac {a x} 2 - \paren {1 - \sqrt 2} } {\tan \dfrac {a x} 2 - \paren {1 + \sqrt 2} } } + C
      | c = substituting for $u$
}}
{{eqn | r = \frac 1 {a \sqrt 2} \ln \size {\frac {\tan \dfrac {a x} 2 - \tan \dfrac \pi 8} {\tan \dfrac {a x} 2 - \tan \dfrac {3 \pi} 8} } + C
      | c = Tangent of $\dfrac \pi 8$ and Tangent of $\dfrac {3 \pi} 8$
}}
{{end-eqn}}
Theorem: Primitive of Reciprocal of Sine of a x minus Cosine of a x

:$\ds \int \frac {\d x} {\sin a x - \cos a x} = \frac 1 {a \sqrt 2} \ln \size {\map \tan {\frac {a x} 2 - \frac \pi 8} } + C$

Proof:
{{begin-eqn}}
{{eqn | l = \int \frac {\d x} {\sin a x - \cos a x}
      | r = \int \frac {\d x} {\sqrt 2 \map \cos {a x - \dfrac {3 \pi} 4} }
      | c = Sine of x minus Cosine of x: Cosine Form
}}
{{eqn | r = \frac 1 {\sqrt 2} \int \map \sec {a x - \dfrac {3 \pi} 4} \rd x
      | c = Secant is Reciprocal of Cosine
}}
{{end-eqn}}
Let:
{{begin-eqn}}
{{eqn | l = z
      | r = a x - \dfrac {3 \pi} 4
      | c = 
}}
{{eqn | ll= \leadsto
      | l = \frac {\d z} {\d x}
      | r = a
      | c = Derivative of Identity Function <br/>and Derivatives of Function of $a x + b$
}}
{{eqn | ll= \leadsto
      | l = \frac 1 {\sqrt 2} \int \map \sec {a x - \dfrac {3 \pi} 4} \rd x
      | r = \frac 1 {a \sqrt 2} \int \sec z \rd z
      | c = Integration by Substitution
}}
{{eqn | r = \frac 1 {a \sqrt 2} \ln \size {\map \tan {\frac z 2 + \frac \pi 4} } + C
      | c = Primitive of $\sec a x$
}}
{{eqn | r = \frac 1 {a \sqrt 2} \ln \size {\map \tan {\frac 1 2 \paren {a x - \dfrac {3 \pi} 4} + \frac \pi 4} } + C
      | c = substituting for $z$
}}
{{eqn | r = \frac 1 {a \sqrt 2} \ln \size {\map \tan {\frac {a x} 2 - \frac \pi 8} } + C
      | c = simplifying
}}
{{end-eqn}}
{{qed}}
Theorem: Primitive of Sine of a x over Sine of a x plus Cosine of a x

:$\ds \int \frac {\sin a x \rd x} {\sin a x + \cos a x} = \frac x 2 - \frac 1 {2 a} \ln \size {\sin a x + \cos a x} + C$

Proof:
First note that:
{{begin-eqn}}
{{eqn | n = 1
      | l = \map {\frac \d {\d x} } {\sin a x + \cos a x}
      | r = a \paren {\cos a x - \sin a x}
      | c = Derivative of $\sin a x$ and Derivative of $\cos a x$
}}
{{end-eqn}}
Then:
{{begin-eqn}}
{{eqn | l = \int \frac {\sin a x \rd x} {\sin a x + \cos a x}
      | r = \int \frac {\paren {\sin a x + \cos a x - \cos a x} \rd x} {\sin a x + \cos a x}
      | c = 
}}
{{eqn | r = \int \frac {\paren {\sin a x + \cos a x} \rd x} {\sin a x + \cos a x} - \int \frac {\cos a x \rd x} {\sin a x + \cos a x}
      | c = Linear Combination of Primitives
}}
{{eqn | r = \int \d x - \int \frac {\cos a x \rd x} {\sin a x + \cos a x}
      | c = simplification
}}
{{eqn | r = \int \d x - \int \frac {\paren {\cos a x - \sin a x + \sin a x} \rd x} {\sin a x + \cos a x}
      | c = 
}}
{{eqn | r = \int \d x - \int \frac {\paren {\cos a x - \sin a x} \rd x} {\sin a x + \cos a x} - \int \frac {\sin a x \rd x} {\sin a x + \cos a x}
      | c = Linear Combination of Primitives
}}
{{eqn | ll= \leadsto
      | l = 2 \int \frac {\sin a x \rd x} {\sin a x + \cos a x}
      | r = \int \d x - \int \frac {\paren {\cos a x - \sin a x} \rd x} {\sin a x + \cos a x}
      | c = rearranging
}}
{{eqn | ll= \leadsto
      | l = \int \frac {\sin a x \rd x} {\sin a x + \cos a x}
      | r = \frac 1 2 \int \d x - \frac 1 {2 a} \int \frac {a \paren {\cos a x - \sin a x} \rd x} {\sin a x + \cos a x}
      | c = Linear Combination of Primitives
}}
{{eqn | r = \frac x 2 - \frac 1 {2 a} \int \frac {a \paren {\cos a x - \sin a x} \rd x} {\sin a x + \cos a x} + C
      | c = Primitive of Constant
}}
{{Eqn-intertext|Then from $(1)$:}}
{{eqn | r = \frac x 2 - \frac 1 {2 a} \ln \size {\sin a x + \cos a x} + C
      | c = Primitive of Function under its Derivative
}}
{{end-eqn}}
{{qed}}
Theorem: Primitive of Sine of a x over Sine of a x minus Cosine of a x

:$\ds \int \frac {\sin a x \rd x} {\sin a x - \cos a x} = \frac x 2 + \frac 1 {2 a} \ln \size {\sin a x - \cos a x} + C$

Proof:
First note that:
{{begin-eqn}}
{{eqn | n = 1
      | l = \map {\frac {\d} {\d x} } {\sin a x - \cos a x}
      | r = a \paren {\cos a x + \sin a x}
      | c = Derivative of $\sin a x$ and Derivative of $\cos a x$
}}
{{end-eqn}}
Then:
{{begin-eqn}}
{{eqn | l = \int \frac {\sin a x \rd x} {\sin a x - \cos a x}
      | r = \int \frac {\paren {\sin a x - \cos a x + \cos a x} \rd x} {\sin a x - \cos a x}
      | c = 
}}
{{eqn | r = \int \frac {\paren {\sin a x - \cos a x} \rd x} {\sin a x - \cos a x} + \int \frac {\cos a x \rd x} {\sin a x - \cos a x}
      | c = Linear Combination of Primitives
}}
{{eqn | r = \int \rd x + \int \frac {\cos a x \rd x} {\sin a x - \cos a x}
      | c = simplification
}}
{{eqn | r = \int \rd x + \int \frac {\paren {\cos a x + \sin a x - \sin a x} \rd x} {\sin a x - \cos a x}
      | c = 
}}
{{eqn | r = \int \rd x + \int \frac {\paren {\cos a x + \sin a x} \rd x} {\sin a x - \cos a x} - \int \frac {\sin a x \rd x} {\sin a x - \cos a x}
      | c = Linear Combination of Primitives
}}
{{eqn | ll= \leadsto
      | l = 2 \int \frac {\sin a x \rd x} {\sin a x - \cos a x}
      | r = \int \rd x + \int \frac {\paren {\cos a x + \sin a x} \rd x} {\sin a x - \cos a x}
      | c = rearranging
}}
{{eqn | ll= \leadsto
      | l = \int \frac {\sin a x \rd x} {\sin a x + \cos a x}
      | r = \frac 1 2 \int \rd x + \frac 1 {2 a} \int \frac {a \paren {\cos a x + \sin a x} \rd x} {\sin a x - \cos a x}
      | c = Linear Combination of Primitives
}}
{{eqn | r = \frac x 2 + \frac 1 {2 a} \int \frac {a \paren {\cos a x + \sin a x} \rd x} {\sin a x - \cos a x} + C
      | c = Primitive of Constant
}}
{{Eqn-intertext|Then from $(1)$:}}
{{eqn | r = \frac x 2 + \frac 1 {2 a} \ln \size {\sin a x - \cos a x} + C
      | c = Primitive of Function under its Derivative
}}
{{end-eqn}}
{{qed}}
Theorem: Primitive of Cosine of a x over Sine of a x plus Cosine of a x

:$\ds \int \frac {\cos a x \rd x} {\sin a x + \cos a x} = \frac x 2 + \frac 1 {2 a} \ln \size {\sin a x + \cos a x} + C$

Proof:
{{begin-eqn}}
{{eqn | l = \int \frac {\cos a x \rd x} {\sin a x + \cos a x}
      | r = \int \frac {\paren {\sin a x + \cos a x - \sin a x} \rd x} {\sin a x + \cos a x}
      | c = 
}}
{{eqn | r = \int \frac {\paren {\sin a x + \cos a x} \rd x} {\sin a x + \cos a x} - \int \frac {\sin a x \rd x} {\sin a x + \cos a x}
      | c = Linear Combination of Primitives
}}
{{eqn | r = \int \rd x - \int \frac {\sin a x \rd x} {\sin a x + \cos a x}
      | c = simplification
}}
{{eqn | r = x - \int \frac {\sin a x \rd x} {\sin a x + \cos a x} + C
      | c = Primitive of Constant
}}
{{eqn | r = x - \paren {\frac x 2 - \frac 1 {2 a} \ln \size {\sin a x + \cos a x} } + C
      | c = Primitive of $\dfrac {\sin a x} {\sin a x + \cos a x}$
}}
{{eqn | r = \frac x 2 + \frac 1 {2 a} \ln \size {\sin a x + \cos a x} + C
      | c = simplifying
}}
{{end-eqn}}
{{qed}}
Theorem: Primitive of Cosine of a x over Sine of a x minus Cosine of a x

:$\ds \int \frac {\cos a x \rd x} {\sin a x - \cos a x} = \frac {-x} 2 + \frac 1 {2 a} \ln \size {\sin a x - \cos a x} + C$

Proof:
{{begin-eqn}}
{{eqn | l = \int \frac {\cos a x \rd x} {\sin a x - \cos a x}
      | r = \int \frac {\paren {\cos a x - \sin a x + \sin a x} \rd x} {\sin a x - \cos a x}
      | c = 
}}
{{eqn | r = -\int \frac {\paren {\sin a x - \cos a x} \rd x} {\sin a x - \cos a x} + \int \frac {\sin a x \rd x} {\sin a x - \cos a x}
      | c = Linear Combination of Primitives
}}
{{eqn | r = -\int \rd x + \int \frac {\sin a x \rd x} {\sin a x - \cos a x}
      | c = simplification
}}
{{eqn | r = -x + \int \frac {\sin a x \rd x} {\sin a x - \cos a x} + C
      | c = Primitive of Constant
}}
{{eqn | r = -x + \paren {\frac x 2 + \frac 1 {2 a} \ln \size {\sin a x - \cos a x} } + C
      | c = Primitive of $\dfrac {\sin a x} {\sin a x - \cos a x}$
}}
{{eqn | r = \frac {-x} 2 + \frac 1 {2 a} \ln \size {\sin a x - \cos a x} + C
      | c = simplifying
}}
{{end-eqn}}
{{qed}}
Theorem: Primitive of Sine of a x over p plus q of Cosine of a x

:$\ds \int \frac {\sin a x \rd x} {p + q \cos a x} = \frac {-1} {a q} \ln \size {p + q \cos a x} + C$

Proof:
{{begin-eqn}}
{{eqn | l = \map {\frac \d {\d x} } {p + q \cos a x}
      | r = -a q \sin a x
      | c = Derivative of $\cos a x$
}}
{{eqn | ll= \leadsto
      | l = \int \frac {\sin a x \rd x} {p + q \cos a x}
      | r = \frac {-1} {a q} \ln \size {p + q \cos a x} + C
      | c = Primitive of Function under its Derivative
}}
{{end-eqn}}
{{qed}}
Theorem: Primitive of Cosine of a x over p plus q of Sine of a x

:$\ds \int \frac {\cos a x \rd x} {p + q \sin a x} = \frac 1 {a q} \ln \size {p + q \sin a x} + C$

Proof:
{{begin-eqn}}
{{eqn | l = \map {\frac \d {\d x} } {p + q \sin a x}
      | r = a q \cos a x
      | c = Derivative of $\sin a x$
}}
{{eqn | ll= \leadsto
      | l = \int \frac {\cos a x \rd x} {p + q \sin a x}
      | r = \frac 1 {a q} \ln \size {p + q \sin a x} + C
      | c = Primitive of Function under its Derivative
}}
{{end-eqn}}
{{qed}}
Theorem: Primitive of Sine of a x over Power of p plus q of Cosine of a x

:$\ds \int \frac {\sin a x \rd x} {\paren {p + q \cos a x}^n} = \frac 1 {a q \paren {n - 1} \paren {p + q \cos a x}^{n - 1} } + C$

Proof:
{{begin-eqn}}
{{eqn | l = z
      | r = p + q \cos a x
      | c = 
}}
{{eqn | ll= \leadsto
      | l = \frac {\d z} {\d x}
      | r = -a q \sin a x
      | c = Derivative of $\cos a x$
}}
{{eqn | ll= \leadsto
      | l = \int \frac {\sin a x \rd x} {\paren {p + q \cos a x}^n}
      | r = \int \frac {\d z} {-a q z^n}
      | c = Integration by Substitution
}}
{{eqn | r = \frac {-1} {a q} \int z^{-n} \rd z
      | c = Primitive of Constant Multiple of Function
}}
{{eqn | r = \frac {-1} {a q} \frac {z^{-n + 1} } {-n + 1} + C
      | c = Primitive of Power
}}
{{eqn | r = \frac 1 {a q \paren {n - 1} z^{n - 1} } + C
      | c = simplifying
}}
{{eqn | r = \frac 1 {a q \paren {n - 1} \paren {p + q \cos a x}^{n - 1} } + C
      | c = substituting for $z$
}}
{{end-eqn}}
{{qed}}
Theorem: Primitive of Cosine of a x over Power of p plus q of Sine of a x

:$\ds \int \frac {\cos a x \rd x} {\paren {p + q \sin a x}^n} = \frac {-1} {a q \paren {n - 1} \paren {p + q \sin a x}^{n - 1} } + C$

Proof:
{{begin-eqn}}
{{eqn | l = z
      | r = p + q \sin a x
      | c = 
}}
{{eqn | ll= \leadsto
      | l = \frac {\d z} {\d x}
      | r = a q \sin a x
      | c = Derivative of $\sin a x$
}}
{{eqn | ll= \leadsto
      | l = \int \frac {\cos a x \rd x} {\paren {p + q \sin a x}^n}
      | r = \int \frac {\d z} {a q z^n}
      | c = Integration by Substitution
}}
{{eqn | r = \frac 1 {a q} \int z^{-n} \rd z
      | c = Primitive of Constant Multiple of Function
}}
{{eqn | r = \frac 1 {a q} \frac {z^{-n + 1} } {-n + 1} + C
      | c = Primitive of Power
}}
{{eqn | r = \frac {-1} {a q \paren {n - 1} z^{n - 1} } + C
      | c = simplifying
}}
{{eqn | r = \frac {-1} {a q \paren {n - 1} \paren {p + q \sin a x}^{n - 1} } + C
      | c = substituting for $z$
}}
{{end-eqn}}
{{qed}}
Theorem: Primitive of Reciprocal of p by Sine of a x plus q by Cosine of a x

:$\ds \int \frac {\d x} {p \sin a x + q \cos a x} = \frac 1 {a \sqrt {p^2 + q^2} } \ln \tan \size {\frac {a x + \arctan \dfrac q p} 2} + C$

Proof:
=== Lemma ===
{{:Primitive of Reciprocal of p by Sine of a x plus q by Cosine of a x/Lemma}}{{qed|lemma}}
{{begin-eqn}}
{{eqn | l = \int \frac {\d x} {p \sin a x + q \cos a x}
      | r = \int \frac {\d x} {\sqrt {p^2 + q^2} \map \cos {a x + \arctan \dfrac {-p} q} }
      | c = Multiple of Sine plus Multiple of Cosine
}}
{{eqn | r = \frac 1 {\sqrt {p^2 + q^2} } \int \map \sec {a x + \arctan \dfrac {-p} q} \rd x
      | c = Secant is Reciprocal of Cosine
}}
{{eqn | r = \frac 1 {a \sqrt {p^2 + q^2} } \int \sec z \rd z
      | c = Primitive of Function of $a x + b$: $z = a x + \arctan \dfrac {-p} q$
}}
{{eqn | r = \frac 1 {a \sqrt {p^2 + q^2} } \ln \tan \size {\frac z 2 + \frac \pi 4} + C
      | c = Primitive of $\sec a x$
}}
{{eqn | r = \frac 1 {a \sqrt {p^2 + q^2} } \ln \tan \size {\frac 1 2 \paren {a x + \arctan \dfrac {-p} q + \frac \pi 2} } + C
      | c = substituting for $z$
}}
{{eqn | r = \frac 1 {a \sqrt {p^2 + q^2} } \ln \tan \size {\frac {a x + \arctan \dfrac q p} 2} + C
      | c = Lemma
}}
{{end-eqn}}
{{qed}}
Theorem: Primitive of Reciprocal of p by Sine of a x plus q by 1 plus Cosine of a x

:$\ds \int \frac {\rd x} {p \sin a x + q \paren {1 + \cos a x} } = \frac 1 {a p} \ln \size {q + p \tan \frac {a x} 2} + C$

Proof:
Let $z = a x$.
Then $\d x = \dfrac {\d z} a$ and so:
$(1): \quad \ds \int \frac {\rd x} {p \sin a x + q \paren {1 + \cos a x} } = \dfrac 1 a \int \frac {\rd z} {p \sin z + q \paren {1 + \cos z} }$
Then:
{{begin-eqn}}
{{eqn | l = u
      | r = \tan \frac z 2
      | c = 
}}
{{eqn | ll= \leadsto
      | l = \int \frac {\rd z} {p \sin z + q \paren {1 + \cos z} }
      | r = \int \frac {\frac {2 \rd u} {\paren {1 + u^2} } } {p \frac {2 u} {1 + u^2} + q \paren {1 + \frac {1 - u^2} {1 + u^2} } }
      | c = Weierstrass Substitution
}}
{{eqn | r = \int \frac {2 \rd u} {2 p u + q \paren {1 + u^2 + 1 - u^2} }
      | c = multiplying top and bottom by $1 + u^2$
}}
{{eqn | r = \int \frac {\d u} {p u + q}
      | c = simplifying
}}
{{eqn | r = \frac 1 p \ln \size {p u + q} + C
      | c = Primitive of $\dfrac 1 {a x + b}$
}}
{{eqn | r = \frac 1 p \ln \size {q + p \tan \frac z 2} + C
      | c = substituting for $u$
}}
{{eqn | r = \frac 1 {a p} \ln \size {q + p \tan \frac {a x} 2} + C
      | c = from $(1)$
}}
{{end-eqn}}
{{qed}}
Theorem: Primitive of Reciprocal of p by Sine of a x plus q by Cosine of a x plus Root of p squared plus q squared

:$\ds \int \frac {\d x} {p \sin a x + q \cos a x + \sqrt {p^2 + q^2} } = \frac {-1} {a \sqrt {p^2 + q^2} } \map \tan {\frac \pi 4 - \frac {a x + \arctan \frac q p} 2} + C$

Proof:
Let $\theta = \arctan \dfrac p q$.
Then by the definitions of sine, cosine and tangent:
{{begin-eqn}}
{{eqn | n = 1
      | l = \cos \theta
      | r = \frac q {\sqrt {p^2 + q^2} }
}}
{{eqn | l = \sin \theta
      | r = \frac p {\sqrt {p^2 + q^2} }
}}
{{end-eqn}}
Now consider:
{{begin-eqn}}
{{eqn | l = \map \cos {\frac \pi 2 - a x - \theta}
      | r = \map \cos {\frac \pi 2 - a x} \cos \theta + \map \sin {\frac \pi 2 - a x} \sin \theta
      | c = Cosine of Difference
}}
{{eqn | r = \sin a x \cos \theta + \cos a x \sin \theta
      | c = Sine of Complement equals Cosine
}}
{{eqn | r = \map \sin {a x + \theta}
      | c = Sine of Sum
}}
{{end-eqn}}
Then let $\theta' = \arctan \dfrac q p$.
From Arctangent of Reciprocal equals Arccotangent:
:$\theta' = \arccot \dfrac p q$.
Hence:
{{begin-eqn}}
{{eqn | l = \map \tan {\frac \pi 2 - \theta}
      | r = \cot \theta
      | c = Tangent of Complement equals Cotangent
}}
{{eqn | r = \tan \theta'
      | c = 
}}
{{eqn | n = 2
      | ll= \leadsto
      | l = \theta
      | r = \frac \pi 2 - \theta'
      | c = 
}}
{{end-eqn}}
Thus:
{{begin-eqn}}
{{eqn | l = \int \frac {\d x} {p \sin a x + q \cos a x + \sqrt {p^2 + q^2} }
      | r = \dfrac 1 {\sqrt {p^2 + q^2} } \int \frac {\d x} {\dfrac p {\sqrt {p^2 + q^2} } \sin a x + \dfrac q {\sqrt {p^2 + q^2} } \cos a x + 1}
      | c = 
}}
{{eqn | r = \dfrac 1 {\sqrt {p^2 + q^2} } \int \frac {\d x} {\sin \theta \sin a x + \cos \theta \cos a x + 1}
      | c = from $(1)$
}}
{{eqn | r = \dfrac 1 {\sqrt {p^2 + q^2} } \int \frac {\d x} {\map \cos {\theta - a x} + 1}
      | c = Cosine of Difference
}}
{{eqn | r = \dfrac 1 {\sqrt {p^2 + q^2} } \int \frac {\d x} {\map \cos {\frac \pi 2 - a x - \theta'} + 1}
      | c = from $(2)$
}}
{{eqn | r = \dfrac 1 {\sqrt {p^2 + q^2} } \int \frac {\d x} {2 \map {\cos^2} { {\paren {\frac \pi 2 - a x - \theta'} / 2} } }
      | c = Square of Cosine
}}
{{eqn | r = \dfrac 1 {2 \sqrt {p^2 + q^2} } \int \map {\sec^2} {\frac \pi 4 - \frac {a x + \theta'} 2} \rd x
      | c = {{Defof|Real Secant Function}}
}}
{{eqn | r = \dfrac 1 {2 \sqrt {p^2 + q^2} } \dfrac {-2} a \map \tan {\frac \pi 4 - \frac {a x + \theta'} 2} + C
      | c = Primitive of $\sec^2 a x$
}}
{{eqn | r = -\dfrac {-1} {a \sqrt {p^2 + q^2} } \map \tan {\frac \pi 4 - \frac {a x + \arctan \frac q p} 2} + C
      | c = substituting for $\theta'$ and simplifying
}}
{{end-eqn}}
{{qed}}
Theorem: Primitive of Reciprocal of p by Sine of a x plus q by Cosine of a x minus Root of p squared plus q squared

:$\ds \int \frac {\d x} {p \sin a x + q \cos a x - \sqrt {p^2 + q^2} } = \frac {-1} {a \sqrt {p^2 + q^2} } \map \tan {\frac \pi 4 + \frac {a x + \arctan \frac q p} 2} + C$

Proof:
Let $\theta = \arctan \dfrac p q$.
Then by the definitions of sine, cosine and tangent:
{{begin-eqn}}
{{eqn | n = 1
      | l = \cos \theta
      | r = \frac q {\sqrt {p^2 + q^2} }
}}
{{eqn | l = \sin \theta
      | r = \frac p {\sqrt {p^2 + q^2} }
}}
{{end-eqn}}
Now consider:
{{begin-eqn}}
{{eqn | l = \map \cos {\frac \pi 2 - a x - \theta}
      | r = \map \cos {\frac \pi 2 - a x} \cos \theta + \map \sin {\frac \pi 2 - a x} \sin \theta
      | c = Cosine of Difference
}}
{{eqn | r = \sin a x \cos \theta + \cos a x \sin \theta
      | c = Sine of Complement equals Cosine
}}
{{eqn | r = \map \sin {a x + \theta}
      | c = Sine of Sum
}}
{{end-eqn}}
Then let $\theta' = \arctan \dfrac q p$.
From Arctangent of Reciprocal equals Arccotangent:
:$\theta' = \arccot \dfrac p q$.
Hence:
{{begin-eqn}}
{{eqn | l = \map \tan {\frac \pi 2 - \theta}
      | r = \cot \theta
      | c = Tangent of Complement equals Cotangent
}}
{{eqn | r = \tan \theta'
      | c = 
}}
{{eqn | n = 2
      | ll= \leadsto
      | l = \theta
      | r = \frac \pi 2 - \theta'
      | c = 
}}
{{end-eqn}}
Thus:
{{begin-eqn}}
{{eqn | l = \int \frac {\d x} {p \sin a x + q \cos a x + \sqrt {p^2 + q^2} }
      | r = \dfrac 1 {\sqrt {p^2 + q^2} } \int \frac {\d x} {\dfrac p {\sqrt {p^2 + q^2} } \sin a x + \dfrac q {\sqrt {p^2 + q^2} } \cos a x - 1}
      | c = 
}}
{{eqn | r = \dfrac 1 {\sqrt {p^2 + q^2} } \int \frac {\d x} {\sin \theta \sin a x + \cos \theta \cos a x - 1}
      | c = from $(1)$
}}
{{eqn | r = \dfrac 1 {\sqrt {p^2 + q^2} } \int \frac {\d x} {\map \cos {\theta - a x} - 1}
      | c = Cosine of Difference
}}
{{eqn | r = \dfrac 1 {\sqrt {p^2 + q^2} } \int \frac {\d x} {\map \cos {\frac \pi 2 - a x - \theta'} - 1}
      | c = from $(2)$
}}
{{eqn | r = \dfrac 1 {\sqrt {p^2 + q^2} } \int \frac {\d x} {-\map \cos {\pi - \paren {\frac \pi 2 - a x - \theta'} } - 1}
      | c = Cosine of Supplementary Angle
}}
{{eqn | r = \dfrac {-1} {\sqrt {p^2 + q^2} } \int \frac {\d x} {\map \cos {\frac \pi 2 + a x + \theta'} - 1}
      | c = simplifying
}}
{{eqn | r = \dfrac {-1} {\sqrt {p^2 + q^2} } \int \frac {\d x} {2 \map {\cos^2} {\paren {\frac \pi 2 + a x + \theta'} / 2} }
      | c = Square of Cosine
}}
{{eqn | r = \dfrac {-1} {2 \sqrt {p^2 + q^2} } \int \map {\sec^2} {\frac \pi 4 + \frac {a x + \theta'} 2} \rd x
      | c = {{Defof|Real Secant Function}} and simplifying
}}
{{eqn | r = \dfrac {-1} {2 \sqrt {p^2 + q^2} } \dfrac 2 a \map \tan {\frac \pi 4 + \frac {a x + \theta'} 2} + C
      | c = Primitive of $\sec^2 a x$
}}
{{eqn | r = \dfrac {-1} {a \sqrt {p^2 + q^2} } \map \tan {\frac \pi 4 + \frac {a x + \arctan \frac q p} 2} + C
      | c = substituting for $\theta'$ and simplifying
}}
{{end-eqn}}
{{qed}}