Best rational approximation with a twist: denominator must be a square

213 Views Asked by At

I'm looking to form a series of better and better rational number approximations to a known value $x$. This is a classic problem elegantly solved by the use of a continued fraction representation. For example, a series of better and better approximations of $\pi$ can be formed as ${3\over1}$, ${22\over7}$, ${355\over113}$... by truncating the continued fraction representation at different depths.

I'm puzzling how to compute a similar series of rational values but with the restriction that the denominator must be a square. So again using $\pi$ as an example, we might form the continually improving series $3\over1$, $13\over 4$, $38\over 9$, $50\over 16$, $113\over49$, $201\over64$, $531\over169$, $908\over289$, $1662\over529$,... . I have generated those, inefficiently, by simply testing every increasing denominator and printing only those that formed a approximation that improved over the previous best.

My question is whether there is an elegant way to generate these approximations better than my brute force method, especially as the denominator becomes large (hundreds of digits) and brute force is no longer a viable option.

I've thought of an initial approach. I form a classic continued fraction approximation not for x, but for $\sqrt x$, and then square the approximation. This does indeed produce a series of improving rational approximators with square denominators, but it is clearly an inferior list since it only considers numerators that are also squares, so it's only exploring a very very small subset of possible values.

I'm stuck for any further ideas how to approach this problem, and thank you for your suggestions!