%! TEX root = NT.tex
% vim: tw=50
% 17/11/2023 10AM

\vspace{-2em}
\begin{enumerate}[(3)]
  \setcounter{enumi}{3}
  \item Induction on $n$. $n = 0$: $\contf[a_0,
    \beta] = \fcontf[a_0, \beta] = \frac{\beta a_0
    + 1}{\beta}$. In general, $\contf[a_0, \ldots,
    a_{n + 1}, \beta] = \contf[a_0, \ldots, a_n,
    \contf[a_{n + 1}, \beta]] = \contf[a_0,
    \ldots, a_n, \gamma]$, where $\gamma =
    \contf[a_{n + 1}, \beta]$. By induction, this
    is
    \[ \frac{\gamma p_n + p_{n - 1}}
    {\gamma q_n + q_{n - 1}}
    = \frac{a_{n + 1} p_n + \beta^{-1} p_n + p_{n - 1}}
    {a_{n + 1} q_n + \beta^{-1} q_n + q_{n - 1}}
    = \frac{p_{n + 1} + \beta^{-1} p_n}
    {q_{n + 1} + \beta^{-1} q_n}
    = \frac{\beta p_{n + 1} + p_n}
    {\beta q_{n + 1} + q_n} .\]

    \[ \frac{p_n}{q_n} - \frac{p_{n - 1}}{q_{n -
    1}} = \frac{(-1)^{n - 1}}{q_n q_{n - 1}}
    \implies \frac{p_n}{q_n}, \frac{p_{n -
    1}}{q_{n - 1}} \text{are distinct} \]
    Simple fact: if $x, y, x;, y' \in \RR$, $y, y'
    > 0$, $\frac{x}{y} < \frac{x'}{y'}$, then
    \[ \frac{x}{y} < \frac{x + x'}{y + y'} <
    \frac{x'}{y'} .\]
    Here: take
    \[ \frac{x}{y} = \min \left( \frac{\beta
    p_n}{\beta q_n}, \frac{p_{n - 1}}{q_{n - 1}}
    \right) \qquad
    \frac{x'}{y'} = \max \left( \frac{\beta
    p_n}{\beta q_n}, \frac{p_{n - 1}}{q_{n - 1}}
    \right)
    \fakeqedhere \]
\end{enumerate}

\begin{flashcard}[convergents-converge-to-theta]
\begin{theorem}
  % Theorem 5.4
  Let $\theta \in \RR \setminus \QQ$, $\theta =
  \contf[\acf_0, \acf_1, \acf_2, \ldots]$. Then:
  \begin{enumerate}[(1)]
    \item $\left| \theta - \frac{p_n}{q_n} \right|
      < \frac{1}{q_n q_{n + 1}}$ for all $n \ge
      0$.
    \item $\lim_{n \to \infty} \frac{p_n}{q_n} =
      \lim_{n \to \infty} \contf[a_0, \ldots, a_n]
      = \theta$.
  \end{enumerate}
\end{theorem}

\textbf{Reminder:} $\frac{p_n}{q_n}$ are called
the \glspl{convergent} of $\contf[a_0, a_1,
\ldots]$.

\begin{proof}
  \cloze{
  We know $\theta = \contf[a_1, a_2, \ldots, a_{n + 1}, \theta_{n +
  2}]$ for all $n \ge 0$. So
  \[ \theta = \frac{\theta_{n + 2} p_{n + 1} +
  p_n}{\theta_{n + 2} q_{n + 1} + q_n} \]
  lies strictly between $\frac{p_n}{q_n}$ and
  $\frac{p_{n + 1}}{q_{n + 1}}$. Therefore
  \[ \left| \theta - \frac{p_n}{q_n} \right| \le
  \left| \frac{p_n}{q_n} - \frac{p_{n + 1}}{q_{n +
  1}} \right| = \frac{}{q_n q_{n + 1}} \]
  (inequality must be strict as $\theta \notin
  \QQ$). We've observed that $0 < q_1 < q_2 <
  \cdots$, so $q_n \to \infty$ as $n \to \infty$.
  }
\end{proof}
\end{flashcard}

\begin{remark*}
  You can show that $\theta \mapsto \contf[a_0,
  a_1, \ldots]$ induces a bijection
  \[ \RR \setminus \QQ \simto \ZZ \times \NN^\NN .\]
\end{remark*}

\begin{example*}
  $\pi = \contf[3, 7, 15, 1, 292, 1, \ldots]$.
  First few \glspl{convergent}:
  \begin{align*}
    \contf[3]
    &= \calccontf[3] \\
    \contf[3, 7]
    &= \calccontf[3, 7] \\
    \contf[3, 7, 15]
    &= \calccontf[3, 7, 15] \\
    \contf[3, 7, 15, 1]
    &= \calccontf[3, 7, 15, 1]
  \end{align*}
\end{example*}
\vspace{-1em}

We now prove two theorems making precise the sense
in which the \glspl{convergent} of $\theta \in \RR
\setminus \QQ$ give a sequence of ``best
possible'' rational approximations to $\theta$.

\begin{flashcard}[good-approximation-must-be-a-convergent]
\begin{theorem}
  % Theorem 5.5
  \label{convergent_optimal_approximation}
  Let $\theta \in \RR \setminus \QQ$, $p \in \ZZ$,
  $q \in \NN$. Then:
  \begin{enumerate}[(1)]
    \item \cloze{If $q < q_{n + 1}$, then $|q\theta - p|
      \ge |q_n\theta - p_n|$.}
    \item \cloze{If $\left| \theta - \frac{p}{q} \right|
      < \left| \theta - \frac{p_n}{q_n} \right|$,
      then $q > q_n$.}
  \end{enumerate}
\end{theorem}

\begin{proof}
  \cloze{
  First prove (1) $\implies$ (2): Suppose $q \le q_n$.
  Then $q < q_{n + 1}$, so $|q\theta - p| \ge
  |q_n\theta - p_n|$. So
  \[ \left| \theta - \frac{p}{q} \right| =
  \frac{1}{q} |q\theta - p| \ge \frac{1}{q_n}
  |q_n \theta - p_n| = \left| \theta -
  \frac{p_n}{q_n} \right| .\]

  Now we prove (1): there exist integers $u, v \in
  \ZZ$ such that
  \[
  \begin{pmatrix}
    p_n & p_{n + 1} \\
    q_n & q_{n + 1}
  \end{pmatrix}
  \begin{pmatrix}
    u \\
    v
  \end{pmatrix}
  =
  \begin{pmatrix}
    p \\
    q
  \end{pmatrix}
  \]
  since
  \[ \det
  \begin{pmatrix}
    p_n & p_{n + 1} \\
    q_n & q_{n + 1}
  \end{pmatrix}
  \in \{\pm 1\}
  \]
  we can invert the matrix over integers. Then
  \[ \begin{cases}
    p_n u + p_{n + 1} v = p \\
    q_n u + q_{n + 1} v = q
  \end{cases}
  \implies q\theta - p = u(q_n\theta - p_n) +
  v(q_{n + 1} \theta - p_{n + 1}) \]
  If $v = 0$, then $|q\theta - p| = |u| |q_n\theta
  - p_n|$. $u$ is a non-negative integer, so
  \[ |q\theta - p| \ge |q_n\theta - p_n| .\]
  If $v \neq 0$, then $q = q_{n + 1} v + q_n u$
  and $q < q_{n + 1}$. Hence $u, v$ must have
  opposite signs, with $u \neq 0$. The sign of
  $q_n \theta - p_n$ is the same as the sign of
  $\theta - \frac{p_n}{q_n}$, which is the
  oppositve of the sign of $\theta - \frac{p_{n +
  1}}{q_{n + 1}}$. Therefore $u(q_n\theta - p_n)$
  and $v(q_{n + 1}\theta - p_{n + 1})$ have the
  same sign. Therefore
  \begin{align*}
    |q\theta - p|
    &= |u| |q_n\theta - p_n| + |v| |q_{n +
    1}\theta - p_{n + 1}| \\
    &\ge |q_n\theta - p_n|
  \end{align*}
  as $u \neq 0$.}
\end{proof}
\end{flashcard}

\begin{flashcard}[convergent-approximates-well]
\begin{theorem}
  % Theorem 5.6
  Let $\theta \in \RR \setminus \QQ$. Then
  \begin{enumerate}[(1)]
    \item \cloze{For all $n \ge 0$, there exists
      $\frac{p}{q} \in \{\frac{p_n}{q_n},
      \frac{p_{n + 1}}{q_{n + 1}}\}$ such that
      \[ \left| \theta - \frac{p}{q} \right| <
      \frac{1}{2q^2} .\]}
    \item \cloze{If $p \in \ZZ$, $q \in \NN$, and $\left|
      \theta - \frac{p}{q}\right| <
      \frac{1}{2q^2}$, then $\frac{p}{q}$ is a
      convergent of $\theta$.}
  \end{enumerate}
\end{theorem}

\begin{proof}
  \phantom{}
  \begin{enumerate}[(1)]
    \item \cloze{Again use that $\theta -
      \frac{p_n}{q_n}$, $\theta - \frac{p_{n +
      1}}{q_{n + 1}}$ has opposite sign. Hence
      \begin{align*}
        \left| \theta - \frac{p_n}{q_n} \right|
        + \left| \theta - \frac{p_{n + 1}}{q_{n +
        1}} \right|
        &= \left| \frac{p_n}{q_n} - \frac{p_{n +
        1}}{q_{n + 1}} \right| \\
        &= \frac{1}{q_n q_{n + 1}} \\
        &< \half \left( \frac{1}{q_n^2} +
        \frac{1}{q_{n + 1}^2} \right)
      \end{align*}
      So we have $\left| \theta - \frac{p_i}{q_i}
      \right| < \frac{1}{2q_i^2}$ for at least one
      $i \in \{n, n + 1\}$. $\alpha, \beta$
      distinct, positive real numbers. Therefore
      \[ (\alpha - \beta)^2 > 0 \implies \half
      (\alpha^2 + \beta^2) > \alpha \beta .\]}
    \item \cloze{Choose $n \ge 0$ soc that $q_n \le q <
      q_{n + 1}$. Then $|q\theta - p| \ge
      |q_n\theta - p_n|$, by
      \cref{convergent_optimal_approximation}(1).
      We consider
      \begin{align*}
        \left| \frac{p}{q} - \frac{p_n}{q_n} \right|
        &\le \left| \theta - \frac{p}{q} \right| +
        \left| \theta - \frac{p_n}{q_n} \right| \\
        &= \frac{1}{q} |q\theta - p| +
        \frac{1}{q_n} |q_n\theta - p_n| \\
        &\le \left( \frac{1}{q} + \frac{1}{q_n}
        \right) (q\theta - p) \\
        &< \left( \frac{1}{q} + \frac{1}{q_n}
        \right) \frac{1}{2q}
      \end{align*}
      Suppose for contradiction that $\frac{p}{q}
      \neq \frac{p_n}{q_n}$. Then
      \[ \left| \frac{p}{q} - \frac{p_n}{q_n}
      \right| = \left| \frac{pq_n - p_n q}{qq_n}
      \right| \ge \frac{1}{qq_n} \]
      so
      \begin{align*}
        \frac{1}{qq_n} < \left( \frac{1}{q} +
        \frac{1}{q_n} \right)
        &\implies \frac{1}{q_n} < \frac{1}{2q} +
        \frac{1}{2q_n} \\
        &\implies \frac{1}{2q_n} < \frac{1}{2q} \\
        &\implies q < q_n \contradiction \qedhere
      \end{align*}}
  \end{enumerate}
\end{proof}
\end{flashcard}

\textbf{Application:} If $d \in \NN$ is a
non-square, can find solutions to \emph{Pell's
equation} $x^2 - dy^2 = 1$, with $x, y \in \NN$?
If $(p, q)$ is a solution, then
\begin{align*}
  \left( \frac{p}{q} \right)^2 - d
  &= \frac{1}{q^2} \\
  \implies \frac{p}{q} - \sqrt{d}
  &= \frac{1}{q^2} \frac{1}{\frac{p}{q} + \sqrt{d}}
  < \frac{1}{2q^2} \\
  \implies \frac{p}{q} \text{ is a
  con}&\text{vergent of}
  \sqrt{d} \in \RR \setminus \QQ
\end{align*}
