Files
wanderbooks/verify/lean/Wanderbooks.lean
T
swaitsandClaude Sonnet 5.5 2d345d02bc feat(lean): the deductible share rounds once, at any size
Law 39 (kernel::deductible_amount, B-32, D-67) was proved by Kani only
for up to three accounts and books to 2^20 cents. Like the proration
kernel, its arithmetic needs no Books model: Deductible.lean states it
on integers, for any number of accounts and any sizes.

Model: a share is a pair of integer numerators over one positive common
denominator D (10^(p+s) for books at p places and percents at s). The
category in cents is N / D, N = sum of book x percent; the /100 of the
percent and the x100 of dollars-to-cents cancel, so there is one
rounding: roundHA N D, the magnitude rounded by Prorate.roundUnit (unit
one, reused, not a second rounding function) and signed after, which is
what checked_div_round_cent does with a_mag, b_mag and `negative`.

Theorems (all on the exact sum, none by cases on the list):
- near: |2(D c - N)| <= D, any size
- tie_away_pos / tie_away_neg: at exactly k + 1/2 cents the result is
  k + 1 (resp. -(k + 1)), the cent farther from zero
- sign: never the opposite sign; zero when the sum is zero
- neg: negating every book negates the result (odd symmetry)
- of_sum, of_perm, append, split_percent: the result depends on the
  shares only through their exact sum
- per_account_differs (+ _mixed, tie_example): the kernel's three
  scenarios by decide: 1.01+1.01 at 50% is 1.01 once, 1.02 by account;
  1.05 at 50% and 30% is 0.84 vs 0.85; 333.33 at 50% is 166.67
- scale_books / scale_percents: a finer common denominator (books or
  percents carrying more decimal places) changes nothing

The Lean proves the law, not the Rust: Kani proves the code on i64, the
bridge and exact-reference properties carry it to Decimal. Overflow
(None) is outside the model. 20 headline theorems added to Audit.lean,
standard axioms only; no sorry.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-08 08:12:24 -07:00

11 lines
275 B
Lean4

import Wanderbooks.Basic
import Wanderbooks.Entry
import Wanderbooks.Statements
import Wanderbooks.Closing
import Wanderbooks.Ledger
import Wanderbooks.Apportion
import Wanderbooks.Parties
import Wanderbooks.Prorate
import Wanderbooks.Deductible
import Wanderbooks.Documents