Algorithm to find a rational number between i and j, minimizing for number of significant figures after n iterations

32 Views Asked by At

I have a program where, a user selects a number $i$ from a list of floats, and the program adds a number k to the list such that $i < k < j$ where $j$ is the upper neighbour of $i$ in the list (if $j$ doesn't exist set $j = i+1$).

Our data may start with the list $\{1, 2, 3\}$.

One approach is for $k$ to be the midpoint of $i$ and $j$, in which case when the user selects $2$, the program adds $(2+3)/2 = 2.5$ to the list, so we have $\{1, 2, 2.5, 3\}$.

Then the user may again select $2$, which would add $(2+2.5)/2 = 2.25$ to the list and so on.

This works, but my limitation is the number of significant figures in my float.

I noticed that in Base 8, given the number $2$,

$\frac{(2+3)}{2} = \frac{5}{2} = 2.4$,

then given the number 2 again,

$\frac{2+2.4}{2} = \frac{4.4}{2} = 2.2$, and

given the number 2 again,

$\frac{2+2.2}{2} = \frac{4.2}{2} = 2.1$.

This means that over 3 iterations of the program, we are only using 2 s.f.

In fact, given any selections over 3 iterations, we are guaranteed to have no number of more than 2 s.f. in our list.

However in base 10, the result after 3 iterations on the number 2 would be $2.125$ which has 4 s.f.

Restricting ourselves to base 10 and the starting list $\{1, 2, 3\}$, what is an algorithm on $i$ and $j$ such that given any user selections, we ensure that after 3 iterations there are no entries with 3 or more s.f.? Bonus if the algorithm is not conditional on the values of $i$ and $j$.