Rational approximations to multiple real numbers, with shared denominator

40 Views Asked by At

To find an optimal rational approximation to a single real number, $x \approx p/q$, one can truncate the continued fraction representation of $x$. Efficient numerical procedures are discussed in previous questions:

Is there a way to find rational approximations to multiple real numbers $x_1, \dots x_n$, such that all rationals share the same denominator? Specifically: I'd like a numerical procedure to find integer numerators $p_1, \dots, p_n$ and a shared integer denominator $q$, such that $x_i \approx p_i / q$ is a good approximation for every $i = 1, \dots, n$.

A brute force scan over $q$ suggests that good approximations can be found. Here is Julia code that simultaneously approximates three irrational numbers, with 4 digits of accuracy, using a single denominator $q$ that is less than 1000.

function find_simultaneous_rationalization(xs; tol)
    for denom = 1:1000
        numers = @. round(Int, xs * denom)
        errs = @. xs - numers / denom
        if all(e -> abs(e) < tol, errs)
            return numers, denom
        end
    end

    error("Could not find rational approximations with small denominator.")
end

xs = [π, 1/5]
numers, denom = find_simultaneous_rationalization(xs; tol=1e-4) # ([377, 24], 120)
numers ./ denom - xs # [7.4e-5, 0.0]

xs = [π, exp(1)]
numers, denom = find_simultaneous_rationalization(xs; tol=1e-4) # ([1863, 1612], 593)
numers ./ denom - xs # [6.0e-5, 9.9e-5]

xs = [π, exp(1), √2]
numers, denom = find_simultaneous_rationalization(xs; tol=1e-4) # ([2086, 1805, 939], 664)
numers ./ denom - xs # [-2.6e-5, 9.2e-5, -5.7e-5]

But perhaps there is some more clever theory connected to this question?