docs: B-32 and verification name the kernel's deductible rounding

B-32's CHOICE now says the category rounding is
`kernel::deductible_amount`, and its Enforced/Checked lines name the two
Kani harnesses and the bridge property. docs/verification.md adds law 39
(the exact sum, rounded once to the cent, never share by share), its
harnesses, the bridge, and the harness table row and the new prove /
prove-slow counts. It records why this law has no Lean model: it is a
report figure's arithmetic, like `discount_max` and `unrecovered_cost`,
not a `Ledger` command or a law about posted entries; the model's Books
has no tax categories, and the arithmetic it would restate is the kernel
function's own definition.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
This commit is contained in:
swaitsandDeepSeek V4.1 Flash committed 2026-11-08 05:44:59 -07:00
1 parent 9603eadfde
commit be98b99abb
2 files changed
+41 -7

No files matched your search

+7 -3
View File
@@ -2248,7 +2248,8 @@ included, and an account's header flag never changes).
summary is the exact sum of each of its accounts' shares (book ×
deductible percent ÷ 100), rounded once to the cent, half away from
zero, following B-21's "round off only the total"; the books stay
exact (R-2).
exact (R-2). The arithmetic is `kernel::deductible_amount`, so Kani
proves the one rounding and the bridge carries it to `Decimal`.
- Every account a tool can require has a category that fits it on every
return: the gain or loss account of a disposal (`form_4797_gain_loss`,
Form 4797), tax-exempt income (`tax_exempt_income`, Schedule K), and
@@ -2259,7 +2260,8 @@ included, and an account's header flag never changes).
and in no total, on every return.
**Enforced:** `tax::needs_category`, `account_needs_category`,
`uncategorized_accounts`, `CATEGORIES`; `Ledger::check_tax_category_required`,
`uncategorized_accounts`, `CATEGORIES`; `kernel::deductible_amount`
(`tax::tax_summary`'s one rounding); `Ledger::check_tax_category_required`,
`check_tax_category_kept` (commands only, never `set_account_tax`, which
replay calls); `settings::TaxCategoryPolicy`, `Settings::require_tax_category`;
`Store::add_account_with_tax`, `add_account`, `set_account_tax`
@@ -2268,7 +2270,9 @@ their first `settings.set` naming the key, B-27); `ledger-mcp` `books.add_accoun
`books.import_chart_csv`, `books.digest`; `ledger-gui` Needs attention
(Info under warn, Todo under refuse). **Checked:** `ledger-core`
`tests/tax.rs` (the rounding: `a_category_rounds_its_deductible_amount_once_not_per_account`,
`a_category_rounds_once_across_different_percents`); `ledger-store` `tests/store.rs`
`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`
(`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`);
+34 -4
View File
@@ -22,8 +22,9 @@ lives in one place, `crates/ledger-core/src/kernel.rs`. Its functions
are small, pure, and generic over an `Amount` trait with *checked*
operations. The engine calls them on `Decimal`: `JournalEntry::validate`,
`movements`, `reverse_entry`, `account_balance`, `account_movement`,
period closing, `periods::allocate`, and the trial balance. There is no
second copy of the arithmetic for proofs to drift from.
period closing, `periods::allocate`, the trial balance, and the tax
summary's deductible amount. There is no second copy of the arithmetic for
proofs to drift from.
Kani compiles the same functions at `i64` (exact integer money in the
smallest unit; the four proration charge harnesses at `i32`) and
@@ -630,6 +631,33 @@ new command, so a new Lean step, and no kernel function.
a period with an open draft can't close, discarded it can, and
every balance and id is as it was).
### A tax category's deductible amount (B-32, D-67)
39. **A category's deductible amount is its accounts' exact shares added
and rounded once**, to the cent, half away from zero: round(Σ bookᵢ ×
percentᵢ ÷ 100), never Σ round(bookᵢ × percentᵢ ÷ 100); within half a
cent of the exact sum, never the opposite sign, and None (never a
panic) when a product or the sum overflows. `tax::tax_summary` calls
it; the book amounts stay exact.
- Kani `deductible_amount_rounds_once` (up to three accounts, books to
2^20 cents, any percent 0 to 100; covers reach a half-cent tie, a
negative sum and a category where per-account rounding differs) and
`deductible_amount_refuses_overflow` (a product past `i64`, and a
sum of two shares past it) · bridge `deductible_amount_agrees` (the
i64 cents result and the Decimal dollars result agree, and the
Decimal result is within half a cent of the exact sum) · tests
`a_category_rounds_its_deductible_amount_once_not_per_account`,
`a_category_rounds_once_across_different_percents`, and the golden
`golden_tax_summary_form_1065`.
- 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`.
## What the proofs found
The engine already had 190+ tests, property tests, mutation testing,
@@ -786,8 +814,8 @@ Lean carrying any weights.
```sh
mise install # once: Kani, Lean, and the rest, pinned in mise.toml
just prove # 51 Kani harnesses and Lean
just prove-slow # the other 9: the justfile's kani_slow
just prove # 53 Kani harnesses and Lean
just prove-slow # the other 10: the justfile's kani_slow
just prove-all # both
```
@@ -897,6 +925,8 @@ each harness's whole run, its compile of about 50 s included):
| `bounds_check_matches_definition` | 34 | prove | (not in the 2026-10-22 run; P4b S1, 2026-10-24) |
| `bounds_kept_is_the_definition_on_books_in_bounds` | 34 | prove | (as above) |
| `settle_is_exact` | 36 | prove | 1 |
| `deductible_amount_rounds_once` | 39 | prove-slow | 992 (2026-11-08) |
| `deductible_amount_refuses_overflow` | 39 | prove | 0 |
| `kani_symbolic_copy_canary` | (the checker: "Trusting the checker") | prove | 3 |