# Probability of an even number

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.

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.$$

• That is awesome! – user66151 Apr 15 '13 at 19:19
• @Hagen : what does your "curly F" symbol mean? You mentioned the imaginary part of the series, so does it mean the imaginary part? – Stefan Smith Apr 15 '13 at 20:42
• @Stefan: Yes, that's a "curly capital I", for imaginary part. The real part is often denoted with a $\Re$ instead. – Cameron Buie Apr 15 '13 at 21:10
• @CameronBuie : Thanks. – Stefan Smith Apr 15 '13 at 23:43

You can evaluate $\mathbb{P}(x/y < 1/2)$ and $\mathbb{P}(x/y \in ]k-1/2, k+1/2[)$ for every $k \geqslant 1$ :

$$\mathbb{P}(x/y < 1/2) = \mathbb{P}(x < y/2) = \int_{0}^1 \mathbb{P}(x < y'/2) dy' = \int_{0}^{1} (y'/2) dy' = 1/4$$

And

$$\mathbb{P}(x/y \in ]k-1/2, k+1/2[) \\= \mathbb{P}(x \in ](k-1/2)y, (k+1/2)y[) \\= \int_{0}^1 \mathbb{P}(x \in ](k-1/2)y', (k+1/2)y'[) dy' \\= \int_{0}^{\frac{1}{k+1/2}} \mathbb{P}(x \in ](k-1/2)y', (k+1/2)y'[) dy' + \int_{\frac{1}{k+1/2}} ^1 \mathbb{P}(x \in ](k-1/2)y', (k+1/2)y'[) dy' \\= \int_{0}^{\frac{1}{k+1/2}} y' dy' + \int_{\frac{1}{k+1/2}} ^1 1-(k-1/2)y' dy' \\= 1/(2k+1) + 1 - \frac{1}{k+1/2} - (k-1/2)(1/2 - (\frac{1}{k+1/2})^2) \\= ~~...$$

You need to think for which numbers $x$ and $y$ the quotioned $x/y$ is even.

In the end you can calculate something like this:

Prob $\Big[\cup_n [y(4n-1)/2 < x < y(4n+1)/2] \cup [0 < x < y/2] \Big]$ for $n=1,2,\dots$

Hope this helps!