merge: the kernel and its proofs become modules, one file per sweep unit (K-U0; branch t3/kernel-modules-scaffold, 0cf013b5; same 1,096 tests, 27 bridge properties, 53 harnesses, 118 theorems)
Conflicts with X-H0 and S-D0 resolved: both new paths kept (tests/bookspec/, tests/kernel_bridge/, src/proofs/); K-U0's two path fixes in rules.md applied to the claims file the rule moved to. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
75c666a7ce
37 files changed
+368
-108
No files matched your search
@@ -0,0 +1,5 @@
|
||||
//! U3: proportional shares, splitting a whole by weights without drift (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its arithmetic here, in this file alone, so
|
||||
//! no two sweep units ever edit the same file. The module root re-exports
|
||||
//! it, keeping every path `crate::kernel::foo`.
|
||||
@@ -0,0 +1,5 @@
|
||||
//! U8: control and aging, what is due or overdue (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its arithmetic here, in this file alone, so
|
||||
//! no two sweep units ever edit the same file. The module root re-exports
|
||||
//! it, keeping every path `crate::kernel::foo`.
|
||||
@@ -1,65 +1,6 @@
|
||||
//! The accounting kernel: the arithmetic every bookkeeping invariant rests
|
||||
//! on, in one place.
|
||||
//!
|
||||
//! Each function here is small, pure, and generic over [`Amount`]. The
|
||||
//! engine runs it on [`Decimal`]; the Kani harnesses in `proofs.rs` run the
|
||||
//! very same code on machine integers and prove it correct for every input
|
||||
//! within their bounds; and the Lean model in `verify/lean` proves the
|
||||
//! laws it implements hold for books of any size. See
|
||||
//! `docs/verification.md` for which proof covers which law.
|
||||
//!
|
||||
//! The laws, in the order they appear (each traced to its authority in
|
||||
//! `docs/spec/rules.md`):
|
||||
//!
|
||||
//! * a line's signed amount is `+amount` for a debit, `-amount` for a credit
|
||||
//! (B-2);
|
||||
//! * an entry is acceptable when it has two or more lines, every amount is
|
||||
//! positive and in range, and its debits equal its credits exactly (B-1,
|
||||
//! B-2, B-21);
|
||||
//! * an acceptable entry nets to zero, account by account summed (B-1);
|
||||
//! * a reversal flips every side, so it is acceptable exactly when the
|
||||
//! original is, and the two together net every account to zero (B-9);
|
||||
//! * an account's balance is its movement read on its normal side, so the
|
||||
//! balances satisfy the accounting equation whenever movements net to
|
||||
//! zero (B-5, B-7);
|
||||
//! * a trial balance puts each movement in exactly one column, so its
|
||||
//! columns differ by the net of all movements (B-6);
|
||||
//! * a closing line zeroes the account it closes (B-11);
|
||||
//! * a payment to a vendor splits, line by line, into what counts toward
|
||||
//! its 1099, what a card or payment network paid, and what is unknown,
|
||||
//! and money moved between the company's own sources nets out (B-19);
|
||||
//! * an early-payment discount never exceeds its stated percentage of the
|
||||
//! total, and a document line's amount is exactly its quantity times its
|
||||
//! unit price, neither rounded (B-39);
|
||||
//! * an allocation's parts sum to the whole, to the last unit, by largest
|
||||
//! remainder (B-13);
|
||||
//! * a cumulative allocation hands out exactly the new amount, and leaves
|
||||
//! each running total one allocation of everything allocated, so it never
|
||||
//! drifts a unit from its exact share (B-13);
|
||||
//! * an entry's cash is applied to the sections of the statement of cash
|
||||
//! flows moving against it, in a fixed order, each up to its own
|
||||
//! movement: the parts sum to the entry's cash, what no cash settled sums
|
||||
//! to zero, and a reversal's parts are the original's negated (B-14);
|
||||
//! * what a member or lender paid or received for the company, with no
|
||||
//! cash account moving, is split among the kinds it settled, netting to
|
||||
//! zero, and mirrored by a reversal (B-14 rule 11);
|
||||
//! * a party's part of an entry is signed as a line on the party's own
|
||||
//! account would be, a reversal's is its original's negated, and what of
|
||||
//! it counts as money or as property never exceeds it (B-35);
|
||||
//! * a span prorated by days (depreciation, B-15; daily schedules, B-16)
|
||||
//! splits into parts that sum to its total, each but the last its days
|
||||
//! times the monthly rate within one unit, the last the remainder;
|
||||
//! * a catch-up run brings the books to the schedule without ever carrying
|
||||
//! more than it says at a month end already posted (B-15), and a
|
||||
//! disposal trues what the books carry up or down to the schedule;
|
||||
//! * an asset's basis figures follow from its basis rule and facts: the
|
||||
//! §723 basis is the contributor's adjusted basis, the depreciable basis
|
||||
//! the cost, that basis, or the lesser of it and fair market value, and
|
||||
//! the §704(c) built-in gain is fair market value less the §723 basis
|
||||
//! (B-25);
|
||||
//! * a tax category's deductible amount adds its accounts' exact shares and
|
||||
//! rounds once to the cent, half away from zero, never share by share
|
||||
//! (B-32, B-21).
|
||||
//! The entry arithmetic: signing, validating, netting, reversing and
|
||||
//! grouping the lines of an entry or a book, unchanged in U0. The laws it
|
||||
//! serves are listed at the module root, [`super`].
|
||||
|
||||
use crate::assets::BasisRule;
|
||||
use crate::{AccountType, Side};
|
||||
@@ -0,0 +1,5 @@
|
||||
//! U1: foreign-currency conversion, the booking of a foreign amount at the transaction-date rate (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its arithmetic here, in this file alone, so
|
||||
//! no two sweep units ever edit the same file. The module root re-exports
|
||||
//! it, keeping every path `crate::kernel::foo`.
|
||||
@@ -0,0 +1,98 @@
|
||||
//! The accounting kernel: the arithmetic every bookkeeping invariant rests
|
||||
//! on, in one place.
|
||||
//!
|
||||
//! Each function here is small, pure, and generic over [`Amount`]. The
|
||||
//! engine runs it on [`rust_decimal::Decimal`]; the Kani harnesses in `proofs/` run the
|
||||
//! very same code on machine integers and prove it correct for every input
|
||||
//! within their bounds; and the Lean model in `verify/lean` proves the
|
||||
//! laws it implements hold for books of any size. See
|
||||
//! `docs/verification.md` for which proof covers which law.
|
||||
//!
|
||||
//! The laws, in the order they appear (each traced to its authority in
|
||||
//! `docs/spec/rules.md`):
|
||||
//!
|
||||
//! * a line's signed amount is `+amount` for a debit, `-amount` for a credit
|
||||
//! (B-2);
|
||||
//! * an entry is acceptable when it has two or more lines, every amount is
|
||||
//! positive and in range, and its debits equal its credits exactly (B-1,
|
||||
//! B-2, B-21);
|
||||
//! * an acceptable entry nets to zero, account by account summed (B-1);
|
||||
//! * a reversal flips every side, so it is acceptable exactly when the
|
||||
//! original is, and the two together net every account to zero (B-9);
|
||||
//! * an account's balance is its movement read on its normal side, so the
|
||||
//! balances satisfy the accounting equation whenever movements net to
|
||||
//! zero (B-5, B-7);
|
||||
//! * a trial balance puts each movement in exactly one column, so its
|
||||
//! columns differ by the net of all movements (B-6);
|
||||
//! * a closing line zeroes the account it closes (B-11);
|
||||
//! * a payment to a vendor splits, line by line, into what counts toward
|
||||
//! its 1099, what a card or payment network paid, and what is unknown,
|
||||
//! and money moved between the company's own sources nets out (B-19);
|
||||
//! * an early-payment discount never exceeds its stated percentage of the
|
||||
//! total, and a document line's amount is exactly its quantity times its
|
||||
//! unit price, neither rounded (B-39);
|
||||
//! * an allocation's parts sum to the whole, to the last unit, by largest
|
||||
//! remainder (B-13);
|
||||
//! * a cumulative allocation hands out exactly the new amount, and leaves
|
||||
//! each running total one allocation of everything allocated, so it never
|
||||
//! drifts a unit from its exact share (B-13);
|
||||
//! * an entry's cash is applied to the sections of the statement of cash
|
||||
//! flows moving against it, in a fixed order, each up to its own
|
||||
//! movement: the parts sum to the entry's cash, what no cash settled sums
|
||||
//! to zero, and a reversal's parts are the original's negated (B-14);
|
||||
//! * what a member or lender paid or received for the company, with no
|
||||
//! cash account moving, is split among the kinds it settled, netting to
|
||||
//! zero, and mirrored by a reversal (B-14 rule 11);
|
||||
//! * a party's part of an entry is signed as a line on the party's own
|
||||
//! account would be, a reversal's is its original's negated, and what of
|
||||
//! it counts as money or as property never exceeds it (B-35);
|
||||
//! * a span prorated by days (depreciation, B-15; daily schedules, B-16)
|
||||
//! splits into parts that sum to its total, each but the last its days
|
||||
//! times the monthly rate within one unit, the last the remainder;
|
||||
//! * a catch-up run brings the books to the schedule without ever carrying
|
||||
//! more than it says at a month end already posted (B-15), and a
|
||||
//! disposal trues what the books carry up or down to the schedule;
|
||||
//! * an asset's basis figures follow from its basis rule and facts: the
|
||||
//! §723 basis is the contributor's adjusted basis, the depreciable basis
|
||||
//! the cost, that basis, or the lesser of it and fair market value, and
|
||||
//! the §704(c) built-in gain is fair market value less the §723 basis
|
||||
//! (B-25);
|
||||
//! * a tax category's deductible amount adds its accounts' exact shares and
|
||||
//! rounds once to the cent, half away from zero, never share by share
|
||||
//! (B-32, B-21).
|
||||
//!
|
||||
//! The kernel is a module directory so each kernel-sweep unit adds its
|
||||
//! arithmetic in a file of its own (`fx`, `round`, `allocate`, `total`,
|
||||
//! `schedule`, `ratio`, `payroll`, `control`) and the entries above stay
|
||||
//! in `entries`. Only this file declares the modules; the units never edit
|
||||
//! it, and every path still resolves as `crate::kernel::foo`.
|
||||
|
||||
mod allocate;
|
||||
mod control;
|
||||
mod entries;
|
||||
mod fx;
|
||||
mod payroll;
|
||||
mod ratio;
|
||||
mod round;
|
||||
mod schedule;
|
||||
mod total;
|
||||
|
||||
// The unit modules are empty until their sweep unit lands; re-exporting
|
||||
// them now is what keeps every `crate::kernel::foo` path in place.
|
||||
#[allow(unused_imports)]
|
||||
pub use allocate::*;
|
||||
#[allow(unused_imports)]
|
||||
pub use control::*;
|
||||
pub use entries::*;
|
||||
#[allow(unused_imports)]
|
||||
pub use fx::*;
|
||||
#[allow(unused_imports)]
|
||||
pub use payroll::*;
|
||||
#[allow(unused_imports)]
|
||||
pub use ratio::*;
|
||||
#[allow(unused_imports)]
|
||||
pub use round::*;
|
||||
#[allow(unused_imports)]
|
||||
pub use schedule::*;
|
||||
#[allow(unused_imports)]
|
||||
pub use total::*;
|
||||
@@ -0,0 +1,5 @@
|
||||
//! U7: payroll arithmetic, withholding and employer taxes (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its arithmetic here, in this file alone, so
|
||||
//! no two sweep units ever edit the same file. The module root re-exports
|
||||
//! it, keeping every path `crate::kernel::foo`.
|
||||
@@ -0,0 +1,5 @@
|
||||
//! U6: ratios, percentages and averages that reports show (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its arithmetic here, in this file alone, so
|
||||
//! no two sweep units ever edit the same file. The module root re-exports
|
||||
//! it, keeping every path `crate::kernel::foo`.
|
||||
@@ -0,0 +1,5 @@
|
||||
//! U2: one rounding primitive, the single place money is rounded to a step (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its arithmetic here, in this file alone, so
|
||||
//! no two sweep units ever edit the same file. The module root re-exports
|
||||
//! it, keeping every path `crate::kernel::foo`.
|
||||
@@ -0,0 +1,5 @@
|
||||
//! U5: schedule plans, the monthly charge a schedule books (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its arithmetic here, in this file alone, so
|
||||
//! no two sweep units ever edit the same file. The module root re-exports
|
||||
//! it, keeping every path `crate::kernel::foo`.
|
||||
@@ -0,0 +1,5 @@
|
||||
//! U4: totals, exact checked sums for books and reports (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its arithmetic here, in this file alone, so
|
||||
//! no two sweep units ever edit the same file. The module root re-exports
|
||||
//! it, keeping every path `crate::kernel::foo`.
|
||||
@@ -0,0 +1,5 @@
|
||||
//! U3 proof harnesses: proportional shares (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its Kani harnesses here; `just prove` scans
|
||||
//! every file in `proofs/`, so a harness needs no change to the module
|
||||
//! root or the recipe.
|
||||
@@ -0,0 +1,5 @@
|
||||
//! U8 proof harnesses: control and aging (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its Kani harnesses here; `just prove` scans
|
||||
//! every file in `proofs/`, so a harness needs no change to the module
|
||||
//! root or the recipe.
|
||||
@@ -0,0 +1,5 @@
|
||||
//! U1 proof harnesses: foreign-currency conversion (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its Kani harnesses here; `just prove` scans
|
||||
//! every file in `proofs/`, so a harness needs no change to the module
|
||||
//! root or the recipe.
|
||||
@@ -19,6 +19,18 @@
|
||||
//! for any number of parts and any sizes (docs/verification.md says
|
||||
//! which, and how it ties to the kernel's formula).
|
||||
|
||||
// One file per kernel-sweep unit; the harnesses above stay here. `just
|
||||
// prove` scans every file in this directory, so a new harness only needs
|
||||
// its own file and no edit to this one.
|
||||
mod allocate;
|
||||
mod control;
|
||||
mod fx;
|
||||
mod payroll;
|
||||
mod ratio;
|
||||
mod round;
|
||||
mod schedule;
|
||||
mod total;
|
||||
|
||||
use crate::kernel::{self, Amount, LineError, MONTH_L, MonthPart};
|
||||
use crate::{AccountType, Side};
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
//! U7 proof harnesses: payroll arithmetic (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its Kani harnesses here; `just prove` scans
|
||||
//! every file in `proofs/`, so a harness needs no change to the module
|
||||
//! root or the recipe.
|
||||
@@ -0,0 +1,5 @@
|
||||
//! U6 proof harnesses: ratios (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its Kani harnesses here; `just prove` scans
|
||||
//! every file in `proofs/`, so a harness needs no change to the module
|
||||
//! root or the recipe.
|
||||
@@ -0,0 +1,5 @@
|
||||
//! U2 proof harnesses: the rounding primitive (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its Kani harnesses here; `just prove` scans
|
||||
//! every file in `proofs/`, so a harness needs no change to the module
|
||||
//! root or the recipe.
|
||||
@@ -0,0 +1,5 @@
|
||||
//! U5 proof harnesses: schedule plans (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its Kani harnesses here; `just prove` scans
|
||||
//! every file in `proofs/`, so a harness needs no change to the module
|
||||
//! root or the recipe.
|
||||
@@ -0,0 +1,5 @@
|
||||
//! U4 proof harnesses: exact totals (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its Kani harnesses here; `just prove` scans
|
||||
//! every file in `proofs/`, so a harness needs no change to the module
|
||||
//! root or the recipe.
|
||||
@@ -0,0 +1,4 @@
|
||||
//! U3 bridge properties: proportional shares (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its `Decimal`-vs-integer properties here,
|
||||
//! beside `main.rs` and the other units.
|
||||
@@ -0,0 +1,4 @@
|
||||
//! U8 bridge properties: control and aging (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its `Decimal`-vs-integer properties here,
|
||||
//! beside `main.rs` and the other units.
|
||||
@@ -0,0 +1,4 @@
|
||||
//! U1 bridge properties: foreign-currency conversion (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its `Decimal`-vs-integer properties here,
|
||||
//! beside `main.rs` and the other units.
|
||||
+11
-1
@@ -1,11 +1,21 @@
|
||||
//! The bridge between the proofs and the engine.
|
||||
//!
|
||||
//! The Kani harnesses (`src/proofs.rs`) prove the accounting kernel on
|
||||
//! The Kani harnesses (`src/proofs/`) prove the accounting kernel on
|
||||
//! `i64` money in the smallest unit; the engine runs the same kernel on
|
||||
//! `Decimal`. These properties check the two instantiations agree, value
|
||||
//! for value, on cents: whatever Kani proved of the `i64` kernel holds of
|
||||
//! the `Decimal` one for the same amounts.
|
||||
|
||||
// One file per kernel-sweep unit; the properties above stay here.
|
||||
mod allocate;
|
||||
mod control;
|
||||
mod fx;
|
||||
mod payroll;
|
||||
mod ratio;
|
||||
mod round;
|
||||
mod schedule;
|
||||
mod total;
|
||||
|
||||
use ledger_core::kernel::{self, Amount, LineError};
|
||||
use ledger_core::{AccountType, Side};
|
||||
use proptest::prelude::*;
|
||||
@@ -0,0 +1,4 @@
|
||||
//! U7 bridge properties: payroll arithmetic (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its `Decimal`-vs-integer properties here,
|
||||
//! beside `main.rs` and the other units.
|
||||
@@ -0,0 +1,4 @@
|
||||
//! U6 bridge properties: ratios (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its `Decimal`-vs-integer properties here,
|
||||
//! beside `main.rs` and the other units.
|
||||
@@ -0,0 +1,4 @@
|
||||
//! U2 bridge properties: the rounding primitive (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its `Decimal`-vs-integer properties here,
|
||||
//! beside `main.rs` and the other units.
|
||||
@@ -0,0 +1,4 @@
|
||||
//! U5 bridge properties: schedule plans (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its `Decimal`-vs-integer properties here,
|
||||
//! beside `main.rs` and the other units.
|
||||
@@ -0,0 +1,4 @@
|
||||
//! U4 bridge properties: exact totals (kernel sweep).
|
||||
//!
|
||||
//! Empty in U0: the unit adds its `Decimal`-vs-integer properties here,
|
||||
//! beside `main.rs` and the other units.
|
||||
Reference in new issue
Block a user