Definition and explanation
This explanation was written alongside the formalization to describe the statement and its reasoning.
Definition · Decimal-sequence fractional finalization
rest and an arbitrary modeled
decimal-sequence record d, DecimalSeqFractionalFinish is the
following checked monadic computation. It subtracts
|\texttt{rest}| from |s| and passes the resulting consumed count
to the extracted trailing-zero counter on s. It casts the returned
trailing count to I32 and adds it to
d.\texttt{decimal\_point}; subtracts trailing from
d.\texttt{num\_digits} to obtain kept; casts kept to I32
and adds it to the intermediate point; and then selects
rest and the resulting
point. Finally it runs the extracted parser loop~1 on d.\texttt{digits}
over the half-open array-index interval [\texttt{nDigits},19), setting
exactly those cells to zero and leaving every other cell unchanged, and
returns the record made from nDigits, the exponent-adjusted point,
flag, and that array. Each failed or divergent checked operation is
propagated by its monadic bind.Lean definition
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.DecimalSeqExponentEval
import Tablet.num_imp_dec2flt_decimal_seq_parse_decimal_seq
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: DecimalSeqFractionalFinish]
def DecimalSeqFractionalFinish (s rest : Slice Std.U8)
(d : num.imp.dec2flt.decimal_seq.DecimalSeq) :
Result num.imp.dec2flt.decimal_seq.DecimalSeq :=
-- BODY
do
let consumed <- Slice.len s - Slice.len rest
let trailing <-
num.imp.dec2flt.decimal_seq.count_trailing_zeros s consumed
let p1 <- d.decimal_point + UScalar.hcast .I32 trailing
let kept <- d.num_digits - trailing
let point <- p1 + UScalar.hcast .I32 kept
let (nDigits, flag) <-
if kept > num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
then ok (num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS, true)
else ok (kept, d.truncated)
let finalPoint <- DecimalSeqExponentEval rest point
let a <- num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop1
{ start := nDigits,
«end» :=
num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW }
d.digits
ok (num.imp.dec2flt.decimal_seq.DecimalSeq.mk nDigits finalPoint flag a)
end dec2flt_model
Preservation and explanation
Natural-language argument
The status above describes the Lean proof. Its explanatory prose may remain a sketch after that proof closes.
Explanatory prose status
Prose retained as authored. The explanatory prose is preserved as it stood when captured.
Preservation argument
Claim
crate/dec2flt/decimal_seq.rs:320--363 after the integral and optional
fractional scans. Let s_0 be the exact original source slice stored as
start, let r be the exact current residual suffix stored as
s, and let d be the exact post-scan DecimalSeq. On the
branch d.\texttt{num_digits}\ne0, the remainder of that source execution is
exactly DecimalSeqFractionalFinish(s_0,r,d): it has the same final
record on normal return and fails at the same modeled checked operation on an
abnormal return. No claim is made that the source invokes this finalization
from an arbitrary state with zero digit count.Proof
parse_decimal_seq declaration
num imp dec2flt decimal seq parse decimal seq.consumed_len to
|s_0|-|r|. The definition binds the same Usize subtraction
Slice.len s_0- Slice.len r. Since r is the exact
residual suffix of this execution, |r|\le |s_0| on every source-reachable
state. At the model level the two fragments still use the same checked
subtraction, so an underflow, if presented outside that source invariant,
would be the same first propagated failure rather than a different result.consumed_len-1, …, 0 in the same order as the original
iter().rev() loop, increments exactly on ASCII zero, passes over a
decimal point, and stops at the first byte that is neither zero nor point.
Thus its Usize result is exactly the source value
n_trailing_zeros; a helper failure is bound and returned before any
record update on both model fragments.u as i32 and Aeneas's pure
UScalar.hcast .I32 u both compute exactly
\operatorname{cast32}(u); this operation truncates and cannot fail (the
lift surrounding it in the pinned parser merely places that pure
value in the Result computation). Thus both fragments first perform
the same checked I32 addition
d.\texttt{decimal_point}+\operatorname{cast32}(z), which either fails on
both sides or produces the same intermediate point. They next perform the
same checked Usize subtraction d.\texttt{num_digits}-z; if it succeeds, call
its Usize result k. Both then compute the identical pure value
\operatorname{cast32}(k) and perform the same checked I32 addition to the
intermediate point. Consequently, whenever both additions and the
subtraction succeed, the uncapped point on each side is the I32 value
d.\texttt{decimal_point}+\operatorname{cast32}(z)
+\operatorname{cast32}(k); subtraction and addition failures coincide, and
neither narrowing cast contributes a failure.truncated to true. In the false
branch both retain k and preserve d.\texttt{truncated}. This establishes
the same pair (n,f) of stored digit count and flag, including the equality
case k=768.Slice.is_empty result is saved across finalization. After a
decimal point, the two copies (according as the pre-fractional digit count is
zero or nonzero) use the post-scan residual s_6 or s_5 and test it after
finalization. In the remaining nonempty, non-decimal-point copy, the parser
saves both the false emptiness result and the byte s_2[0] across
finalization. In every copy, the intervening consumed-length computation,
trailing-zero scan, casts, arithmetic, cap test, and flag update only read the
residual slice; none changes that slice. Thus the argument r passed to the
factoring is respectively that same s_2, s_6, s_5, or s_2.Slice.is_empty is total and returns
the deterministic test of whether the slice length is zero. Recomputing it
on the unchanged r therefore returns the parser's saved Boolean in the
first and fourth copies, and is the identical test already made by the parser
in the two post-decimal copies. In the empty case both computations take the
empty branch and neither indexes r. In every nonempty case, index zero is
in bounds; Slice.index_usize therefore succeeds deterministically
and returns the same byte, including the byte saved by the outer parser in
the fourth copy. Hence the factoring's extra emptiness and index observations
cannot fail or diverge, and both sides select the same nonmarker,
lowercase-e, or uppercase-E branch.MAX_DIGITS_WITHOUT_OVERFLOW and writes zero to each selected digit
cell. Aeneas duplicated this one source loop across control-flow branches as
parse_decimal_seq_loop1, loop4, loop6, and
loop7 in the pinned node; their range iterator, array update, state,
and exit bodies are identical. The factoring calls loop1 with the
same range and original d.\texttt{digits}, and hence produces exactly the
same filled array a, or propagates the same range/array failure at the same
iteration. When all binds succeed, both computations construct
DecimalSeq.mk with fields
num_digits=n, decimal_point=p,
truncated=f, and digits=a. Monadic short-circuiting
also shows that any earlier failure prevents this construction on both sides.
This proves equality of normal and failure behavior precisely on the source's
nonzero-digit post-scan branch, while making no assertion about source use at
zero count.Requirement: parser totality
Requirement: parser numeric acceptance
parse_decimal_seq. The definition adds no grammar condition and assumes no acceptance result.Requirement: parser invalid rejection
Requirement: parser nan acceptance
Requirement: parser infinity
parse_decimal_seq. This factoring changes neither their keyword path nor their lexical sign.Requirement: parser non nan results
Requirement: parser numeric sign
Requirement: parser signed zero
Requirement: parser exact rounding
Requirement: parser selected exponent
DecimalSeq or the identical prior failure. No biased-exponent range fact is inserted as a premise.Requirement: parser selected magnitude sign
Requirement: dispatch abstract composition
Requirement: dispatch component compliance
Requirement: parser accumulated rounding
Requirement: parser equal target rounding
Requirement: number helper acceptance
parse_number returns a Decimal before the optional slow decimal-sequence conversion and never calls this finalizer. Its nonempty-slice domain and Some cases are unaffected.Requirement: number helper rejection
None decision precedes and is independent of parse_decimal_seq. A definition over DecimalSeq states no new condition on that decision.Requirement: number helper record bounds
Decimal, whereas this definition consumes and constructs DecimalSeq. It cannot change the returned mantissa, negative flag, or 10^{19} bound.Requirement: number helper accumulated value
parse_number record. Post-scan trailing-zero and array finalization occurs only later on the slow path and leaves that record untouched.Requirement: special helper infinity
parse_inf_nan neither produces nor consumes a DecimalSeq. Its keyword bytes, separate sign argument, and infinity result are noninterfering.Requirement: special helper nan
Requirement: special helper rejection
None cases remain identical.Requirement: native correct or defer
try_fast_path operates directly on the Decimal record and runs before slow decimal-sequence parsing. This finalizer changes neither a native-path Some value nor a deferral.Requirement: integer correct or defer
compute_float accepts scalar exponent and mantissa arguments and does not observe any DecimalSeq array. Its returned or deferred BiasedFp is unaffected.Requirement: slow accumulated rounding
parse_long_mantissa calls parse_decimal_seq and receives precisely the final record factored here on the actual nonzero branch, with the zero branch preserved separately. No premise is added to unsigned numeric inputs, and no rounding result is assumed.Requirement: assembly correspondence
biased_fp_to_float consumes only a completed raw pair, not a source slice, residual, or decimal digit array. This finalizer cannot alter the assembly formula quantified over all field values.Requirement: classification totality
Requirement: classification determinism
Requirement: classification significand digit
Requirement: rounding totality
Requirement: rounding determinism
DecimalSeq. Its real input and binary64 comparison relation remain unchanged.Requirement: exponent value agreement
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Inspect related source (77)
- parse_decimal_seq · dec2flt/decimal_seq.rs:283 Program Rust
- parse_decimal_seq_loop0 · dec2flt/decimal_seq.rs:290 Program Rust
- body · dec2flt/decimal_seq.rs:290 Program Rust
More program dependencies (44)
- parse_decimal_seq_loop1 · dec2flt/decimal_seq.rs:361 Program Rust
- body · dec2flt/decimal_seq.rs:361 Program Rust
- parse_decimal_seq_loop2 · dec2flt/decimal_seq.rs:303 Program Rust
- body · dec2flt/decimal_seq.rs:303 Program Rust
- parse_decimal_seq_loop3 · dec2flt/decimal_seq.rs:307 Program Rust
- body · dec2flt/decimal_seq.rs:307 Program Rust
- parse_decimal_seq_loop4 · dec2flt/decimal_seq.rs:361 Program Rust
- body · dec2flt/decimal_seq.rs:361 Program Rust
- parse_decimal_seq_loop5 · dec2flt/decimal_seq.rs:307 Program Rust
- body · dec2flt/decimal_seq.rs:307 Program Rust
- parse_decimal_seq_loop6 · dec2flt/decimal_seq.rs:361 Program Rust
- body · dec2flt/decimal_seq.rs:361 Program Rust
- parse_decimal_seq_loop7 · dec2flt/decimal_seq.rs:361 Program Rust
- body · dec2flt/decimal_seq.rs:361 Program Rust
- read_u64 · dec2flt/common.rs:18 Program Rust
- write_u64 · dec2flt/common.rs:25 Program Rust
- is_8digits · dec2flt/common.rs:40 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:21 Program Rust
- default · dec2flt/decimal_seq.rs:33 Program Rust
- MAX_DIGITS · dec2flt/decimal_seq.rs:63 Program Rust
- MAX_DIGITS_WITHOUT_OVERFLOW · dec2flt/decimal_seq.rs:66 Program Rust
- count_trailing_zeros · dec2flt/decimal_seq.rs:235 Program Rust
- count_trailing_zeros_loop · dec2flt/decimal_seq.rs:239 Program Rust
- body · dec2flt/decimal_seq.rs:239 Program Rust
- parse_decimal_exponent · dec2flt/decimal_seq.rs:269 Program Rust
- parse_decimal_exponent_loop · dec2flt/decimal_seq.rs:272 Program Rust
- body · dec2flt/decimal_seq.rs:272 Program Rust
- parse_digits_into_seq · dec2flt/decimal_seq.rs:256 Program Rust
- parse_digits_into_seq_loop · dec2flt/decimal_seq.rs:258 Program Rust
- body · dec2flt/decimal_seq.rs:258 Program Rust
- from_u64 · dec2flt/mod.rs:263 Program Rust
- FloatErrorKind · num/mod.rs:18 Program Rust
- ParseFloatError · num/mod.rs:13 Program Rust
- Dec2FltAssemblyTrace · dec2flt/mod.rs:329 Program Rust
- Dec2FltTrace · dec2flt/mod.rs:295 Program Rust
- Lemire · dec2flt/mod.rs:115 Program Rust
- BiasedFp · dec2flt/common.rs:52 Program Rust
- ByteSlice · dec2flt/common.rs:4 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- try_add_digit · dec2flt/decimal_seq.rs:73 Program Rust
- CastInto · traits.rs:18 Program Rust
- Float · traits.rs:74 Program Rust
- FloatExt · traits.rs:170 Program Rust
- Int · traits.rs:27 Program Rust
Standard-library dependencies (30)
- clone · core/src/clone.rs:698 Rust library
- div · core/src/ops/arith.rs:515 Rust library
- mul · core/src/ops/arith.rs:350 Rust library
- neg · core/src/ops/arith.rs:719 Rust library
- bitand · core/src/ops/bit.rs:178 Rust library
- bitor · core/src/ops/bit.rs:282 Rust library
- shl · core/src/ops/bit.rs:489 Rust library
- shr · core/src/ops/bit.rs:612 Rust library
- EXPONENT_MASK · core/src/num/f64.rs:615 Rust library
- INFINITY · core/src/num/f64.rs:512 Rust library
- MANTISSA_DIGITS · core/src/num/f64.rs:412 Rust library
- MANTISSA_MASK · core/src/num/f64.rs:637 Rust library
- NAN · core/src/num/f64.rs:509 Rust library
- NEG_INFINITY · core/src/num/f64.rs:515 Rust library
- classify · core/src/num/f64.rs:782 Rust library
- from_bits · core/src/num/f64.rs:1269 Rust library
- to_bits · core/src/num/f64.rs:1223 Rust library
- is_ascii_digit · core/src/num/mod.rs:958 Rust library
- from_residual · core/src/option.rs:2793 Rust library
- branch · core/src/option.rs:2779 Rust library
- first · core/src/slice/mod.rs:155 Rust library
- split_first · core/src/slice/mod.rs:198 Rust library
- as_bytes · core/src/str/mod.rs:498 Rust library
- FpCategory · core/src/num/mod.rs:1522 Rust library
- Div · core/src/ops/arith.rs:460 Rust library
- Mul · core/src/ops/arith.rs:322 Rust library
- Neg · core/src/ops/arith.rs:690 Rust library
- BitOr · core/src/ops/bit.rs:254 Rust library
- Shl · core/src/ops/bit.rs:461 Rust library
- Shr · core/src/ops/bit.rs:584 Rust library
Related source and models come from the extraction records and declared dependencies.
Proof assumptions and review
Lean checks the formal proof. Trellis also reviews how the statement corresponds to the intended requirement.
Transitive assumptions
- Classical.choice
- Quot.sound
- propext
This list combines the assumptions recorded for this declaration and its dependencies. It may include assumptions used by auxiliary declarations in those modules.
Helper theorems included
- DecimalSeqExponentEval
- DecimalSeqFractionalFinish
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice write u64
- num imp dec2flt common is 8digits
- num imp dec2flt decimal seq DecimalSeq
All 14 entries
- DecimalSeqExponentEval
- DecimalSeqFractionalFinish
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice write u64
- num imp dec2flt common is 8digits
- num imp dec2flt decimal seq DecimalSeq
- num imp dec2flt decimal seq DecimalSeq Insts CoreDefaultDefault default
- num imp dec2flt decimal seq DecimalSeq MAX DIGITS
- num imp dec2flt decimal seq DecimalSeq MAX DIGITS WITHOUT OVERFLOW
- num imp dec2flt decimal seq DecimalSeq try add digit
- num imp dec2flt decimal seq count trailing zeros
- num imp dec2flt decimal seq parse decimal exponent
- num imp dec2flt decimal seq parse decimal seq
- num imp dec2flt decimal seq parse digits into seq
Technical checking records
Local closure summary
{
"node": "DecimalSeqFractionalFinish",
"closure_version": "patch_c_v1",
"active_decl_hash": "8f5b2adac8306a1da3c84006295dd69c558681e78129bcd2abc74195d8e5d96b",
"active_statement_hash": "c963c56b92bb36ace1752c59ce61ef8fe36f9c1a533bb3ebd435fe2843e8feac",
"kernel_axioms": [
"Classical.choice",
"Quot.sound",
"propext"
],
"toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
"lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
"checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
"approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
"axcheck_status": "Agreed",
"accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-170",
"boundary_theorems": {},
"strict_theorem_deps": {},
"strict_definition_deps": {
"DecimalSeqExponentEval": "b51b6389c17b6c1f",
"num_imp_dec2flt_decimal_seq_DecimalSeq": "59bf1ff9fe88fa8d",
"num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS": "39f6cb231ef80388",
"num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS_WITHOUT_OVERFLOW": "65634ac95536dcca",
"num_imp_dec2flt_decimal_seq_count_trailing_zeros": "7a77bc9e01c1a09b",
"num_imp_dec2flt_decimal_seq_parse_decimal_seq": "9f2c4f5675cad683"
}
}Prose assessment
{
"label": "Recorded Sound: VerifierPass",
"assessment_status": "VerifierPass",
"fingerprint_relation": "matches current fingerprint",
"assessment_fingerprint": "preservation-v1:883578e52dffe87c7be56336f6809c86e9b47be5df03e0a53d1805c01d74a482",
"current_fingerprint": "preservation-v1:883578e52dffe87c7be56336f6809c86e9b47be5df03e0a53d1805c01d74a482",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"sound_status": "Pass",
"substantiveness_status": "Pass"
}