fix(core): a running total of rounded shares adds by the rounding sum (K-U11a)

After K-U10 made the kernel's Decimal sum exact or refused, the K-1
worksheet refused every split by thirds with "a member's tax-basis
capital is too large to compute". Two tests caught it
(thirds_summed_are_the_cents_they_are, a_running_split_never_drifts_a_cent);
it never reached main, where the worksheet still called rust_decimal's
own sum.

A member's running total in RunningSplit is a sum of shares, each
whole x weight / sum of weights: a quotient of 28 significant digits. Two
thirds of 28 digits do not add to a number 96 bits hold. The total they
stand for was never an exact figure, and INVARIANT 4 of that type was
written for exactly that: the total is rounded to ten places before a
cent is taken from it. So the fault was in the routing, not the
arithmetic: K-U11a's script mapped that sum to the exact operation.

A sum of rounded quotients is a rounded figure by construction, as a
share's product is (checked_mul_rounded, K-U10). The kernel now names
that sum too: Amount::checked_add_rounded and checked_sub_rounded,
rust_decimal's own for Decimal and the plain operation for a machine
integer. RunningSplit::split and unsplit call them and nothing else does;
every sum of amounts stays exact or refused. So the K-1 worksheet
computes what it computes on main, to the digit.

The bridge property checks, over Decimal's whole range: the rounding sum
is rust_decimal's figure to the digit and the scale, it is the exact
figure wherever exact arithmetic gives one, and where it rounds it is
within half a unit of the last place it keeps. The seed proptest shrank
the failure to is kept.

Every other place outside the kernel that makes a figure of more than
ten places was read for the same fault (docs/proofs/k-u11.md lists
them); none adds such a figure before rounding it.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude committed 2026-11-09 23:27:24 -07:00
1 parent 7d525d392e
commit 34f5275ec4
4 files changed
+76 -4

No files matched your search

+28
View File
@@ -50,6 +50,28 @@ pub trait Amount: Copy + Ord {
fn checked_mul_rounded(self, rhs: Self) -> Option<Self> {
self.checked_mul(rhs)
}
/// `self + rhs` as the amount type adds, which for [`Decimal`] is
/// `rust_decimal`'s: exact where the sum fits 96 bits and scale 28,
/// otherwise rounded to what it holds. `None` only on overflow.
///
/// The engine's rounding sum, beside its rounding product and its
/// rounding division, and for one use: a running total of rounded
/// shares (`whole x weight / total`, each a quotient of 28 significant
/// digits). Three thirds of 28 digits are not a sum 96 bits hold, and
/// the total they stand for was never an exact figure: the caller
/// rounds it to the places it means before a cent is taken from it
/// (`tax_capital`'s `RunningSplit`, INVARIANT 4). Nothing else calls
/// it; a sum of amounts is [`Amount::checked_add`], exact or refused.
/// A machine integer never rounds, so there it is `checked_add`.
fn checked_add_rounded(self, rhs: Self) -> Option<Self> {
self.checked_add(rhs)
}
/// `self - rhs` as the amount type subtracts: [`Amount::checked_add_rounded`]'s
/// other half, for taking a rounded share back out of such a running
/// total. For a machine integer it is `checked_sub`.
fn checked_sub_rounded(self, rhs: Self) -> Option<Self> {
self.checked_sub(rhs)
}
/// `self * rhs`, computed exactly and rounded once to a whole multiple
/// of `step` in `mode`; `None` when `step` is not positive or the
/// result cannot be represented.
@@ -142,6 +164,12 @@ impl Amount for Decimal {
fn checked_mul_rounded(self, rhs: Self) -> Option<Self> {
Decimal::checked_mul(self, rhs)
}
fn checked_add_rounded(self, rhs: Self) -> Option<Self> {
Decimal::checked_add(self, rhs)
}
fn checked_sub_rounded(self, rhs: Self) -> Option<Self> {
Decimal::checked_sub(self, rhs)
}
fn checked_mul_round_to_step(self, rhs: Self, step: Self, mode: Rounding) -> Option<Self> {
if let Some(product) = super::decimal_exact::exact_mul(self, rhs) {
return super::round::round_step(product, step, mode);