# Demerit and p99: a count-compressed counterexample

These are exact constructed finite populations, not sampled device timings.
Run beside the original model.py and test_model.py (Python 3.10 or newer):

```sh
python3 -B tail.py --check tail-results.json
python3 -B -m unittest discover -p 'test_*.py' -v
python3 -B -O -m unittest discover -p 'test_*.py' -v
```

## Convention and construction
Q(p) is the smallest latency whose cumulative fraction is at least p, with
0 < p <= 1 (inverse ECDF/type 1). The p=0 extension is deliberately not part of
this API. Use Fraction(99, 100), not a binary floating-point 0.99. R's official
quantile documentation distinguishes this from interpolated definitions:
https://stat.ethz.ch/R-manual/R-devel/library/stats/html/quantile.html

For N divisible by 100, the reference has 99N/100 values at 1 ms and N/100 at
101 ms. The modeled histogram moves exactly one observation from fast to slow.
The reference mean is 2 ms. Qref(.99)=1 and Qmodel(.99)=101.
Their squared difference is 10000 on the probability interval
(.99 - 1/N, .99] and zero elsewhere, so D^2 = 10000/N ms^2.
Endpoint choices do not change the integral, but do affect a point percentile.

The four published rows use N=100, 10000, 1000000 and 10000000000.
The last has D=.001 ms, relative demerit .05%, and a 100 ms p99 gap.
Exceedance fractions above 50 ms are 1/100 and 1/100+1/N: the percentile jump
does not imply a large change in the frequency of stalls.

## What the aggregate does bound
For a>0, integrate the inequality
a^2 * indicator(abs(Qref-Qmodel)>=a) <= (Qref-Qmodel)^2.
The probability mass of quantile positions with error >=a is at most
min(1, D^2/a^2). The family reaches equality at a=100 ms.
This is not a statement about request-paired errors or a confidence bound.
Without extra distributional assumptions, integrated error alone does not
control a prescribed point percentile. The jump is an explicit assumption,
not an assertion that real latency densities always have this shape.

## Representation and checks
Histogram entries are exact latency values and positive integer multiplicities,
not buckets, sampled weights or histogram midpoints. Duplicate values are
combined, sorted and swept by cumulative count. At most k+l-1 intervals are
visited for k and l distinct values. Each family member visits three.
Input count size affects integer bit arithmetic; there is no expanded N-row
allocation. No runtime, disk-device or historical-model speedup is claimed.

Twelve new test methods compare 14400 small sample pairs to the existing
independently tested expanded-sample implementation; 12000 percentile queries
to sorted order statistics; 3645 error-mass cases to a direct sorted oracle;
and endpoint, strict-exceedance, unit-scaling, malformed input and huge-count
controls. The existing model suite separately checks an LCM-grid oracle.
These are deterministic controls, not independent scientific experiments.

The original four evidence files are unchanged. tail-results.json records this
generator's hash and generation time. Only floating-point square roots and
relative percentages are display approximations; squared results and fractions
are exact strings. No paper text, figure or external trace is redistributed.
