From aa1331c8bd6cee95223908911d44fa7c8dbbbd9f Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Sun, 8 Nov 2026 08:14:49 -0700 Subject: [PATCH] docs: law 39 names its Lean theorems Law 39 said no Lean theorem was needed because the Books model has no tax categories. That reasoning was wrong: the law is pure kernel arithmetic, like Prorate's roundUnit laws, and needs no Books model. verify/lean/Wanderbooks/Deductible.lean now proves it at any size. verification.md law 39 lists the Lean theorems in the usual format and states the split plainly: Lean proves the law on integers over a common denominator (one rounding, Prorate.roundUnit on the magnitude, signed after); Kani proves the code on i64; the bridge and exact-reference properties carry it to Decimal; overflow stays outside the model. rules.md B-32's Checked line and plan/STATUS.md name the Lean file. Co-Authored-By: Claude Sonnet 5.5 --- docs/spec/rules.md | 5 ++++- docs/verification.md | 39 +++++++++++++++++++++++++++++++-------- plan/STATUS.md | 4 ++-- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/docs/spec/rules.md b/docs/spec/rules.md index d8be4b15..4afaf457 100644 --- a/docs/spec/rules.md +++ b/docs/spec/rules.md @@ -2272,7 +2272,10 @@ their first `settings.set` naming the key, B-27); `ledger-mcp` `books.add_accoun `tests/tax.rs` (the rounding: `a_category_rounds_its_deductible_amount_once_not_per_account`, `a_category_rounds_once_across_different_percents`); Kani `deductible_amount_rounds_once`, `deductible_amount_refuses_overflow`; -bridge `deductible_amount_agrees`; `ledger-store` `tests/store.rs` +bridge `deductible_amount_agrees`; Lean `verify/lean/Wanderbooks/Deductible.lean` +(`Deductible.near`, `tie_away_pos`, `tie_away_neg`, `sign`, `neg`, `of_sum`, +`per_account_differs`, `scale_books`, `scale_percents`: the one rounding, at any +number of accounts and any sizes); `ledger-store` `tests/store.rs` (`prop_tax_policy_refuses_exactly`, `a_journaled_clear_replays_under_refuse`); `ledger-cli` `tests/spec_tax_policy.rs`; `ledger-gui` `tests/view_model.rs` (`needs_attention_flags_every_uncategorized_pl_account_defect_8`); diff --git a/docs/verification.md b/docs/verification.md index 72dd68a9..35d9eb74 100644 --- a/docs/verification.md +++ b/docs/verification.md @@ -679,14 +679,37 @@ new command, so a new Lean step, and no kernel function. the same function; the bridge properties above carry it to Decimal, the exact-reference one over the decimal shapes Kani's integer model does not have. - - No Lean model: this is arithmetic on a report figure, like - `discount_max` (law 33) and `unrecovered_cost` (law 32), not a - `Ledger` command or a law about posted entries. The model's `Books` - has no tax categories; adding them would model presentation (a - category is a label on an account, and the summary is read from the - P&L), not a change to the books, and the law it would restate is the - kernel function's own definition. Kani proves that function, and the - bridge carries it to `Decimal`. + - Lean `Deductible.near`, `Deductible.tie_away_pos`, + `Deductible.tie_away_neg`, `Deductible.sign`, `Deductible.neg`, + `Deductible.of_sum`, `Deductible.of_perm`, `Deductible.append`, + `Deductible.split_percent`, `Deductible.per_account_differs` (with + `_mixed` and `Deductible.tie_example`, the spec's three scenarios by + `decide`), `Deductible.scale_books`, `Deductible.scale_percents` + (and their rounding lemmas `Deductible.roundHA_*`, all in + `Audit.lean`), for any number of accounts and any sizes: the result + is within half a cent of the exact sum (`|2(D·c − N)| ≤ D`); at + exactly k + ½ cents it is k + 1 (and −(k + 1)), the cent farther + from zero; it never has the sum's opposite sign and is 0 for a zero + sum; negating every book negates it; it depends on the shares only + through their exact sum (reordering, regrouping, or splitting an + account's percent changes nothing), while the sum of per-account + roundings does differ (1.01 + 1.01 at 50%: 1.01 once, 1.02 by + account); and writing books or percents at a finer common + denominator (more decimal places) changes nothing. + - What the model is, and what it is not: no `Books` model is needed, + the way `Prorate.lean` needs none for the proration kernel. A share + is a pair of integers over one positive common denominator `D` + (`10^(p+s)` for books at p and percents at s decimal places, the + mantissas the `Decimal` path of `checked_div_round_cent` works on); + the category in cents is `N / D`, `N = Σ bookᵢ × percentᵢ` (the + `÷ 100` and the dollars-to-cents `× 100` cancel); one rounding, + `roundHA`, is `Prorate.roundUnit` (reused, unit one) on the magnitude, + signed after, as the kernel's `a_mag`/`b_mag`/`negative` do. Lean + proves the **law** of that arithmetic at any size; it does not prove + the Rust. Kani proves the code on `i64` (bounded, above); the bridge + and exact-reference properties carry it to `Decimal`; overflow + (`None`) is outside the model, Kani's `deductible_amount_refuses_overflow` + and the tests cover it. ## What the proofs found diff --git a/plan/STATUS.md b/plan/STATUS.md index 54358454..664e7fc2 100644 --- a/plan/STATUS.md +++ b/plan/STATUS.md @@ -29,8 +29,8 @@ both were fixed before merging. - **2026-11-08:** the deductible share is `kernel::deductible_amount` with Kani harnesses (`deductible_amount_rounds_once`, in `kani_slow`, ~17 min; `deductible_amount_refuses_overflow`), bridge and exact-reference - properties, and docs/verification.md law 39 (no Lean theorem: report - arithmetic, reasoning there). `just prove` green; the slow harness + properties, and docs/verification.md law 39 (Lean `Deductible.lean`: the + law at any size, no Books model needed). `just prove` green; the slow harness verified. Review caught a false overflow on huge Decimal results, fixed. **Left:** as before: P12 step 2 (the owner's overnight run, not started);