@@ -134,11 +134,11 @@ as possible without violating the denominator bound.
134134The main loop, together with that partial Euclidean step, produces candidate
135135approximations $r/s$ and $t/u$ which bracket the target fraction $m/n$, and
136136whose denominators are no greater than the limit $\ell$. With just two
137- additional pieces of information, namely that $ts - ru = ±1$ and that $\ell < s
138- + u$, we can deduce that _ all_ fractions strictly between $r/s$ and $t/u$ have
139- denominator greater than $\ell$, hence that either $r/s$ or $t/u$ is a best
140- approximation. The final line of the code then determines which of these two
141- fractions is better and returns it.
137+ additional pieces of information, namely that $ts - ru = ±1$ and that
138+ $\ell < s + u$, we can deduce that _ all_ fractions strictly between $r/s$ and
139+ $t/u$ have denominator greater than $\ell$, hence that either $r/s$ or $t/u$
140+ is a best approximation. The final line of the code then determines which of
141+ these two fractions is better and returns it.
142142
143143In more detail, we'll show in the sections below that after exiting the ` while `
144144loop and defining $t$ and $u$, the following five properties hold:
@@ -156,12 +156,12 @@ any fraction $y/z$ strictly between $r/s$ and $t/u$ has $z > \ell$. We have:
156156
157157$$ z = (ts - ru)vz = (tz - yu)vs + (ys - rz)vu. $$
158158
159- Now $v$ is either $1$ or $-1$. If $v = 1$ then $r/s < t/u$, so $r/s < y/z <
160- t/u$. So $ys - rz$ and $tz - yu$ are positive, hence $(ys - rz)v$ and $(tz -
161- yu)v$ are positive integers. Conversely if $v = -1$ then $t/u < r/s$, so $t/u <
162- y/z < r/s$ and $ys - rz$ and $tz - yu$ are negative. So again $(ys - rz)v$ and
163- $(tz - yu)v$ are positive integers. So in either case, $(tz - yu)v \ge 1$ and
164- $(ys - rz)v \ge 1$, hence
159+ Now $v$ is either $1$ or $-1$. If $v = 1$ then $r/s < t/u$, so $r/s < y/z < t/u$.
160+ So $ys - rz$ and $tz - yu$ are positive, hence $(ys - rz)v$ and $(tz - yu)v$
161+ are positive integers. Conversely if $v = -1$ then $t/u < r/s$, so
162+ $t/u < y/z < r/s$ and $ys - rz$ and $tz - yu$ are negative. So again
163+ $(ys - rz)v$ and $( tz - yu)v$ are positive integers. So in either case,
164+ $(tz - yu)v \ge 1$ and $( ys - rz)v \ge 1$, hence
165165$$ z = [(tz-yu)v]s + [(ys - rz)v]u \ge s + u > \ell. $$
166166
167167At this point $r/s$ and $t/u$ are candidates, there are no candidates strictly
@@ -208,14 +208,14 @@ invariant $b < a$ is smaller than the old value of $a$.
208208Here we prove that the five properties mentioned earlier hold.
209209
210210One of our two possible return values, $r/s$, comes directly from the loop. We
211- construct the second candidate $t/u$ after the loop: $t = p + kr$ and $u = q +
212- ks$, with $k = \lfloor (\ell - q) / s \rfloor$. Think of $t/u$ as the result of
213- taking a _ partial_ Euclidean step, as a replacement for the full Euclidean step
214- which would have taken the denominator out of bounds.
211+ construct the second candidate $t/u$ after the loop: $t = p + kr$ and
212+ $u = q + ks$, with $k = \lfloor (\ell - q) / s \rfloor$. Think of $t/u$ as
213+ the result of taking a _ partial_ Euclidean step, as a replacement for the
214+ full Euclidean step which would have taken the denominator out of bounds.
215215
216216That $0 < s \le \ell$ follows directly from the loop invariants. From the
217- definition of $k$ we have $ks \le \ell - q < s + ks$, hence $ks + q \le \ell <
218- s + ks + q$, that is
217+ definition of $k$ we have $ks \le \ell - q < s + ks$, hence
218+ $ks + q \le \ell < s + ks + q$, that is
219219$$ u \le \ell < s + u. $$
220220That $u$ is positive follows from $s \le \ell < s + u$. So $t/u$ is also a
221221valid candidate approximation.
@@ -225,8 +225,8 @@ analogous relation for $r/s$ and $t/u$:
225225$$ (ts - ru)v = 1. $$
226226
227227We also define an integer $c = a - kb$, the result of taking the partial
228- Euclidean step that gives $t$ and $u$. It's immediate from the definitions and
229- the earlier loop invariants that:
228+ Euclidean step that gives $t$ and $u$. It's immediate from the definitions
229+ and the earlier loop invariants that:
230230$$ (tn - mu)v = c $$
231231and
232232$$ bt + cr = m $$
0 commit comments