Commit Graph
584 Commits
Author SHA1 Message Date
swaitsandClaude 5777787b69 test(core): exact Decimal arithmetic refuses nothing it could hold
The independent review of K-U10 found the bridge properties proved one
direction only. They compared the kernel with an expectation built from
rust_decimal's own result, so they showed a figure returned is exact, and
could not show that an exact figure is never refused. Each of add,
subtract, multiply and exact division is now also Some exactly when the
rational result is a Decimal (a mantissa under 2^96 at a scale of 0 to
28), decided from the rational alone. All hold: no change to the kernel.

Also from the review:
- the FX product rounded once is checked at steps of every scale, not 0 to
  3 places, and a None is accepted only at the two bounds the code states;
- one refusal the docs did not state is now stated and pinned: a product
  that is not exact, at a step of 27 or 28 places, is None though its
  rounded figure can be a Decimal (the one rounding needs two places
  below the step and Decimal ends at 28). No currency's step is near it;
- running totals are checked over thousands of lines, and the first
  refusal is pinned (line 7,923 of the largest ten-place amount, where
  rust_decimal drops a place and rounds);
- three stale sentences: percent_of's product is exact or refused since
  this unit (only its division rounds), the header of allocate.rs, and
  the table in docs/proofs/k-u10.md, which now records the review.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 22:18:54 -07:00
swaitsandClaude e46fa4fc6e fix(core): an exact division refuses a rounded quotient
`Amount::checked_div_exact` promises the exact quotient or nothing: "never
a rounded share". On Decimal it checked the quotient by multiplying back,
but with rust_decimal's own product, which rounds. A rounded quotient
times the divisor rounds back to the dividend (10 / 3 is 3.333...3 at 28
places, and 3.333...3 x 3 is held as 10), so a third, a seventh and a
ninth all passed as exact.

No figure in the books was wrong: the one caller divides a basis-point
product by 10,000, which is always exact. The contract was broken for
the next caller. The check now multiplies back exactly (K-U10's
`exact_mul`), so a rounded quotient is refused.

The bridge gets the property (a quotient returned, times the divisor, is
the dividend as a rational) and the named cases. The FX rounding
property also takes steps of 5 and 25 units, whose half steps sit one
place below the step: the wide product keeps that digit real.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 21:05:43 -07:00
swaitsandClaude Sonnet 5.5 786e503858 test(core): the Decimal edges are refused, not rounded
The bridge compares impl Amount for Decimal's add, subtract and multiply
with rust_decimal's own result and with an independent BigRational
reference over every mantissa to 2^96 - 1 and every scale 0 to 28: a Some
is the exact result; an exact old result is returned unchanged, compared
as strings; a rounded one is None; an overflow stays None. Over the posted
range (line cap, ten places, any raw scale) sums, differences, running
totals and FX products are identical to the old to the character, and the
FX product is checked rounded once from the exact one in all four
rounding modes. Unit tests check the private 256-bit helpers against
num_bigint.

The pinned findings now assert the law holding:
finding_decimal_add_rounds_dust_at_the_edge and
finding_decimal_add_rounds_scale_near_the_top become
a_sum_past_exact_arithmetic_is_refused,
the_mantissa_edge_is_outside_the_precondition_and_pinned becomes
the_mantissa_edge_books_the_exact_products_cent (10500000099.89, which the
reference gives; the old 99.90 was a double rounding). Expectations that
moved are all outside what a posted line carries: 599 parts of 1.3e26 at
the cent sum past 96 bits (schedule::the_edges), the 26-place product now
rounds once to 0.00, and the replaced-chain comparison refuses a step
rust_decimal rounded. No golden changed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 20:46:19 -07:00
swaitsandClaude Sonnet 5.5 38da08b2c2 fix(core): Decimal sums and products are exact or refused
rust_decimal's checked_add and checked_mul return None only when the
integer part overflows. When the exact result needs more than 96 bits of
mantissa, or a scale past 28, they round it and return Some: MAX + 0.4 is
Some(MAX) (K-U4), 0.01 + 792281625142643375935439503.35 is ...503.4
(K-U8), 1050000010.0000000001 x 9.9999999999 is 10500000099.895 where the
exact product is 10500000099.89499999999999999999 (K-U1), and
123456789.0123456789 squared loses its last digits (K-U3). The kernel's
contract is exact or None, and BS-ledger-1 says a product the arithmetic
cannot hold MUST be refused.

impl Amount for Decimal now runs rust_decimal's operation and checks, in
256-bit integers (kernel/decimal_exact.rs), that the figure equals the
exact sum or product as a rational; otherwise None. It builds no rounded
figure of its own, and an exact result is returned as rust_decimal gave
it, scale and all, so nothing exact moves. Comparing values is complete
where the K-U10 row's "result scale fell below the operands'" test is not:
100 x 0.3333333333333333333333333333 is exact with a full-scale mantissa
past 96 bits (trailing zeros), and percent_of computes it for every
ratio. checked_sub is rust_decimal's subtraction under the same check
(the trait default gave -0 for 0 - 0). Money::checked_add and
checked_sub go through Amount; sum_exact*, add_exact and sub_exact already
did.

Two products could not simply become exact, and the suite found both:
- Shares multiply a cent amount by a many-place percent
  (33.333333333333333333333333333, 27 places) and then divide, which
  rounds anyway (spec_cash_flow's government payment). They use the new
  Amount::checked_mul_rounded, rust_decimal's own product, so every share
  is the figure it always was.
- A foreign amount at a rate (fx_booked) rounds once, from the exact
  product: Amount::checked_mul_round_to_step holds it in 256 bits, cuts it
  only as far as Decimal needs with a sticky digit for what was cut, and
  rounds with round_step. The one posted-range figure that moves is the
  one the old double rounding got wrong: 1050000010.0000000001 x
  9.9999999999 books 10500000099.89, the exact product's cent, not
  10500000099.90.

checked_div and checked_div_exact are unchanged. Inherent
Decimal::checked_* calls outside the kernel are listed in
docs/proofs/k-u10.md and not converted.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 20:46:19 -07:00
swaitsandClaude Opus 5.5 4da1c5b30f fix(proofs): K-U7's overflow harness takes i64::MIN, with the native subtraction
K-U7 and K-U8 found the same thing from two sides: the integer model's
subtraction negated the subtrahend first, so x - i64::MIN was refused
where it fits. K-U7 assumed the minimum away and asserted the refusal;
K-U8 made i64 and i32 subtract natively. With both merged the
assumption goes: the harness ranges over the whole i64 domain, minimum
included, and asserts -1 - i64::MIN = i64::MAX.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 13:52:41 -07:00
swaitsandClaude Opus 5.5 8aa0ed985d merge: the control, aging and reconciliation identities in the kernel (K-U8; reviewed, fixes applied)
Three identities the books rest on are kernel functions now, proved
rather than only summed: an aging's five buckets add to the document
total (aging_total), a control account's difference from its documents
and unattached lines (control_difference), and the K-1 reconciliation's
total (reconciliation_total). Kani proves each, None exactly on
overflow; bridge properties check them against an exact integer
reference and the replaced chains on 20,000 cases, scale included; law
46 in bookspec's Lean. The CPA package's aging now refuses a total past
exact arithmetic instead of panicking. The harnesses found the integer
model's subtraction negating first, so x - MIN was refused where it fits;
i64 and i32 now use the native subtraction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 13:52:10 -07:00
swaitsandClaude Opus 5.5 a37612d07c merge: payroll's net pay in the kernel (K-U7; reviewed, fixes applied)
Net pay is gross less the withholdings and deductions, now one kernel
fold (net_pay) with the plan's totals through the kernel's checked
totals; payroll_remit_plan refuses a total past exact arithmetic instead
of panicking. Proved: Kani (net pay equals gross less the deductions,
None exactly when a running difference overflows, the plan balances for
an employee), bridge properties against an exact integer reference at
every prefix, and law 45 in bookspec's Lean for any number of employees.
No figure moves; every golden unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 13:52:02 -07:00
swaitsandClaude Sonnet 5.5 b31824b2ca test(core): K-U7 review: None-iff-overflow proof, covers that can fail, a sharper bridge
- Kani net_pay_none_iff_a_prefix_overflows proves what the doc claimed:
  None exactly when some running difference leaves the i64 range, else
  the exact i128 result. It found that i64's Amount::checked_sub negates
  first, so a deduction of i64::MIN (no negation) is refused where the
  difference would fit (-1 - i64::MIN). Conservative, and Decimal's range
  is symmetric, so the engine is unaffected; the harness assumes it away
  and asserts the refusal at the fixed case; the kernel doc says so.
- payroll_plan_balances: covers that the assumes did not already force
  (net of one unit, payables holding employer shares alone, federal or
  state posted); the harness doc says it rebuilds the plan on i64 rather
  than calling payroll_entry_plan, and what that does and does not prove.
- Docs name the Lean theorems that carry any number of employees
  (payroll_run_net_eq, payroll_run_plan_balances) where they had
  claimed it.
- Bridge: compare to_string as well as value (Decimal equality ignores
  scale); a strategy near Decimal::MAX/MIN where the reference also
  returns None, which required the reference to check every running
  difference as the kernel's fold does, not only the last.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 13:50:54 -07:00
swaitsandClaude Sonnet 5.5 46dccd5d76 fix(core): payroll_remit_plan refuses past exact arithmetic instead of panicking
The remittance plan totalled the payables with a raw `total +=`, which
panics on Decimal overflow, on a pub fn returning a bare plan. Its
callers refused first through sum_exact_of, but that was an unenforced
precondition (BS-entry-4: every derived figure is checked arithmetic).
It now returns Result<_, LedgerError>, totalling through
kernel::total_of and refusing TooLargeToCompute; Ledger and the store
propagate it and keep their pre-checks. A test shows payables past the
range, up and down, are refused, not a panic.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 13:50:54 -07:00
swaitsandClaude Sonnet 5.5 80c93179b5 test(core): bound the rounded figures against the exact value
A rounded step can later return to scale 2, so the bound is four whole
units in cents, not one unit at the final scale.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 13:17:12 -07:00
swaitsandClaude Sonnet 5.5 c8cfd32723 test(core): the control harnesses prove None only on overflow; i32/i64 checked_sub is native
The tightened harnesses assert Some whenever every i128 prefix fits in i64.
That found the default Amount::checked_sub refusing x - MIN on i32/i64 where
the difference fits; both now use the native subtraction. The bridge pins
aging_total(0,0,0,0,MAX) to Some(MAX), bounds the rounded figures to one
unit of the exact value, and covers scales 0..=28. Two smaller worksheet
harnesses (nine terms on i32, seven on i32) found no verdict in 400 s and
300 s: recorded, no harness.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 12:53:09 -07:00
swaitsandClaude Opus 5.5 652f9da877 build: pin bookspec at ed6e379, payouts, tags, prepaid contributions
portable-macos / portable (macos-latest) (push) Canceled after 0s
portable-windows / portable (windows-latest) (push) Canceled after 0s
two-user / two-user (push) Canceled after 0s
check / check (push) Canceled after 0s
bookspec main now carries X-H1e2: the last examples slice, two rules left
without one (BS-asset-9, BS-partner-16, which the engine does not do).
112 of 139 examples run and pass, the other 27 are for options
wanderbooks did not pick.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 12:51:31 -07:00
swaitsandClaude Sonnet 5.5 632a1a543c fix(package): the agings refuse a total past exact arithmetic instead of panicking
The CSV total and the statement's column totals used raw Decimal += and a
five-term sum, which panic at the edge. They now go through
kernel::total_of and kernel::aging_total and return TooLargeToCompute as an
error (BS-entry-4). Only the error path changes; no golden moves.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 12:39:11 -07:00
swaitsandClaude Sonnet 5.5 b4b233e486 test(core): Kani and bridge for the kernel control identities
Kani proves, on arbitrary i64s with an exact i128 specification, that
aging_total is the sum of its five buckets, control_difference is
balance - documents - unattached and vanishes exactly when the account
agrees with its subledger, and reconciliation_total is beginning + gain
+ without - distributed; in-range figures always total (law 45). The
book/tax worksheet statement did not finish in the solver (500 s at nine
terms, 110 s at seven), so Lean's reconciliation_identity carries it and
a bridge property checks it on i64 and Decimal; written down in
docs/proofs/k-u8.md rather than weakened.

The bridge compares i64 against Decimal and Decimal against an
independent exact i128 reference over the whole mantissa range, pins the
Decimal edges (each overflowing step is None, never a panic), and checks
the kernel against the three hand-written chains it replaced, as strings
including scale, on 20,000 random Decimals: identical. The reference
also shows rust_decimal rounds an add to a coarser scale wherever the
exact result needs more than 96 bits at the operands' scale (K-U4's
finding, wider than the MAX edge); pinned as a canary for K-U10.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 12:13:32 -07:00
swaitsandClaude Sonnet 5.5 a87e2d0a7a test(core): the adapter runs a platform's payout, an asset's tag and the K-1's tax-basis note through the engine
The bookspec schema gained a `payout` event, a `tag_asset` event, an
`asset_tag` query and a note on the tax-basis property line (BS-revenue-1,
BS-asset-3, BS-partner-17). The adapter runs each through the engine and
rebuilds none of it: a payout goes through `payouts::payout_plan`, which
refuses unless gross less fee is the deposit to the cent, and its plan's lines
post as one entry; a tag goes through `Store::set_asset_tag`, which refuses a
tag of a wrong form and one another asset holds or ever held; the tax-basis
line's note is `Note::PrepaidAtBook` read off the worksheet. The engine's
InvalidPayout, InvalidAssetTag and AssetTagTaken are worded as the examples
word them.

Thirteen examples were added and every one the engine's picks reach passes:
five are for options wanderbooks did not pick (no-tags, every-prepaid-is-cash,
every-prepaid-is-property, left-open, whole-payment-to-each) and are skipped,
so the skipped count is 22 + 5 = 27 and 112 of 139 run. A prepaid contract
credited straight to capital is property (1,500.00 each) and a service paid
through Due to Members is cash (1,000.00 each); the contract enters the tax
capital at its book amount with the note; a 1,000.00 check naming Dana Studio
at 600.00 counts 600.00 toward Dana's 1099.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 12:05:15 -07:00
swaitsandClaude Sonnet 5.5 0df463b703 refactor(core): the control, aging and reconciliation identities in the kernel
Three identities were still hand-written chains at their call sites:
an aging row's five buckets summing to what is owed (BS-arap-1), the
control check's difference, balance less documents less unattached
lines (BS-arap-2), and the K-1 reconciliation total, beginning plus
built-in gain plus property without a basis less property distributed
(BS-partner-4). They move to kernel::aging_total, control_difference
and reconciliation_total, generic over Amount, returning None on
overflow, so each is a named law with a harness and a Lean theorem
rather than a sum.

Behaviour is identical: the same checked steps in the same order, so
figures, scales and TooLargeToCompute refusals are unchanged; every
golden passes untouched. The next commit's bridge compares the old
chains and the kernel as strings on 20,000 random Decimals of any scale.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 11:48:10 -07:00
swaits 90d34585fd Merge branch 'main' into t3/payroll-net-pay-kernel 2026-11-09 11:44:50 -07:00
swaitsandClaude Opus 5.5 e45c62348a build: pin bookspec at 6d85d8b, schedules that take the pick and the books' own facts
check / check (push) Canceled after 0s
portable-macos / portable (macos-latest) (push) Canceled after 0s
portable-windows / portable (windows-latest) (push) Canceled after 0s
two-user / two-user (push) Canceled after 0s
bookspec main now carries X-H1e1: a schedule may leave its method to the
engine, yen schedules, the IIF export's choices, settings, role
assignments and the tax summary in the schema; eight rules remain
without an example. Lean audits standard axioms only; 104 of 126
examples run and pass, the other 22 are for options wanderbooks did not
pick.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 11:23:56 -07:00
swaitsandMuse Wonder 1.0 2295d15be8 test(core): the payroll plan harness carries one employee
The two-employee payroll_plan_balances timed out in CBMC: over 80
minutes at full CPU, killed with no result (sixteen symbolic figures
into eight totals and check_lines). The earlier note's 297.6s figure
came from a misattributed background result and is withdrawn here;
the harness as committed had never verified.

One employee reaches every plan line, both FICA shares on both sides,
net_pay and check_lines, and verifies in 62.0s (65.6s wall). Lean's
payroll_plan_balances carries the plan at its totals for any number
of employees, since a run's totals are sums of the same eight
figures. The bound and why are written in the harness and the note.

Co-Authored-By: Muse Wonder 1.0
2026-11-09 11:22:13 -07:00
swaitsandClaude Opus 5.5 1add7df419 merge: the adapter runs schedules that take the pick, yen schedules, the IIF's options and the books' own facts (X-H1e1's wanderbooks half; reviewed, re-checked)
Wanderbooks passes every bookspec example for its picks: 104 run, 104
passed, 22 for options it did not pick. A schedule plan is answered as
the engine holds it (a yen month 333, a dollar month 33.33); the IIF
line ending is cr-lf only when every line ends so; bookspec's setting
keys map to the engine's in one place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 11:18:25 -07:00
swaitsandClaude Sonnet 5.5 e49b6d3427 test(core): the adapter maps bookspec's setting keys to the engine's
Bookspec now closes its setting keys (fiscal_year_start); the engine's key is
company.fiscal_year_start. The event and the query both go through one map
(BS-ledger-9).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 11:17:14 -07:00
swaitsandClaude Sonnet 5.5 bab7ac72ca test(core): the adapter's line-ending answer needs every break to be CR LF
contains(CR LF) answered cr-lf for a file mixing CR LF and bare LF. Now the
count of LF must equal the count of CR LF for cr-lf, with none CR LF for lf,
and a mix is mixed. The claims say the engine has no host notion, so
host_line_ending is unused (BS-format-4).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 11:17:14 -07:00
swaitsandDeepSeek V4.1 Flash 688ab951d3 test(core): the adapter runs schedules that take the pick, settings, role accounts, tax summaries and an export's line ending
A schedule may now leave its convention to the engine, so an example can
show BS-prepaid-2's pick: the adapter registers such a schedule by the
day, wanderbooks' method (D-11, D-37), and the equal-months examples are
skipped as the runner skips another engine's option. The yen examples run
through `Store::register_schedule`, whose `schedule_minor_unit` feature
rounds a monthly-even month to the currency's minor unit (D-72, K-U5);
`answer_schedule_plan` now prints each month as the plan holds it, so a
yen month is 333 and not 333.00.

The new events and queries go through the engine's own commands, never a
reimplementation: `set_setting` is `Store::change_settings` with its
`Source` (who decided and when), the setting query reads
`Ledger::settings`, the role account query reads `Ledger::role_account`,
the tax summary is `tax::tax_summary`'s once-rounded lines, and the line
ending is the `ledger_import` file's own CR LF. The BS-format-9 example
uses an entry posted as an earlier version wrote it, so its memo is the
example's and no document's wording stands between the file and the
check. The skip count moves from 16 to 22, the six new unpicked-option
examples (the cent rule, the file's place, one fiscal year, closes
written, the platform line ending and per-account rounding).

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 10:49:44 -07:00
swaitsandMuse Wonder 1.0 fbe7eb7125 test(core): Kani and bridge for the kernel payroll
Three Kani harnesses on i64, fixed arrays (five deductions, a
two-employee plan of eight lines): net_pay_is_gross_less_deductions
(19.5s verification), net_pay_nonnegative_when (7.0s) and
payroll_plan_balances through check_lines (297.6s), each with covers.
The bridge checks i64 against Decimal and Decimal against an
independent exact i128 reference, with the edges (Decimal::MAX/MIN,
mid-fold overflow) giving None, never a panic.

All three prove law 45 (bookspec, BS-entry-1/BS-entry-3/BS-entry-4).
The traceability gate passes against the k-u7 bookspec branch: 63
kernel functions, 48 fully backed, 45 law rows. docs/proofs/k-u7.md
is the unit's record.

Co-Authored-By: Muse Wonder 1.0
2026-11-09 10:37:16 -07:00
swaitsandMuse Wonder 1.0 e8f60532b1 refactor(core): payroll's net pay in the kernel
Net pay was a hand fold of Decimal::checked_sub in payroll.rs, and
payroll_entry_plan totalled its seven columns with local checked folds.
Both now go through the kernel: kernel::net_pay (gross less every
deduction, folded left to right, None past exact arithmetic) and
kernel::total_of/total_try for the plan's columns, the net over each
line's kernel net pay.

The fold order preserves the old behaviour exactly, including at the
edge: each running difference must be representable, so [MAX, MAX,
-MAX] from a zero gross refuses where summing first would cancel.
Figures, scale, zero-skipping and the TooLargeToCompute refusals are
unchanged; every golden and test passes as before. The rules are
BS-entry-3 (exact amounts), BS-entry-4 (every payroll figure computed
with checked arithmetic) and BS-entry-1 (the plan balances).

payroll_remit_plan's bare total and name_payroll_parties' grouped
checked_add stay: both callers refuse through sum_exact_of first, in
the same order, and a grouped accumulation has no kernel shape. See
docs/proofs/k-u7.md.

Co-Authored-By: Muse Wonder 1.0
2026-11-09 10:37:11 -07:00
swaitsandDeepSeek V4.1 Flash c49ddc0d6b test(core): no bare old rule label beside a cash-flow or party citation
BS-statement-3 and BS-partner-3 no longer open their statements with
"Rule n", so a numbered rule label in the cash-flow or party files can
only be the drifted old citation. sub_refs now refuses a bare "Rule n" /
"rule n" there, and elsewhere only on a line that cites one of those two
records. Ordinary uses of the word ("this rule holds", "the run rule
0.02") are not labels, and a label straight after a bookspec id is
already the id check's finding. Self-tests cover both scopes and the
non-label cases. The checked-reference floor rises to 515, the count
after the citations moved to positions.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 10:21:07 -07:00
swaitsandDeepSeek V4.1 Flash 409845e665 docs: the cash-flow and party citations name statements by position
bookspec unit S-C8 dropped BS-statement-3's and BS-partner-3's "Rule n"
labels: they had drifted from the statements' positions, and every
reference is now a position, "BS-statement-3 statement k". This rewrites
wanderbooks' citations from the old labels to the positions.

Method: the map was confirmed against the pinned records at b61fa50 by
reading each statement before use. BS-statement-3: Rule 1 -> statement 2,
2 -> 3, 3 -> 4, 4 -> 5; Rule 5 by the sentence's meaning (gross lines 6,
operating classes 7, governments 8, payroll 9, kinds 10, the family 6-10);
6 -> 11, 7 -> 12, 8 -> 13, 9 -> 14, 10 -> 15, 11 -> 16, 12 -> 17.
BS-partner-3: 1 -> 1, 2 -> 2, 3 -> 3-4, 4 -> 5-6, 5 -> 7, 6 -> 8, 7 -> 9,
8 -> 10, 9 -> 11. Each sentence was read against the statement it now
cites; a "rule n" meaning an IRS rule, an engine rule, or another
record's rule was left alone (odd_cent.rs's close true-up, the asset
register's note numbering, and testing.md's "run rule 0.02").

Rewritten: 44 references in src/cashflow.rs, 22 in
tests/spec_cash_flow.rs, 3 in tests/spec_reports.rs, 5 in
docs/spec/claims/statement.md (whose stale "rules 1-12" count is now
"18 statements"), 21 in the vendored ASC notes, 10 in docs/testing.md,
2 in docs/verification.md, 2 in kernel/entries.rs, and 1 in the CLI's
journey test.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 10:21:04 -07:00
swaitsandClaude Opus 5.5 01acb159f0 build: pin bookspec at b61fa50, the percentage law
check / check (push) Canceled after 0s
portable-macos / portable (macos-latest) (push) Canceled after 0s
portable-windows / portable (windows-latest) (push) Canceled after 0s
two-user / two-user (push) Canceled after 0s
bookspec main now carries law 44 (K-U6): a percentage of a positive whole
within half a step of the exact ratio, a ratio split's sides summing to
the amount. Lean audits standard axioms only; the traceability gate
finds a law for all 62 kernel functions' harnesses it checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 09:50:06 -07:00
swaitsandClaude Opus 5.5 650a89c94e merge: percentages and ratios in the kernel (K-U6; reviewed, fixes applied)
A project's contribution margin as a percent of its revenue, and a
government's part of a payment split from the company's, are now kernel
functions (percent_of, split_ratio) with Kani harnesses, bridge
properties against an exact integer reference, and law 44 in bookspec's
Lean. A review fuzzed old against new as strings: no figure moves. Fixed
in review: a split's zero rest could be -0, and the split harness proved
divisibility at a step of 1, where every number divides. The viewer's
display percentages stay as they are; its f64 chart percentage is a
money path K-U9 must make Decimal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 09:39:28 -07:00
swaitsandDeepSeek V4.1 Flash 142de09ff2 docs(core): state the ratio split's part scale
The part keeps the share's scale when the share is already a whole
multiple of the step and takes the step's otherwise, so callers that need
a fixed scale rescale (as contribution_margin_pct does for its one-place
display). Say so in `split_ratio`'s invariant list.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 09:38:13 -07:00
swaitsandDeepSeek V4.1 Flash 4f6cbefeb2 test(core): the split harness proves divisibility at step 3
The harness split with step 1, where every integer is a multiple, so its
"the rounded side is a whole multiple of the step" claim was vacuous and
the assertion absent. Step 3 makes it mean something, and the harness
asserts `part % step == 0`; the sum and the two covers are unchanged.
Record the re-run (3.1 s wall, 0.66 s verification), note that the Lean
model is total where the kernel is partial (a + b = 0), and refresh the
traceability counts from the merged bookspec branch.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 09:38:13 -07:00
swaitsandDeepSeek V4.1 Flash 803dfc5de0 fix(core): a ratio split's zero rest is +0, never -0
`split_ratio(0.00, 1, 2, 0.01, half-to-even)` handed the rest back as -0:
the generic `checked_sub` negates the subtrahend, and a zero negated
keeps its sign bit. Decimal equality hides it, but a printed "-0.00" is
not money and a sign test saw it. Map a zero rest to T::ZERO, which is
generic and always +0.

The bridge's edge test now asserts the sign (`!is_sign_negative()`) for
a zero rest and a zero percent, including a negative-zero amount, instead
of trusting equality. Its refusal test also covers a negative step for
both functions, which the kernel already refuses.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 09:38:09 -07:00
swaitsandClaude Opus 5.5 8d1d2ddeed build: pin bookspec at 22d02fe, refused input and records citing their own parts
bookspec main now carries X-H1d (refused dates, amounts, periods, roles,
exports, 1099 years and returns as examples; the role list is
BS-ledger-8's) and S-C8 (records cite their own statements by position).
Lean 188 theorems, standard axioms only; 95 of 111 examples run and
pass, the other 16 are for options wanderbooks did not pick.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 09:25:38 -07:00
swaits c9d6c8f59a Merge branch 'main' into t3/kernel-percentages-ratios 2026-11-09 09:25:35 -07:00
swaitsandDeepSeek V4.1 Flash a5c62a2412 test(core): Kani and bridge for the kernel ratios
Kani proves the kernel's percentages and ratio splits on i64: a percent is
within half a step of the exact ratio (the model's whole fixed so its
truncating division is exact: an i64 quotient loses the fraction before
the multiply, which Decimal keeps), a percent of a zero or negative whole
is None, and a 1 : 2 split's rounded part plus its exact rest is the
amount.

The bridge carries the same laws to Decimal: the i64 model and the engine
agree where the quotient is exact; percent_of and split_ratio agree with
an independent exact i128 reference (no Decimal division at the reference)
for parts, wholes, ratios and steps of every sign and scale; a split's
parts sum and its rounded side is a whole multiple on every input; and the
edges (Decimal::MAX, scale 28, a zero whole and a zero ratio) are None or
exact, never a panic.

docs/proofs/k-u6.md records the harness-to-law table, the measured times,
the bridge properties and what rounds at Decimal's edge (K-U10). The law
is bookspec law 44; the traceability gate passes against the k-u6 bookspec
branch (the pin moves when that branch is merged).

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 09:14:41 -07:00
swaitsandDeepSeek V4.1 Flash a70099daae refactor(core): percentages and ratios in the kernel
A project's contribution margin is its net as a percent of revenue: the
exact ratio times 100, rounded once to the place the page prints (one
place, half to even), and none when there is no revenue to divide by. The
same computation was hand-written in reports; it is now
kernel::percent_of, division first as the call site always did, so the
figures, the scale and the None on a non-positive revenue do not move.

The government's part of an operating payment is an amount split a : b:
the government side rounded once to the currency's places, half to even,
the rest exact, the two summing to the payment (BS-statement-3 statement
8). U3 had already routed the share through kernel::share_of; U6 names the
whole split as kernel::split_ratio, which builds on share_of and
round_step, and cashflow::split_part calls it. The old party-shares
refusal on the shares' own sum is kept.

The percentage's rules come from BS-statement-5 statement 2 (a project's
net is revenue less expenses) and wanderbooks' WB-statement-7 (the margin
as a percent of revenue), and BS-entry-3 (round only where a rule says
to); the split's from BS-statement-3 statement 8, BS-partner-1 and
BS-entry-3.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 09:14:19 -07:00
swaitsandClaude Opus 5.5 f5826d45a4 merge: the adapter runs refused dates, amounts, periods, roles, exports, 1099 years and returns (X-H1d's wanderbooks half; reviewed, re-checked)
Wanderbooks passes every bookspec example for its picks on refused
input: 95 run, 95 passed, 16 for options it did not pick. The IIF export
now keeps its typed refusal (an entry on two receivable or payable
accounts is BS-format-10's), where it had stringified it; the package and
the MCP tool still show the same text. A test walks every role the
schema lists through the engine's control_account, so the two lists
cannot drift apart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 09:09:03 -07:00
swaitsandDeepSeek V4.1 Flash a63e02b810 test(core): a retired bookspec id is no source
source_refs checked existence only, so a SOURCE clause could rest on a
record that bookspec retired (D-71) as long as the record still existed.
It now refuses a retired BS id unless the same clause names a live
successor, so a historical mention can still read "formerly
BS-ledger-13, now WB-ledger-16" while a bare retired id fails. The
self-tests pin both sides. The tree after S-E4 has zero problems, and
the free-text count stays 56 because every rewritten clause cites a
product rule rather than falling through to free text.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 09:00:52 -07:00
swaitsandDeepSeek V4.1 Flash b72ba2514a docs: SOURCE lines cite what states the rule now, not a retired record
Unit S-E4: 37 SOURCE clauses across ledger-core, ledger-gui, ledger-mcp
and ledger-store still cited records bookspec retired on 2026-11-08
(D-71). A retired id names what a rule was, not what governs now, so
each clause cites its successor: BS-ledger-13 is WB-ledger-16 (the
audit), BS-ledger-12 is WB-ledger-15 (evidence read from the bytes),
and BS-format-1, whose retirement names no successor, becomes the
WB-format rule that states each clause's fact: WB-format-1 (the format
gate), WB-format-2 (a journal feature declared before its first line),
WB-format-3 (the owner's format upgrade) or WB-format-4 (each projection
schema in a file of its own). No clause's fact was left without a live
rule, so no claim was added.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 09:00:48 -07:00
swaitsandDeepSeek V4.1 Flash 75533aeb45 test(core): every role the schema lists is a role the engine assigns
The schema's `ACCOUNT_ROLES` is now the list BS-ledger-8 names, not a list
read off any engine. The adapter passes `assign_role`'s key straight to
`Store::assign_role`, so a listed key this engine spelled differently
would turn an example into a refused assignment it did not ask for. The
new test walks the schema's list and requires `control_account` to resolve
every key, which is also the check that `other_deductions_payable` is now
listed and the internal-only roles are not.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 08:58:25 -07:00
swaitsandDeepSeek V4.1 Flash eb073b53c6 style(core): rustfmt the refused-input adapter additions
The X-H1d adapter commits left two expressions the workspace's rustfmt
reflows: the `matches!` in `check.rs` and the `assert_eq!` arguments in
`queries/parties.rs`. No behavior changes; `cargo fmt --all -- --check`
now passes.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 08:58:16 -07:00
swaitsandDeepSeek V4.1 Flash 7ac1e644b2 test(core): the adapter runs refused dates, amounts, periods, roles, exports, 1099 years and returns
The bookspec examples now spell the input an engine has to refuse, and the
adapter takes each through the real books:

- a date past 9999 is refused by `Store::create_entry`'s own
  `try_create_entry` (DateOutOfRange), and a line past one quadrillion by
  `add_line` (AmountOutOfRange), each on a rehearsal so a refused entry
  leaves no draft;
- a close whose period partly overlaps another creates it through
  `Store::create_period` and reads PeriodsOverlap;
- `assign_role` is `Store::assign_role`, the journaled command, so a role
  on a header is refused by `check_assign_role` (ControlAccountMismatch)
  and the chart stays as it was;
- an IIF export with an entry on a receivable and a payable account is
  refused with BS-format-10's word, which is why `export_iif` keeps its
  typed error;
- a 2027 worksheet is refused through `RuleNotKnown` as
  `unknown_1099_year`, never guessed;
- `return_tin` reads the full number from the real `ledger_vault::Vault`
  the example's `setup.vault_tins` fills, and the books' own record keeps
  only the last four.

The adapter skips sixteen examples now (three more, each for an option
wanderbooks did not pick): allow-partial-overlap, carry-the-last-amount
and nowhere. Every one of the 95 it runs passes.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 07:40:26 -07:00
swaitsandDeepSeek V4.1 Flash 9c299eb768 fix(package): the IIF export keeps its typed refusal
`export_iif` turned `journal_to_iif`'s refusal into a string, so a caller
could not tell why the file was refused without reading the message. An
entry on more than one receivable or payable account is BS-format-10's
own refusal (the receiving program will not take the transaction), while
every other IIF refusal is BS-format-2's; the bookspec adapter must name
the one rule an example expects. Returning `IifError` keeps the two apart
by type. The package and the MCP tool still hand the human a string.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 07:40:21 -07:00
swaitsandClaude Opus 5.5 045e70bb0d merge: tests where coverage was thinnest, the audit's strict close bound, WB-ledger-17 (V-D2; reviewed, fixes applied)
Ninety-six tests, each encoding the rule it covers, reach what the core
and store suites left untouched: the evidence requirement (34% to 100% of
its lines), the store's reconcilable accounts (0% to 100%), the command
steps' refusals, conventions, settings and the audit's branches. ledger-
core's line coverage rises from 89.79% to 95.49%, and the floor with it.

Found: the digest listed cash accounts found by name in hash order, so
the same books could list them differently; they come in ascending
account id now. The audit now holds a close's member split to under one
unit (BS-partner-1 statement 5) once the count has been trued up, a
close records its rule, and only drift beyond one unit before; the
reconciliations rule is written down as WB-ledger-17.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 07:33:54 -07:00
swaitsandClaude Sonnet 5.5 ae32a83407 docs(spec): WB-ledger-17, the reconciliations rule, and the order the tests pin
Which accounts the monthly close reconciles, and when each is due, was a
module's own spec block with no id. It is now WB-ledger-17 (product-only, a
CONVENTION sourced to docs/parties-and-attachments.md "Reconciliations"),
checked against the code: the cash accounts (configured ones in the order
given, else by name in ascending account id), the card accounts (ascending
id), then the other liabilities with a statement in the order the statements
are given (period end, then file; not ascending id), each once; and an account
is due through last month's end when it has a posted line on or before it and
no reconciliation not voided is dated on or after it. The module and the test
file cite it.

The order within the cash group is the account id's, as `card_accounts` sorts,
not the chart code's (`ChartOfAccounts::all` is unordered). The test is renamed
to say so and its codes are out of creation order, so a sort by code fails it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 06:15:39 -07:00
swaitsandClaude Sonnet 5.5 2ce48090fd test(core): a replayed line past the line limit is refused when it posts
Opening old books is a real input: a draft line an earlier version accepted
past MAX_LINE_AMOUNT replays as journaled, and its post refuses it
(AmountOutOfRange, BS-entry-4), leaving the draft and the books as they were.
Covered for a plain line and a foreign line (bounded by its booked base
amount), at Decimal::MAX and one cent past the limit, and a draft at the limit
itself posts. A foreign original of any size beside an in-range base amount is
not refused by replay or by the post, and no journal writes one, so it is
left documented, not pinned.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 06:15:38 -07:00
swaitsandClaude Sonnet 5.5 344e09933d test(core): cite the rule that states the fact, and assert the fact, not the wording
Review of V-D2's tests:
- S-E3's vocabulary: `item k` and `INVARIANT k` become `invariant k` of
  WB-ledger-15, WB-ledger-9 (no numbered parts: cited whole), and the statements
  and invariants of BS-arap-5 and BS-arap-6 that the tests actually pin.
- The split-group tests cite WB-entry-6, the only rule that says "as part of a
  split group", not BS-entry-5.
- A refusal is pinned by its variant plus the fragment that states the fact (a
  figure, "positive", "strictly greater"), not its whole sentence; the
  `ConventionKind::ALL.len() == 7` pin is dropped.
- `a_send...moves_no_figure` compared receivables with itself; it now asserts
  the bank unchanged and receivables at 500.00.
- The disposal test says a day before the asset was acquired is refused and
  now asserts DisposalBeforeAcquisition.
- Main's FeeAboveCash variant replaces the InvalidSettlement text the fee test
  matched; it now asserts the variant and both figures.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 06:15:38 -07:00
swaitsandClaude Sonnet 5.5 7ac1ef8c5a fix(core): the audit holds a close's split to under one unit once the count is trued up
BS-partner-1 statement 5 says that after a close that posts, each member's
running total MUST be under one smallest unit from its exact share. The audit
flagged drift only when it was greater than a unit, so exactly one unit passed.
The looser bound is right only until the first true-up (statement 6,
WB-partner-1): a count that still holds closes made under the older rules may
carry their rounding until a cumulative close posts.

A close records both facts replay needs: its rule (`MembersClosed.rule`) and
whether it posted (`closing_entry`). `Ledger::member_close_trued_up` says a
count has had a cumulative close that posted, at or before a given close, and
`audit::check_split` flags drift of a unit or more once it has, drift beyond a
unit before. Closes under the older rules are not read by the audit at all.

Tests: both regimes at the edge in either direction, and a count walked through
a per-close January, a non-posting February (not trued up), a posting March
(trued up) and a non-posting April (still trued up). WB-ledger-16 gains
invariant 8 for it. The same test file now cites WB-ledger-16 for the audit
(BS-ledger-13 is retired), and audit.rs's own invariant and scenario where
WB-ledger-16's numbering does not match.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 06:15:38 -07:00
swaitsandClaude Opus 5.5 ee3c2b99c3 build: pin bookspec at 2b3b6c9, the even-parts law
bookspec main now carries law 43 (K-U5): a monthly-even schedule's parts
sum to its total, all but the last the same rounded share, at any size.
Lean 188 theorems, standard axioms only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 05:24:41 -07:00
swaits 5fd382450b Merge branch 'main' into t3/coverage-gap-tests-v-d2 2026-11-09 05:07:33 -07:00