# Finite-sample distance under identical populations

This is an exact illustrative probability model, not disk telemetry or a new
statistical method. Two samples independently contain n iid observations drawn
with replacement from the same population: 1 ms or 101 ms, each with probability
one half. Their true population distance is zero.

## Derivation and meaning

Let X and Y count the high observations. They are independent Binomial(n, 1/2)
counts. For inverse empirical CDFs, only probability mass abs(X-Y)/n is moved
between the two support points. Hence D^2 = 10000 * abs(X-Y)/n in ms^2.

Because n-Y is also Binomial(n, 1/2) and independent of X,
Z = X + (n-Y) is Binomial(2n, 1/2), and X-Y = Z-n. Thus
P(abs(X-Y)=0) = choose(2n,n)/4^n. For k=1,...,n,
P(abs(X-Y)=k) = 2*choose(2n,n+k)/4^n.
The implementation generates these n+1 exact probabilities by adjacent integer
coefficient ratios, without constructing 4^n individual binary sample pairs.

For a separate closed-form check, set C_k = choose(2n,n+k). The identity
k*C_k = n*(choose(2n-1,n+k-1) - choose(2n-1,n+k))
telescopes when summed from k=1 to n. It gives
E[abs(X-Y)] = n*choose(2n,n)/4^n, so
E[D^2] = 10000*choose(2n,n)/4^n.

The reported square root is sqrt(E[D^2]), NOT E[D].
For n=1 these are about 70.711 ms and 50 ms, respectively.
It is not a p-value, confidence interval or threshold. The chance of a nonzero
sample distance increases with n in this model while its mean square decreases.
Do not normalize by the population mean to claim E[relative demerit]: the
reference sample mean is random and enters a nonlinear ratio.

Independence, fair probabilities and two-point support are assumptions. No
general latency population is fitted, no actual measurements are drawn, and no
Monte Carlo seed is needed. Repeated requests, shared samples or temporal
dependence do not satisfy this design. Duplicating records does not increase
independent information. No general bootstrap procedure is implemented.

## Primary context

Sommerfeld and Munk, JRSS B 80 (2018), 219-238, DOI 10.1111/rssb.12236:
https://arxiv.org/pdf/1610.03287v2
Theorem 1(c), section 4 and appendix B address finite-support inference.
Ramdas, Garcia Trillos and Cuturi, Entropy 19 (2017), 47,
DOI 10.3390/e19020047: https://www.mdpi.com/1099-4300/19/2/47
Section 2 separates a distance statistic from a calibrated decision rule.

## Reproduction

Run from this directory with Python's standard library:
```sh
python3 -B null_sampling.py --check null-results.json
python3 -B -m unittest test_null_sampling.py -v
python3 -B -O -m unittest test_null_sampling.py -v
```

To regenerate, use --write instead of --check. JSON records UTC generation time,
Python version and source hashes. Exact fraction fields are authoritative;
the existing range-checked numeric.py supplies approximate displayed roots.
Counts describe possible independent observations in the model, not observations
collected by Hesela. The standalone tests enumerate raw binary sequences through
n=6, independently multiply binomial probabilities through n=40, and compare
every pair of high counts through n=16 against the existing interval sweep.
They also check units, input errors, duplication and the distinction between
E[D] and sqrt(E[D^2]). Tests are deterministic arithmetic checks, not experiments.
