A puzzle from Sheena
A puzzle that came to me via @sheena2907:
Choose two numbers, $x$ and $y$, uniformly from $[0,1]^2$. What’s the probability that $\frac{x}{y}$ rounds to an even number? What’s the probability that it rounds down to an even number?
As always, spoilers below the line.
Rounding
One of my best approaches to a problem I don’t see an immediate way into is to rephrase it into something else, in case I can see my way into that.
The first thing I think of is what, algebraically, is going on. For $\frac{x}{y}$ to round to an even number, $2n - \frac{1}{2} \le \frac{x}{y} < 2n + \frac{1}{2}$ for some (non-negative) integer $n$.
We can safely double everything: $4n - 1 \le \frac{2x}{y} < 4n + 1$ - although I’m not sure how much that helps yet. We can also multiply by $y$ to get $(4n-1)y \le 2x < (4n+1)y$.
Now we’re (maybe) getting somewhere: if we find the area between the lines $(4n-1)y = 2x$ and $(4n+1)y = 2x$ inside the unit square and add up the infinite series, we’ll have our answer. We may need to take a bit of care with the edge cases and possibly the corner, but let’s see.
For $n=0$, the lines are $y=\pm 2x$. We’re only interested in the part inside the unit square, which is a triangle of area $\frac{1}{4}$.
For $n=1$, the lines are $y=\frac{2}{3}x$ and $y = \frac{2}{5}x$, which hit the edge of the box at $x=\frac{2}{3}$ and $x=\frac{2}{5}$, forming a triangle of area $\frac{2}{15}$.
The next triangle has a ‘base’ of $\frac{2}{7} - \frac{2}{9}$ and an area of $\frac{2}{63}$.
There’s a pattern forming! The answer will be $S = \frac{1}{4} + \sum_{n=1}{\infty} \frac{1}{4n-1} - \frac{1}{4n+1}$. Does that have a closed form sum?
Writing it out helps: it’s $S = \frac{1}{4} + \left(\frac{1}{3}-\frac{1}{5}+\frac{1}{7}-\frac{1}{9}\right)$, and that parenthetical series jumps out: $\arctan(1) = 1 - \frac{1}{3} + \frac{1}{5} - \dots$, so the brackets work out to be $1-\frac{\pi}{4}$.
We need to add on the quarter, though, so $S = \frac{5-\pi}{4}$, which is about $0.4646$.
Rounding down
The same sort of approach ought to work for ‘rounding down’, which I’m going to take as meaning that the integer part of $\frac{x}{y}$ is even.
That turns into $2n \le \frac{x}{y} < 2n+1$.
Multiply everything by $y$ and we get the two lines $2ny = x$ and $(2n+1)y = x$.
This time, the $n=0$ case gives the lines $x=0$ and $y=x$, which give a triangle of area $\frac{1}{2}$ at the top of the box.
With $n=1$, the base of the triangle is $\frac{1}{2}-\frac{1}{3}$ (giving an area of $\frac{1}{6})$
For $n=2$, it’s $\frac{1}{4}-\frac{1}{5}$, and so on.
The total area is $S = \frac{1}{2} + \frac{1}{2}\sum_{n=1}^{\infty} \frac{1}{2n} - \frac{1}{2n+1}$. Again, writing that out makes things easier: $\frac{1}{2}-\frac{1}{3} + \frac{1}{4} - \frac{1}{5} + \dots$ converges (not absolutely!) to $1-\ln(2)$.
So, in the second case, $S= 1 - \frac{1}{2}\ln(2)$, or about 0.6534.
Did you do it a different way? I’d love to hear about it!