# Legendre's Proof (continued fractions) from Hardy's Book

I'm tryng to understand the proof given in Hardys book A Theory of Numbers from the chapter on continued fractions. It states that

If $$\left|\frac{p}{q}-x\right| < \frac{1}{2q^2}$$ then $\frac{p}{q}$ is a convegent to $x$.

Proof:

I the above inequality holds then $$\frac{p}{q} - x = \frac{\epsilon \alpha}{q^2},$$

$\epsilon = \pm 1$ and $0 < \alpha < \frac{1}{2}.$ This part makes sense but then he says

We write $\frac{p}{q}$ as a finite continued fraction say $[a_0,a_1,...,a_n];$ and by Theorem 158 we can choose n even or odd, we may assume that $\epsilon = (-1)^{n-1}.$ x can be written as

$$x = \frac{\omega p_n + p_{n-1}}{\omega q_n + q_{n-1}}$$

This equality is what I dont understand. Where does $\omega$ come from?

The book says that $\omega = \frac{1}{\alpha} - \frac{q_{n-1}}{q_n}.$

but I've tried staring at it for the last hour and I dont get where it comes from.

Consider $\omega$ as an unknown for a moment. Solve $x = \frac{\omega p_n + p_{n-1}}{\omega q_n + q_{n-1}}$ for $\omega$: $$\omega = \frac{q_{n-1}x - p_{n-1}}{-q_nx+p_n}$$ Now insert $$x = \frac{p}{q} - \frac{\epsilon\alpha}{q^2}$$ and note $p=p_n, q=q_n$ as well as $q_{n-1}p_n-p_{n-1}q_n = \epsilon$. This gives immediately the stated value for $\omega$.