I'm trying to come up with a way to solve this problem:
Assume x and y are rational numbers in the range (0, 1].
Given x, what is the nearest y to x such that yn=1 for some integer n?
Or put another way,
Round x to the nearest 1/n.
What I'm trying to do is find a good interval for a table I'm creating. I've computed the optimal interval, x, but I also want the table to land on every whole integer as well.
I'm trying to find the function that performs this transformation.
Examples:
f(x) = y
f(0.3168705857) = 1/3
f(0.2141233120) = 1/5
f(0.9583990664) = 1
f(0.2426311964) = 1/4
f(0.8125500321) = 1
f(0.3569497599) = 1/3
f(0.0539263572) = 1/19