Tell / quantify how much a number is close to some simple integer ratio

approximationelementary-number-theoryfractionsratio

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?

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$

Related Question