# Third version: totals against the source's own units, bounds on the gate, and a test sized for the decision

Declared after the first and second versions' results had been read, and before the code below was written or run.
Nothing in either earlier version is edited: protocol-r1.json, predictions-r1.json, every results/*-r1.json file,
CHANGES-r2.md and results/change2-r2.json stay as they are, and the pages report their figures beside these.

## Why

Three questions are left open by the earlier versions. Totals in the first version read the source side with the rule
document's units, so a unit documented wrong moves both sides together; a gate could instead tie the target to the
source system's own reported amounts. Both earlier versions judge the target rules against the failures of the
correct conversion, which a real first run does not have, so the quick checks' 25 of 40 is an upper bound whose lower
end was never stated. And the proposed test (29 charge-off-moving faults with no miss) mixes a one-sided bound with
the two-sided 32% beside it, and was not sized to tell the observed miss share from the 10% line. Every figure here
was chosen after the results and is labelled so on the pages; none enters a headline hit rate.

## Part A: totals against the source system's own units

- Scope: every fault in the 19 chosen and 40 random sets. For a fault in code the rule document is correct, so this
  variant equals the first version's totals. For a fault in the rule document, the variant compares the source-side
  totals read with the faulted document's units against the same totals read with the correct document's units
  (count, approved, guaranteed and charged-off amounts per source, tolerance US$1, the first version's). The faulted
  target ties to the first of these within the tolerance (the first version's totals did not fire on any rule fault),
  so a difference there is what the target would show against the source's own units.
- Inputs: the patches stored in protocol-r1.json and results/fresh-r1.json, and the raw tables in the work database
  that `tools/run_study.py prepare` builds, opened read-only. The first version's tools are imported, not changed.
- Expectation: the three unit faults that touch a summed amount (the mortgage loan amount documented in dollars, the
  504 approved amount and the mortgage loan amount taken as 100 times the documented unit) now fire, and no other.
  So 9 of 19 chosen and 19 of 40 random. The applicant-income unit fault does not, since totals do not sum income.

## Part B: bounds on the quick checks

- From the stored per-fault flags: how many faults the target rules alone caught (no help from totals or the code
  census), and the quick checks with the rules removed. That second figure is the lower bound if every failure on
  the first run is accepted as an exception, so a fault present from the first run never raises a rule.
- Expectation: the rules alone caught 8 of the 25 random faults the quick checks caught; the lower bound is 17 of 40
  random (the code census caught none of them) and at least 8 of 19 chosen.

## Part C: the test, at one confidence level

- One-sided 95% throughout. The exact (Clopper-Pearson) one-sided upper bound on the quick checks' charge-off miss
  share for 1 of 15. Expected about 28%.
- For the zero-miss test of 29 faults: the chance it passes if the true miss share is 1 in 15, and if it is 10%.
  Expected about 13% and 5%, so it would most likely end without a verdict.
- The smallest number of charge-off-moving faults for which, at a true miss share of 1 in 15, the one-sided 95%
  upper bound falls under 10% with at least 80% chance. Expected several hundred (about 450 by a normal approximation).

## Part D: how much of the rebuild's catch the money needs

- The smallest share of the code faults it caught here that the rebuild must catch to pay for itself, at the base
  cost per escaped fault, 10 faults a conversion and the base, low and high rebuild days. Expected about 9% at the
  base (6% to 15% over 10 to 25 days).

No pass bars: Part A is a rescoring, and Parts B to D are bookkeeping and sizing.

Code: tools/change3.py. Output: results/change3-r3.json.
