# Disk-model demerit: exact constructed controls

No external dependencies. Run with Python 3.10 or newer:
```sh
python3 -B model.py --check results.json
python3 -B -m unittest -v test_model.py
python3 -B -O -m unittest -v test_model.py
```

The historical demerit compares horizontal separations of latency-distribution
curves. This implementation explicitly chooses inverse empirical CDFs with equal
mass per observation. It integrates squared differences exactly using Fraction,
then displays their square root. It is not a reproduction of the historical
programs' undocumented interpolation/binning choices.

For equal sample sizes, squared distance is the mean squared difference of sorted
observations. Request-paired squared error instead preserves the supplied order;
the caller must establish that order really pairs the same requests. Unequal
sample sizes have no request-paired value in the examples.

For unequal sizes, merge cumulative-probability endpoints, without interpolation,
truncation or padding. At most n+m-1 intervals are visited after sorting. The
independent small-case oracle expands to an LCM-sized equal-probability grid;
that slow oracle is confined to tests. The coprime 1009/1013 control visits 2021
intervals instead of expanding 1022117 positions. This is an operation-count
comparison, not a measured speedup.

Nine constructed cases include swaps, a matched mean, unequal sample masses,
duplication, a slow-request omission and a zero denominator. Exact squared values
are rational strings in ms^2. Square roots and relative percentages are display
approximations. Relative demerit uses the reference mean; a zero mean returns
null with a reason, not a perfect score.

The 100-request tail fixture deliberately excludes its final paired request in
the filtered case, leaving 99 requests. It does not reproduce the thresholds or
effect sizes of the 1994 report. The suite checks 14400 small sample pairs, 24
permutations, 27 order-preserving comparisons and explicit edge cases.

Source works retain their copyright. Original example code and results belong
to this repository; no historical trace or paper is redistributed.

## Checked numerical presentation

Keep numeric.py beside model.py, tail.py and mixture.py. All three result
generators record its SHA256, in addition to their existing source identities.
No third-party package is required.

The exact rational fields are unchanged by display conversion. Positive roots
use Python Decimal with an explicit 80-digit, wide-exponent context before
conversion to float. This prevents first converting a 10^-400 square to zero
or a 10^400 square outside float range when its root still fits. Normalize the
squared relative percentage exactly before extracting its root. Do not first
multiply a large floating RMS by 100 and then divide by the reference mean.

This is an approximate display algorithm, not a proof of correctly rounded
binary64 results for every rational input. Positive roots that round to zero
or infinity raise ValueError; exact squared-distance functions remain usable.
True zero is zero. A zero reference mean still makes relative demerit undefined.
The helper does not modify or inherit the caller's decimal settings.

Run all original and numerical regression tests:
```sh
python3 -B -m unittest discover -p 'test_*.py' -v
python3 -B -O -m unittest discover -p 'test_*.py' -v
```
The 12 new methods include 654 comparisons with an independently binary-scaled
oracle (within two ulps), exact squared float endpoints, scaling by 10^-300
through 10^300, normalization at 10^307, and a compact count of 10^400.
These extreme scales/counts are arithmetic stress tests, not measured data.
Previous exact case values and three-decimal table displays are unchanged.

Background, not an implementation copied here:
- Hanson and Hopkins (2018), Remark on Algorithm 539, sections 4 and 6:
  https://kar.kent.ac.uk/67205/1/remark.pdf
- Python 3.11 decimal context and square-root contract:
  https://docs.python.org/3.11/library/decimal.html

The checked conversion solves a range problem. It does not quantify uncertainty,
repair excluded observations or establish a model's validity on another workload.
