# Probability

I once saw an interesting math challenge: Assume X and Y are randomly chosen numbers, with each being equally likely to be any number between 0 and 1.  Take Y/X and round to the closest integer.  What is the probability that this number will be even (or odd)?

It turns out this problem involves using the a ratio distribution.  I felt that Wikipedia’s page on this subject was very poor, at the very least certainly unintuitive, so I hoped to come up with a more intuitive explanation.

(Note: This post does assume familiarity with probability distributions, using them to get cumulative distributions, averages, etc.)

It occurred to me that problems like this can be shown graphically.  Because X and Y are between 0 and 1, you can plot (X,Y) in a unit square.  Because they are uniformly distributed there, and the area of the square is exactly equal to one, the probability of getting any collection of points is exactly equal to the area of that collection.

Example, suppose you want to find the probability that x is between 0.6 and 0.7 (and you don’t care what y is).  The region described by that is a rectangle with area of 0.1.  Therefore, the probability of that result is 0.1. If you want x to be between 0.6 and 0.7 and also want y to be between 0.1 and 0.3, the area of that region is 0.02, so that is the probability of that result.

However, this general idea can find the probability for more complicated relations between X and Y.

Say we want to know how to describe X+Y — what the probability of getting some S = X + Y is.

If X + Y = S, then Y = S – X.  This is the equation for a straight line.  Furthermore, If X + Y <= S, then Y <= S – X.  The probability of getting some value for X + Y that is less than X will be the area under the line Y = S – X.  The below figure shows what this area would look like if S = 1/2. The region is a triangle whose base and width are both S.  Therefore, the cumulative probability that X + Y is less than S is $\frac{1}{2}S^2$

However, this is only true if S < 1.  If 1 < S <2, the area is the whole unit square with a triangle taken out of it.  The below figure shows the case for S = 1.5. In this case, the base and heigh of the triangular notch we are subtracting is (2-S).  This means the cumulative probability that X + Y is less than S is $1 - \frac{1}{2}(2-S)^2 = -\frac{1}{2}S^2 + 2S-1$

We can find the probability distribution by differentiating the cumulative probability by S. $p(S) = S, 0 \leq S \leq 1$ $p(S) = 2-S, 1 \leq S \leq 2$

This probability distribution is graphed below. What about the product S = X * Y?  Consider the case X * Y < 1/2, graphed below. In general, the region will be a rectangle with base S and height 1, plus the area under the curve Y = S/X, from X = S to X = 1.  This means the cumulative probability is $S + \int_{S}^{1} \frac{S}{X} dx = S - S log(S)$

Note that while log(0) is negative infinity, the limit of S log(S), as S tends to zero, is zero; so the cumulative probability that X*Y is less than zero is of course zero.

This means that the probability distribution is $p(S) = -log(S)$

Unlike the previous probability distribution, which had mean, median, and mode all equal to 1, this one is not symmetric.  In this case, the mode is zero, the median is the S that solves $1/2 = S - S log(S)$

or $S \approx 0.18668$

and the mean is $\int_{0}^{1} -S log(S) dS = \left [ -\frac{S^2(2log(S)-1)}{4} \right ]^{1}_{0} = \frac{1}{4}$

Now let’s consider the example that kicked off this post.  What about Y/X < S?  In that case, Y = SX is again a line. The below figure shows the case that Y/X < 1/3 In general, if S <1, the area will be a triangle with base 1 and height S, so the area is $\frac{1}{2}S$

If S>1, things change.  The below graph shows the case for S = 3. Now we need to subtract the area of the white triangle from 1.  This white triangle will have height 1 and base 1/S, so the area (of the shaded region) will be $1 - \frac{1}{2}\frac{1}{S}$

By differentiating the cumulative probabilities, we get the probability density: $p(S) = \frac{1}{2}, S \leq 1$ $p(S) = \frac{1}{2}\frac{1}{S^2}, 1 \leq S$

Going back to my criticism that Wikipedia’s article explains this poorly, they have this result, but they certainly do not give a simple, intuitive reason why the functional form of the probability density changes when S passes 1.  In this derivation, the explanation is very simple: The line Y=SX passes the corner at (1,1) when S passes 1.

Now we are able to answer the question that kicked off this thread:  If you take Y/X and round to the nearest integer, what is the probability that that integer will be even?

Even if we didn’t know the form of the probability density, the answer would be $\int_{0}^{1/2}p(S)dS + \int_{1\ 1/2}^{2\ 1/2}p(S)dS + \int_{3\ 1/2}^{4\ 1/2}p(S)dS + \int_{5\ 1/2}^{6\ 1/2}p(S)dS +...$

This is because, if the result is between 0 and 1/2, we round it to zero (even); if the result is between one and one half and two and one half, we round it to two (even); and so on.  So, we need to find the sum of all such probabilities.

Since we DO know the form of the probability density, we can substitute in $\int_{0}^{1/2} \frac{1}{2}dS + \int_{1\ 1/2}^{2\ 1/2}\frac{1}{2}\frac{1}{S^2}dS + \int_{3\ 1/2}^{4\ 1/2}\frac{1}{2}\frac{1}{S^2}dS + ...$

This evaluates to $\frac{1}{4} + \left[ -\frac{1}{2}\frac{1}{S} \right ]_{3/2}^{5/2}+\left[ -\frac{1}{2}\frac{1}{S} \right ]_{7/2}^{9/2}+\left[ -\frac{1}{2}\frac{1}{S} \right ]_{11/2}^{13/2}+...$

Or $\frac{1}{4} +\frac{1}{3} - \frac{1}{5} +\frac{1}{7} -\frac{1}{9} +\frac{1}{11} -\frac{1}{13} +...$

Everything after that first 1/4 looks very similar to the Leibniz sum for pi.  Therefore, we can solve for that sum and rewrite the previous equation as $\frac{1}{4} + (1-\frac{\pi}{4})$

Finally, it is $\frac{5}{4}-\frac{\pi}{4} \approx 0.4646$

Not only is the probability of getting an even number not equal to 50% (though 46.46% is sort of close), it surprisingly even involves the irrational number pi, which is especially surprising since people tend to think of pi as relating to circles.  There is well known problem, Buffon’s needle problem, which includes a factor of pi in a probability, but in my opinion that is much less surprising, since Buffon’s needle problem is obviously geometrical.

Next time, we’ll use similar graphical methods to solve a more complicated, and maybe more interesting, probability problem.