How to tell / quantify how much a number is close to some simple integer ratio?

210 Views Asked by At

It's easy for us to tell that 0.49999 is only 0.00001 away from being expressed as a simple ratio: 1/2.

However, it may not be as obvious that 0.142858 is also at most only 0.00001 away from being expressed as a simple ratio. 1/7 in this case.

For our purpose a simple ratio will be defined as a fraction where both the numerator and the denominator consist of a single digit.

Is there a way to calculate the closest simple ratio to a number other than comparing the difference between every ratio and the number in question?

How would you generalize this to approximating simple ratios using integers up to n for the numerator and denominator?

3

There are 3 best solutions below

2
On BEST ANSWER

An algorithm for finding the best rational approximation with a given range of denominator in Wikipedia. Basically you find the continued fraction expansion of the number, then massage the last entry a bit. If you ask Alpha for the continued fraction for $0.142858$ you get $[0; 6, 1, 23808, 1, 2]$ which represents $0+\frac 1{6+\frac 1{1+\frac 1{23808+\ldots}}}$ That huge entry $23808$ says that stopping just before it gives a very good approximation, which here is $\frac 17$

4
On

However, it may not be as obvious that 0.142858 is also only 0.00001 away from being expressed as a simple ratio. 1/7 in this case.

Not only may it not be obvious, but it also is not true either :).
0.142858 is only 0.00001 from 0.142857 (or 0.142859) which is 142857/1000000 (or 142857/1000000). Neither is equal to 1/7 (nor are they simple fractions).

0
On

I'll answer the more general question. Your first question is just the case $n=9$.

Let $x$ be a real number. Then $x$ can be written as a simple ratio if, and only if, there exists $b\in\{1,\ldots,n\}$ such that writing $x$ in base $b$ has at most one digit after the dot. This is because "has at most one digit after the dot" is equivalent to "is a multiple of $\frac 1b$".

Checking that a number is close to a simple ratio is then a matter of checking if there are a lot of $0$ or $b-1$ at the end of its expression in base $b$.