I am trying to compute best rational approximations to various transcendental numbers $c$, subject to the following constraints: $$\frac {i j} {2^k} = c + \epsilon, \space\space2^n \le i, j \lt 2^{n+1}$$
For sufficiently small $n$, say $n \lt 40$, optimal values of $i,j,k$ which minimize $\vert\epsilon\vert$ can be found by exhaustive search. For example, for $n=23$ and $c=\pi$, the best rational approximation under my constraints is provided by $i=14120171, j=15656321, k=46$ such that $$\frac {14120171 \times 15656321}{2^{46}} = \pi + 3.1974({10^{-14}})$$
How would I go about finding optimal rational approximations for larger $n$, say $n=52$, for which exhaustive search is not feasible?
For large $n$ I am currently using heuristic searches based on methods like simulated annealing, but I am wondering whether there is a mathematical approach rather than an engineering approach I could utilize. I am aware that one can use the convergents of the continued fraction expansion of a transcendental number to determine best rational approximations, but I do not know how to then extend this approach to rational approximations that satisfy my constraints.
The practical relevance of my constraints is that for an appropriate choice of $n$, $a=\frac {i}{2^{\left \lceil \frac {k}{2} \right \rceil}}$ and $b=\frac {j}{2^{\left \lfloor \frac {k}{2} \right \rfloor}}$ are exactly representable as IEEE-754 floating-point numbers.
Modern floating-point processors frequently offer a fused multiply-add operation (FMA), which computes $ab+c$ such that the exact product $ab$ is used in the addition, and only the final sum is rounded. This operation is also exposed as a function in programming languages, for example the standard math functions fma()
and fmaf()
in ISO C99.
In conjunction with the desired rational approximations, this allows a more accurate computation of expressions like $\pi-x$ which can be programmed as fmaf(1.68325555f, 1.86637890f, -x)
instead of simply using 3.14159265f - x
.