Books · The Fiddler: Solutions
Chapter 86
Round, Round, Get a Round, I Get a Round
Pick two real numbers uniformly and independently from the interval . You can round each to the nearest integer and then add, or add first and then round the sum. What is the probability the two procedures give the same answer?
The Fiddler, Zach Wissner-Gross, August 23, 2024(original post)
Solution
The two procedures can only disagree because rounding discards a little of each number, and the question is whether the discarded pieces, added together, are enough to push the sum across a half-integer boundary. So follow the discarded piece. For uniform on , let its rounding error be . When the nearest integer is and ; when it is and . Each half of maps uniformly onto one half of , so is itself uniform on .
Write and , both integers. Then , and since is an integer, . Rounding first and adding gives ; so the two agree exactly when , that is when the combined error satisfies With independent and uniform on , their sum has a triangular density on , peaking at . The probability it lands in the central band is one minus the two tails, and each tail is so the answer is :
The computation
A closed form this short invites a direct check. Drawing ten million pairs and comparing the two procedures outright agrees with to three decimals.
import numpy as np
rng = np.random.default_rng(0); n = 10_000_000
x, y = rng.random(n), rng.random(n)
print((np.rint(x) + np.rint(y) == np.rint(x + y)).mean()) # ~0.75
Extra Credit
Now pick numbers uniformly from . What is the probability that rounding each and adding equals rounding the sum?
Solution
The reduction survives unchanged. With integers and errors each uniform on , so the two procedures agree exactly when the total error lies in . Shift each error by to make it a standard uniform, ; then follows the Irwin–Hall distribution, the law of a sum of independent uniforms, whose cumulative distribution function is The condition becomes , so the probability is the central slab of that distribution, This gives , , , , , and the value falls slowly towards : more numbers mean more accumulated error, and the chance it all stays within half a unit shrinks.
The computation
Rather than evaluate the formula just derived, run the experiment itself for each : draw uniforms, round each and sum, sum and round, and compare. The measured frequencies match to sampling precision, an independent check on the Irwin–Hall slab.
import numpy as np
rng = np.random.default_rng(0); n = 5_000_000
for N in range(2, 7):
X = rng.random((n, N))
agree = (np.rint(X).sum(1) == np.rint(X.sum(1))).mean()
print(N, round(agree, 4)) # ~0.75, 0.6667, 0.599, 0.55, 0.511