How best to select $d$ from $[d_1, d_2]$ so $n/d$ is closest to $p/q$

45 Views Asked by At

An answer to a question here asked how to approximate $pi$ with denominators in a certain range (where the minimum denominator is not necessarily 1). This is almost solved by the continued-fraction approach, but the requirement that the denominator not be smaller than a certain value is the challenge. I am able to suggest a method of not testing every denominator in the range, by finding the range of numerators that are candidates given the range of candidates.

e.g. what is the best approximation of $5/41$ with a fraction having denominator in range $[170, 200]$? We can find that numerators will have to be in the range $[21, 24]$ which is smaller than the denominator range. These numerators correspond to candidates $21/172, 22/180, 23/189, 24/197$ where $24/197$ is closest to $5/41$. When ordered by value instead of numerator, these candidates are $23/189, 24/197, 21/172, 22/180$ and it is clear that they are ordered by neither numerator nor denominator.

It seems like one must simply test each candidate to find the closest approximation. Is there a better way?

In a given interval $[a/D, (a+1)/D]$, is there a way to know in what order numerators of fractions with denominators $d_i$ with $d <= d_i < D$ will appear? If $a = 1$ and $D/d < 2$ we know the order since all numerators will be 1 in the interval, e.g. if $d=170$ and $D=200$ then $1/200 < 1/119 < ... 1/170 < 2/200$. But when $a=24$ then numerators $18-25$ appear on fractions between $24/200$ and $25/200$ in this order (with the stars around the value that corresponded to the numerator of the best approximation): $$[18, 21, 24, 22, 19, 23, 20, 24, 21, 22, 19, 23, 20, 24, 21, 22, 23, 19, *24*, 20, 21, 22, 23, 24, 19, 20, 21, 22, 23, 24, 19, 20, 21, 22, 23, 24, 19, 20, 21, 22, 23, 24, 19, 20, 21, 22, 23, 24, 25]$$