[Math] Probability of an even number

probability

I have been having problems solving the following problem.

Two real numbers $x$ and $y$ are chosen uniformly at random in the interval $(0,1)$. What is the probability that the closest integer to $x/y$ is even?

I wrote a computer program to estimate the answer but I can't see how to solve it without one.

Best Answer

The integer closest to $\frac xy$ is $n>1$ if $n-\frac12<\frac xy<n+\frac12$ or equivalently $(2n-1)y<2x<(2n+1)y$ (it doesn't really matter what you decide for the boundary cases or if you take $\le$ instead of $<$). This describes a triangle with vertices $(0,0)$, $(\frac2{2n-1},1)$ and $(\frac2{2n+1},1)$ and that has area $A_n=\frac12(\frac{2}{2n-1}-\frac2{2n+1})=\frac2{4n^2-1}$. In the special case $n=0$, we obtain a triangle with vertices $(0,0)$, $(1,0)$, and $(1,\frac12)$ and area $A_0=\frac14$. The sought probability equals $$ p =\sum_{k=0}^\infty A_{2k}\approx 0.4646.$$

This sum is also essentially the imaginary part of $\sum_{n=1}^\infty \frac{i^n}n$. More precisely (with the $\frac54$ coming from special treatment for $A_0$ and $\frac in$), $$ p = \frac54-\Im\left(\sum_{n=1}^\infty \frac{i^n}n\right)=\frac54-\Im(\ln i)=\frac{5-\pi}4.$$

Related Question