An 'irrationality score'

There is a binary distinction between rational and irrational numbers: all real numbers can either be expressed as p/q for integer p and q, or they can't. This question was inspired by the thought that, while some irrational numbers are 'almost' rational in the sense of being very close to a rational number of low denominator; other rational numbers are 'almost' irrational in the sense of requiring a very large denominator.

Let r be a real number between 0 and 1. To calculate r’s ‘irrationality score’, that is S(r), we take the following procedure.

1. Find the distance between r and the closest rational number with denominator 1 (that is, an integer). Add this value (min(r, 1-r)) to the score.

2. Next, calculate the minimum distance between r and the closest rational number with denominator 2. If this is smaller than the score achieved in step 1 (ie r can be better approximated by 1/2 that by 0 or 1), then add this distance to the total score.

3. Repeat the procedure for rational numbers with denominator 3; then 4 and so on. If any score is smaller than the smallest score achieved previously, add it to the total score.

For a rational number r, by definition there will be a finite number of steps, as once the denominator is equal to q, the rational approximation is perfect and no better approximation can be made.

Of course, for an irrational r, there are infinite additions to make to calculate its score, though these converge rapidly. For instance, for r = pi - 3, the best approximations are: 0/1; 1/3; 1/4; 1/5; 1/6; 1/7; 8/57 ... It's score is approximately 0.34.

It is provable that S(k/q) → (ln 2 – 0.5). As q → infinity, for any k.

There are, however, several questions to ask:

What value of r maximises S(r)?

What is the expected value of S(r) if r is a randomly generated number between 0 and 1?

• I'm a bit confused by your description. What is $S(\frac{1}{2})$? – Chas Brown Jan 12 '17 at 7:51
• S(1/2)=1/2. This is because for q=1 both 0/1 and 1/1 are half away from r - in this case .5 - and then when q=2 the best approximation of 1/2 is equal to r, thus yielding a score of zero. As any subsequent score is only added to S(r) if it is less that the previous best approximation, which in this case is 0, nothing will be added and thus S(r)= 1/2+0=1/2. – Thomas Delaney Jan 12 '17 at 8:27
• – Klangen Jun 21 '18 at 16:32

Some data: The largest score I can find, by random trial and error, is $S(0.5839751641596652) \approx 0.6148779$. There's another slighly lower peak around $r=0.732$. Here are a few graphs of random samples.   