Files
wanderbooks/verify/lean/Audit.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

127 lines
4.6 KiB
Lean4

import Wanderbooks
/-! `just prove` runs this file: each headline theorem's axioms are printed,
and must be only Lean's standard three (`propext`, `Quot.sound`,
`Classical.choice`) or fewer. No `sorryAx`, nothing assumed. -/
open Wanderbooks
#print axioms Accepted.net_zero
#print axioms sum_movements
#print axioms movement_with_reversal
#print axioms accepted_reversal_iff
#print axioms accounting_equation
#print axioms balance_after_line
#print axioms trial_balance_iff
#print axioms closingEntry_net
#print axioms closingEntry_zeroes
#print axioms closingEntry_accepted
#print axioms net_closings_is_net_income
#print axioms plugLast_total
#print axioms plugLast_keeps
#print axioms runPart_telescopes
#print axioms closePart_total
#print axioms trueUp_total
#print axioms trueUp_running
#print axioms closePart_eq_trueUp
#print axioms cumulative_drift
#print axioms statement_after_close
#print axioms statement_unmoved_by_close
#print axioms Reachable.inv
#print axioms Reachable.books_net_zero
#print axioms Reachable.trial_balance
#print axioms Reachable.trial_balance_through
#print axioms Reachable.accounting_equation
#print axioms Reachable.accounting_equation_through
#print axioms Steps.extends
#print axioms Steps.frozen
#print axioms close_zeroes
#print axioms close_credits_net_income
#print axioms statements_add_up
#print axioms Apportion.ranks_perm
#print axioms Apportion.apportion_sum
#print axioms Apportion.apportion_sum_of_shortfall
#print axioms Apportion.rem_pos_of_rank_lt
#print axioms Apportion.apportion_drift
#print axioms Apportion.allocW_sum
#print axioms Apportion.allocW_drift
#print axioms Apportion.allocW_cumulative_drift
#print axioms Apportion.allocW_cumulative_total
#print axioms Step.record_changes_no_figure
#print axioms Reachable.records
#print axioms net_splits_by_flow
#print axioms applyCash_conserves
#print axioms applyCash_exhausts
#print axioms applyCash_neg
#print axioms entry_flows_sum
#print axioms flows_reversal
#print axioms constructive_nets
#print axioms constructive_neg
#print axioms constructive_sections_net
#print axioms stmt_flows_sum
#print axioms stmt_flows_reversal
#print axioms cashflow_sections_sum_to_cash_change
#print axioms secNet_cash_is_movement
#print axioms operating_reconciliation_ties
#print axioms operating_reconciliation_ties_all
#print axioms cashflow_reversal_nets
#print axioms Reachable.cashflow_foots
#print axioms Reachable.cashflow_is_change_in_cash
#print axioms reverseTarget_involutive
#print axioms capitalTarget_odd
#print axioms partyTarget_odd
#print axioms sumOver_movement_reversal
#print axioms Prorate.cum_mono
#print axioms Prorate.cum_le
#print axioms Prorate.cum_full
#print axioms Prorate.parts_telescope
#print axioms Prorate.prorate_total
#print axioms Prorate.prorate_nonneg
#print axioms Prorate.part_within_a_unit
#print axioms Prorate.roundUnit_near
#print axioms Prorate.roundUnit_scale
#print axioms Prorate.cum_near
#print axioms Prorate.cum_dvd
#print axioms Prorate.part_near
#print axioms Prorate.chargeMid_eq_cum
#print axioms Prorate.chargeLast_eq_cum
#print axioms Prorate.chargeLast_start
#print axioms Prorate.chargeLast_mono
#print axioms Prorate.kernel_parts_total
#print axioms Prorate.kernel_parts_nonneg
#print axioms Documents.control_agrees
#print axioms Documents.control_agrees_through
#print axioms Documents.Step.document_unattached
#print axioms Documents.settle_posts_a_document_step
#print axioms Documents.settle_unattached
#print axioms Documents.Step.reverse_moves
#print axioms Documents.reverse_twice
#print axioms Documents.Step.markSent_changes_no_figure
#print axioms Documents.Reachable.unattached_zero
#print axioms Documents.Reachable.control_is_documents
#print axioms Documents.Step.writeOff_unattached
#print axioms Documents.writeOff_within_bounds
#print axioms Step.discard_keeps_books
#print axioms Step.discard_drafts
#print axioms Step.discard_unblocks_close
#print axioms Deductible.roundHA_near
#print axioms Deductible.roundHA_tie_pos
#print axioms Deductible.roundHA_tie_neg
#print axioms Deductible.roundHA_neg
#print axioms Deductible.roundHA_sign
#print axioms Deductible.roundHA_scale
#print axioms Deductible.near
#print axioms Deductible.tie_away_pos
#print axioms Deductible.tie_away_neg
#print axioms Deductible.sign
#print axioms Deductible.neg
#print axioms Deductible.of_sum
#print axioms Deductible.of_perm
#print axioms Deductible.append
#print axioms Deductible.split_percent
#print axioms Deductible.per_account_differs
#print axioms Deductible.per_account_differs_mixed
#print axioms Deductible.tie_example
#print axioms Deductible.scale_books
#print axioms Deductible.scale_percents