Round, Round, Get a Round, I Get a Round
This Week's Fiddler
Let's consider the error of a number being the difference between the rounded result and the number itself. So would have an error of , and would have an error of . The error is thus uniformly distributed from , where any incurs an error of , and any incurs an error of .
Now let's consider summing two random numbers. The errors are additive. For example, would have a combined error of . Its sum of rounded numbers would add to , but its rounded sum would be rounding to . So the combined error must rest between and for the sum of rounds to agree with the rounded sum.
In other words, the question is asking what the probability is for two independent and identically distributed (i.i.d.) uniform distributions from to to have a sum between and . As the sum of two uniform distributions leads to a triangular shape, we can find the proportion of the triangle that rests between and and divide it by the area of the entire triangle, which ranges from to (the bounds of the distribution). Due to symmetry, we can find the area taken up from to and divide that by the area from to .
Mental-math-wise, the left side is a right triangle similar to the larger triangle, with a base scaled by . So its area should be that of the larger triangle, making the area we're looking for .
This means the probability is 75%.
Answer: 75%
Extra Credit
Continuing from before, the sum of errors for rounded random variables would actually be the sum of i.i.d. uniformly distributed variables from to . The Irwin–Hall distribution describes this sum of uniformly distributed variables, albeit for (we'll adjust accordingly).
This distribution goes from to , unlike our distribution from the previous part that would go from to . Because we are trying to find the probability that the sum of rounds matches the rounded sum, we want to find the integral of this value in the middle of its distribution, namely the middle from to . Due to this distributions symmetry, we can simply take the first half of this (integrating from to ) and double it. We're left with the integral:
This was the closest I could get to a closed form. At the very least, it's easy to compute! The following computes and simulates the probabilities for from to .
Code
import math
import random
from fractions import Fraction
random.seed(12)
T = 10**6
for n in range(1, 11):
print(f'{n=}')
expected_prob = Fraction(2, math.factorial(n)) * sum(
(-1) ** k
* math.comb(n, k)
* ((Fraction(n, 2) - k) ** n - (Fraction(n - 1, 2) - k) ** n)
for k in range(0, (n + 1) // 2)
)
print(f'{expected_prob=!s} ({float(expected_prob)})')
successes = 0
for _ in range(T):
nums = [random.random() for _ in range(n)]
successes += round(sum(nums)) == sum(round(num) for num in nums)
simulated_prob = successes / T
print(f'{simulated_prob=}')
print()
Output
n=1
expected_prob=1 (1.0)
simulated_prob=1.0
n=2
expected_prob=3/4 (0.75)
simulated_prob=0.749818
n=3
expected_prob=2/3 (0.6666666666666666)
simulated_prob=0.666279
n=4
expected_prob=115/192 (0.5989583333333334)
simulated_prob=0.597873
n=5
expected_prob=11/20 (0.55)
simulated_prob=0.550337
n=6
expected_prob=5887/11520 (0.5110243055555556)
simulated_prob=0.510976
n=7
expected_prob=151/315 (0.4793650793650794)
simulated_prob=0.47955
n=8
expected_prob=259723/573440 (0.4529209681919643)
simulated_prob=0.452742
n=9
expected_prob=15619/36288 (0.4304177689594356)
simulated_prob=0.430889
n=10
expected_prob=381773117/928972800 (0.4109626428244185)
simulated_prob=0.410581
Probability of success | Approx. | |
---|---|---|
1 | 100% | |
2 | 75% | |
3 | 66.67% | |
4 | 59.79% | |
5 | 55.03% | |
6 | 51.10% | |
7 | 47.96% | |
8 | 45.27% | |
9 | 43.09% | |
10 | 41.06% |
Answer: 2/N! * sum from k=0 to floor((N - 1) / 2) for (-1)^k * (N choose k) * ((N / 2 - k)^N - ((N - 1) / 2 - k)^N)