e42c3909fa13735740e904836ec00102ad88255d
8
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
8dec2900eb |
fix(prove): audit bookspec's own theorem list, not a copy
just prove audited verify/lean/Audit.lean, a copy of bookspec's list made when the laws moved there (L-F2). The laws then grew in bookspec (the FX law, the rounding primitive, the executable model's soundness and completeness, the empty close) and the copy did not: it audited 151 theorems of the 177 bookspec states, so 26 were proved but never checked for axioms on this side. Bookspec's CI audits them, so no theorem is known to rest on more than Lean's three; but the laws live once (D-69), and so must their list. just prove now runs bookspec's lean/Audit.lean from the pinned package, and the copy is gone: 177 theorems, standard axioms only. A unit's #print axioms line now goes in its bookspec branch with its theorem. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
e431791bbc |
build(lean): verify/lean requires bookspec's Lean; the laws live once
D-69 puts the accounting laws in one place: bookspec's Lean, namespace `Bookspec`. L-F1 landed there every file of `verify/lean/Wanderbooks/`. Before deleting the copies, each was checked: comments stripped, namespace normalised, blank lines dropped, and diffed against its bookspec peer -- all ten are identical (Basic, Entry, Statements, Closing, Ledger, Apportion, Parties, Prorate, Deductible, Documents). There is nothing wanderbooks-only left to keep. So `verify/lean/lakefile.toml` now `[[require]]`s bookspec as a git dependency at 77e046334eea29e082b53bbe907017d9ffef5a0a -- the same rev `crates/ledger-core/Cargo.toml` pins the Rust checker to -- with `subDir = "lean"`. The generated `lake-manifest.json` is committed, because Lake builds from it and it must not float. `Wanderbooks.lean` is now a thin local target that imports `Bookspec`: `lake build` builds and checks the whole law set, and the file says where a law is edited and how wanderbooks picks it up (move the pin). The duplicated modules and the `Wanderbooks/` directory are gone. `Audit.lean` imports `Bookspec` and audits all 151 theorems (the 118 headline laws plus the 33 named laws in `Laws.lean` that cite them) -- the whole set bookspec itself audits. `just prove` still checks standard axioms only; its summary now says "theorems", since the set is more than headline ones. The new `tests/bookspec/pin.rs` reads the rev out of the lakefile, the manifest, and both crates' Cargo.toml, and fails unless all four name the same repository at the same commit, and bookspec's `lean/` package. Without it the Lean laws and the Rust checker could silently be different spec versions. Verified: `lake build` from a clean `.lake` (fetches and builds in 7 s); `just prove` 871 s (Kani 53 harnesses, then 151 theorems, standard axioms only); `cargo test -p ledger-core --test bookspec pin`; `cargo fmt --check`; `cargo clippy -p ledger-core --tests -D warnings`. Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai> |
||
|
|
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> |
||
|
|
d7fa16e974
|
feat(arap)!: documents read their figures from standing lines; control accounts
check / check (push) Canceled after 0s
refuse hand entries (P4b S1, part A) Plan P4b (D-45), slice S1, the engine half: rules.md B-38. - ledger-core: every receivables or payables line carries its document (Ledger.line_docs: DocRef, Movement, DocTag), written by the document commands in the step that posts it, derived on replay from the existing document events (the role's account as it stood then; payments by the ordinal rule), copied onto a reversal's mirror. Ledger::stands_on; doc_state / invoice_state / bill_state (total, paid, outstanding, status Open/Partial/Paid/WrittenOff/Void, overdue days) as of any day; ar_aging / ap_aging read them, so reversed payments and voids are right. The control guard (add_line, add_line_fx, post_entry, register_recurring) refuses untagged lines on receivables/payables, exempting a reversal's mirror of a legacy line; replay never refuses. Bounds (kernel::running_bounds, bounds_kept) on payments and reversals; a document reversal never dated before its entry; deposit/payer accounts must be cash-like and hold no role. New API: receive_payment_with / pay_bill_with (PaymentDetails: instrument, reference), void_document / check_void_document, control_check, payments_recorded, standing_payments, replay_reverse_entry. Invoice.amount_paid/status remain only as derived caches for the MCP layer until part B. cashflow bill_splits reads payments from the tags. - ledger-store: journal feature document_standing (D-39 gated) for a payment accepted only because an earlier one was reversed; receive_payment_with / pay_bill_with (instrument journaled as entry.instrument_set, reference in the description), void_document; replay uses replay_reverse_entry; schema 15 drops the projection's amount_paid/status. Fixture p4-arap-before + golden figures written by the version before S1, adjudicated in arap_standing.rs. - ledger-gui: party card, cash "coming up" and company owed totals read doc_state as of today (late from the derived state). - Lean Documents.lean (control_agrees and friends); Kani bounds_check_matches_definition, bounds_kept_is_the_definition_on_books_in_bounds; rules B-38, B-18/B-23 amended; bookspec `older = true` for legacy hand lines; tests that hand-post to 1200/2000 post as replay or renumbered. Review fixes (both reviews of part A): - control_role_of guards only an account the role is assigned to or one holding its documents' lines (a chart's own 1200 Equipment or card at 2000 is free until a document posts there); payment accounts check other roles by holds_role (type-checked). The MCP tests that failed on the guard (oracle_mcp, spec_projects) pass unchanged. - standing_payments leaves out reversals (sorted, deduped); replayed tags match the movement's side; payments_recorded counts every payment event (tagged or not, Ledger.payment_events) and refuses overflow. - The record caches settled (paid + discounted + written off) and owed (Invoice/Bill.owed, never serialized): a void never reads as paid. - assign_role: receivables/payables refuse moving onto an account with untagged lines (RoleAccountHasHandLines) and, on their control account holding a balance, say DocumentRoleHoldsBalance (no hand entry named); B-23 reworded. The reversal-mirror exemption only takes a hand line off (even chain depth); putting it back is refused. - DocStatus Overpaid and Unattached; aging leaves out credit balances; ControlCheck.attention lists out-of-bounds and unattached documents. - stands_on counts a chain in order; indexes (doc_index, doc_accounts, order_pos, reversed_by) keep the derived figures linear. - Viewer reads a post-dated document as of its own date; one state per row. bounds_kept's side-crossing documented as intended. - Tests: ten new spec_documents scenarios, stronger proptests, store proptest arap_props (live = replay = snapshot at every date, closed months), fuzz ops void/payments with details, a GUI post-dated test; Lean Step.assign / Step.release with unattached_zero kept; model limits stated in docs/testing.md and B-38. Review fixes (CPA and engineering lenses): only an assigned role's account or one holding document lines is a control account (a chart's own 1200 asset stays free); a role can't move onto untagged lines or off document lines (Lean Step.assign); a void's cache never reads as paid; no Decimal sum panics; per-document indexes keep figures linear; a replayed tag matches its side; the feature gate counts payment events; a payment's reversal is never listed as standing; an overpaid document has its own status; the viewer keeps post-dated documents. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T3gXMVt7XJPi6ens1or9Dj |
||
|
|
b0a9fd8ad4
|
P3: depreciation straight-line by days through the final month, schedules by day (defects 22, 9, D-37)
The final month takes what the months before leave, spread over its days; a disposed asset stops on its disposal day. A skipped month is caught up in the month the run is made; a reversed run un-posts its month. New schedules spread by day; equal-months schedules must start on the 1st. Amounts round to the currency's own minor unit. Kani and Lean proofs; an exhaustive search over runs, reversals and disposals. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T3gXMVt7XJPi6ens1or9Dj |
||
|
|
c2ceabbae9
|
P3: party totals by what moved the money, once (defects 14, 11, 24)
Each party's part of an entry is signed as its own account would show it, with a direction and its cash and in-kind amounts; a reversal is its original negated. Totals on a cash or all basis: for a member, all equals the members' equity statement and cash the K-1's cash. Money is cash, cards and the financing accounts, and a liability credit never pays its own creditor (creditor_of), so accruals and declared distributions count once. tin_last4 from the TIN or W-9 facts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T3gXMVt7XJPi6ens1or9Dj |
||
|
|
714caf9be9 |
lean: apportion's parts sum to the whole for any number of parts
The ranks of n parts are a permutation of 0..n-1 (being ahead is a strict total order; pigeonhole by hand, core Lean has no subperm), so exactly u parts get a unit and one gets the fraction. apportion_sum and apportion_sum_of_shortfall; the audit shows only the standard axioms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GWVo7x3UHw5kwCUaWxiejX |
||
|
|
2d36fb05a4 |
feat(core): prove the accounting laws (Kani + Lean); fix three engine gaps
The money arithmetic every invariant rests on now lives in one kernel,
ledger-core/src/kernel.rs: signing a line, totals, net, per-account
movements, reversal, normal balances, trial-balance columns, closing
lines, and the rounding plug for member splits. It is generic over a
checked `Amount` trait. The engine runs it on Decimal (validate,
movements, reverse_entry, account_balance, close_period_to, allocate,
trial_balance): there is one copy of the arithmetic, and it is the one
under proof.
Three layers, docs/verification.md maps every law to its proofs:
- Kani (src/proofs.rs): 17 harnesses prove the kernel at i64 for every
input up to 4 lines over 3 accounts. An entry is accepted exactly
when it is two or more positive, in-range lines whose debits equal
credits; accepted entries net to zero; grouping by account loses
nothing; a reversal mirrors and cancels its original; trial-balance
columns balance iff the books net to zero; closing lines zero their
accounts and a close balances however the net is split; the plug
makes parts sum to the whole. No panics, no overflow. kani::cover!
shows the proofs are not vacuous.
- Lean 4 (verify/lean): 24 headline theorems for books of any size. The
ledger is a state machine (add account, draft, post, reverse, open,
close), and in every reachable state the books net to zero, the trial
balance balances (as of any date), and the accounting equation holds.
Posting only appends ("posted is forever"), closed periods are
frozen, a close zeroes revenue and expenses and credits exactly the net
income, and period statements add up. Audit.lean shows standard axioms
only, no sorry.
- Bridge (tests/kernel_bridge.rs): the Decimal and i64 kernels agree.
What the proofs found (each one missed by every test, fuzzer, and
mutant):
- The engine accepted negative line amounts; only MCP refused them. Now
NegativeAmountLine: direction is the side's job.
- Summing lines near Decimal::MAX panicked. Lines are now capped at one
quadrillion and ten decimal places (AmountOutOfRange), which keeps
every realistic sum exact, and the kernel's sums are checked.
- FX conversion (foreign_amount * fx_rate) could panic the same way; it
is now a checked multiply.
- Kani itself: 0.68 mis-models symbolic-length copy_from_slice
(model-checking/kani#4904) and reported a reversal that doesn't net to
zero. The counterexample, replayed natively, passes, and a 15-line
standalone crate reproduces the bug. Harnesses avoid bulk copies, and
a should_panic canary will flag the upstream fix.
`just prove` runs it all (Kani memory- and time-capped, fails on an
unsatisfiable cover or a non-standard Lean axiom). AGENTS.md now makes
formal coverage part of every core change.
Also, docs: GnuCash is *an* oracle, never *the* oracle (the owner). The
spec is accounting principles, proved. Golden files are recomputed from
principles. External implementations (GnuCash, the old Sheet, QBO/Xero)
are cross-checks whose disagreements get adjudicated, never obeyed.
docs/oracle.md gains "Who is right"; AGENTS, README, architecture,
roadmap, parity, and STATUS are reworded to match.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GWVo7x3UHw5kwCUaWxiejX
|