fix(core): the shares keep the old scale, and the floor's correction is bounded
The review's kernel findings, with the bridge properties that hold them. FirstAbsorbs computed the first part as whole minus the rest, which is algebraically the old split_first's parts[0] + (whole minus the sum of parts) but not the same scale: 4860 by 6/0.7/0.5 gave 4050.00 where the old code gave 4050, and 902 by 1/0.000001/0.000001 gave 902 where the old code gave 902.00. That scale reaches Part.amount, so a printed share moved. The kernel computes the old expression now, with checked ops; LastAbsorbs was already the old plug_last and the no-places conventions split. The bridge compares the strings. share_floor_with's correction loop could walk without end on a rounded product far from the exact floor: 0.1113 x 5909471247797156928749568911.8 / 0.11134381908633486049673 hangs. Both directions now stop at MAX_CORRECTION_STEPS and refuse, so an input past the cap is None, never a hang; no figure produced within the cap changes. The bridge pins the input. Ranking needed a property of its own: on i64 every remainder is zero, so the harnesses never rank. A random-weight bridge checks the split against the independent exact reference over non-terminating totals, excluding exact ties because the kernel ranks the rounded quotients' remainders; finding_ties_follow_the_rounded_quotient pins those ties (20.00 by 4/1/1 over 6 is 13.33/3.34/3.33, 20 whole is 13/4/3), today's behaviour and the pre-U3 sites' alike, for K-U10 to decide. share_floor and split_by_weights had no engine caller (only the bridge), so they are gone; split_by_weights_with and share_floor_with are the public API, and the docs say both checked_mul and checked_div can round at Decimal's edge. Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
This commit is contained in:
1 parent
d4440b6a4e
commit
8edc2e85dd
6 files changed
+313
-82
No files matched your search
@@ -4,10 +4,11 @@
|
||||
//! The divisor is fixed in every harness: CBMC's bit-blasted division by
|
||||
//! a symbolic `i64` did not finish in 30 minutes in K-U2
|
||||
//! (`docs/proofs/k-u2.md`), and every split here divides by a total or a
|
||||
//! step. The fixed weights and totals cover a tied split (2/3/5), a zero
|
||||
//! weight, a total of one, and a step that is not a power of ten; the
|
||||
//! bridge carries the same laws to every `Decimal` weight and step, and
|
||||
//! bookspec's Lean proves them for any number of parts.
|
||||
//! step. The fixed weights and totals cover three different weights
|
||||
//! (2/3/5), a zero weight and a total of one; the steps used are 1 and
|
||||
//! 10. The bridge carries the same laws to every `Decimal` weight and
|
||||
//! step, and bookspec's Lean proves them of the exact-share model for any
|
||||
//! number of parts.
|
||||
//!
|
||||
//! ```text
|
||||
//! GOAL: the parts of a weighted split sum to the whole exactly, each
|
||||
@@ -21,8 +22,10 @@
|
||||
//! INVARIANTS:
|
||||
//! 1. The parts sum to the whole, for every policy.
|
||||
//! 2. Under largest remainder each part is within one unit (the step)
|
||||
//! of its exact share: `-total < part x total - whole x weight <
|
||||
//! total` at step one.
|
||||
//! of its exact share: `-total < part x total - whole x weight <=
|
||||
//! total` at step one. The upper bound is inclusive on `i64` (its
|
||||
//! division truncates); the bridge checks the strict `Decimal`
|
||||
//! bound.
|
||||
//! 3. No part is negative or above the whole for non-negative weights
|
||||
//! that do not exceed the total.
|
||||
//! 4. A zero total gives zeros; all-zero weights hand the whole out by
|
||||
@@ -30,17 +33,19 @@
|
||||
//! units as there are parts.
|
||||
//! 5. Overflow is `None`, never a panic.
|
||||
//! SCENARIOS:
|
||||
//! 1. IF 101 by 1/1/1 to the unit: SHOULD be 34/34/33 (the tied unit
|
||||
//! to the first), never 33/34/34.
|
||||
//! 1. IF 101 by 1/1/1 to the unit: SHOULD be 34/34/33 (the rounded
|
||||
//! remainders tie, so the units go to the earlier parts), never
|
||||
//! 33/34/34.
|
||||
//! 2. IF a quotient rounds up across the step: `share_floor_with`
|
||||
//! SHOULD still give the exact floor, by multiplication.
|
||||
//! 3. IF the product `whole x weight` is past `i64`: SHOULD be None.
|
||||
//! ```
|
||||
//!
|
||||
//! Bounds: amounts up to 1,000, weights up to 100, totals and steps fixed
|
||||
//! (`10`, `1`, `7`). The laws are about the shape of the split, not the
|
||||
//! magnitude; Lean proves them at any size and the bridge checks the
|
||||
//! `Decimal` engine.
|
||||
//! Bounds: amounts up to 1,000, weights up to 100, totals fixed (10 and
|
||||
//! 0), steps 1 and 10. The laws are about the shape of the split, not the
|
||||
//! magnitude; Lean proves them of the exact-share model at any size, and
|
||||
//! the bridge checks the `Decimal` engine, whose ranking uses the rounded
|
||||
//! quotient.
|
||||
|
||||
use crate::kernel::{self, Leftover, Rounding, share_floor_with, share_of, split_by_weights_into};
|
||||
|
||||
|
||||
Reference in new issue
Block a user