Definition and explanation
This explanation was written alongside the formalization to describe the statement and its reasoning.
Definition
+ is removed and records the optional Boolean sign
\operatorname{some}(\mathit{false}), while a leading ASCII - is
removed and records \operatorname{some}(\mathit{true}); either case returns
none when the remainder is empty and otherwise returns that exact nonempty
remainder as the body. Every other nonempty byte list is returned unchanged as
the body with no leading sign. Failed sign stripping classifies the input as
invalid. Successful sign stripping produces a nonempty body, the same optional
leading sign, and a source-valid Rust byte-slice carrier for exactly that body.
The original string's bytes are classified by a numeric lexeme x exactly
when there is a valid unsigned lexeme whose rendering is the body and whose
complete record becomes x upon replacing its absent leading sign by that
exact optional sign. They are classified by a special kind with an optional
sign exactly when that sign is the stripped sign and the body is the
corresponding unsigned special literal. Thus sign stripping preserves the
complete numeric, special, and invalid classification on precisely the
source-string domain: empty and sign-only inputs cannot invent a helper body,
whereas every other nonempty invalid input reaches the lexical helpers on the
exact body just described.nan or the infinity selected
by the separate sign argument for inf and infinity.
Conversely, each unsigned special literal has some returned value satisfying
its corresponding predicate; this existential does not choose one NaN
representation and equate it with all NaNs. When there is no unsigned special
literal, the parser returns none. A represented record is nonnegative,
has mantissa below 10^{19}, and either denotes the input's accumulated-
exponent magnitude when no digits were truncated or brackets that diagnostic
magnitude between the values obtained from its mantissa and from mantissa plus
one. A distinct target-preservation clause says that a nontruncated record has
the same rounding targets as the exact input and that agreement of the two
many-digit endpoint pairs gives an exact-input rounding target.Lean definition
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.DecimalGoalVocabularyDefault
import Tablet.SourceValidByteSlice
import Tablet.num_imp_dec2flt_common_BiasedFp
import Tablet.num_imp_dec2flt_decimal_Decimal
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: DispatchContracts]
structure DispatchContracts where
-- BODY
stripSign : List Nat -> Option (Option Bool × List Nat)
parseNumber : List Nat -> Option num.imp.dec2flt.decimal.Decimal
parseSpecial : List Nat -> Bool -> Option F64
native : num.imp.dec2flt.decimal.Decimal -> Option F64
incrementMantissa : Std.U64 -> Option Std.U64
integer : Std.I64 -> Std.U64 -> num.imp.dec2flt.common.BiasedFp
samePair : num.imp.dec2flt.common.BiasedFp ->
num.imp.dec2flt.common.BiasedFp -> Bool
forceDefer : num.imp.dec2flt.common.BiasedFp ->
num.imp.dec2flt.common.BiasedFp
slow : List Nat -> num.imp.dec2flt.common.BiasedFp
assemble : num.imp.dec2flt.common.BiasedFp -> F64
applySign : Bool -> F64 -> F64
recordRepresents : num.imp.dec2flt.decimal.Decimal -> DecimalLexeme -> Prop
flow : List Nat -> Option F64 -> Prop
stripSign_exact : ∀ s,
DecimalGoalVocabularyDefault.sourceString s ->
stripSign (DecimalGoalVocabularyDefault.bytes s) =
match DecimalGoalVocabularyDefault.bytes s with
| [] => none
| 43 :: body =>
if body = [] then none else some (some false, body)
| 45 :: body =>
if body = [] then none else some (some true, body)
| body => some (none, body)
stripSign_none : ∀ s,
DecimalGoalVocabularyDefault.sourceString s ->
stripSign (DecimalGoalVocabularyDefault.bytes s) = none ->
DecimalGoalVocabularyDefault.classifies
(DecimalGoalVocabularyDefault.bytes s) none
stripSign_some : ∀ s sign body,
DecimalGoalVocabularyDefault.sourceString s ->
stripSign (DecimalGoalVocabularyDefault.bytes s) = some (sign, body) ->
body ≠ [] ∧
(∃ bodySlice : Slice Std.U8,
SourceValidByteSlice bodySlice ∧
DecimalGoalVocabularyDefault.bytes bodySlice = body) ∧
(∀ x,
(DecimalGoalVocabularyDefault.classifies
(DecimalGoalVocabularyDefault.bytes s) (some (Sum.inl x)) ↔
∃ unsigned,
unsigned.leadingSign = none ∧
DecimalGoalVocabularyDefault.validNumeric unsigned ∧
DecimalGoalVocabularyDefault.renderNumeric unsigned = body ∧
x = { unsigned with leadingSign := sign })) ∧
(∀ specialSign nan,
(DecimalGoalVocabularyDefault.classifies
(DecimalGoalVocabularyDefault.bytes s)
(some (Sum.inr (specialSign, nan))) ↔
specialSign = sign ∧
DecimalGoalVocabularyDefault.specialLiteral body none nan))
parseNumber_spec : ∀ (body : Slice Std.U8) d,
SourceValidByteSlice body ->
body.val ≠ [] ->
(parseNumber (DecimalGoalVocabularyDefault.bytes body) = some d ↔
∃ x,
x.leadingSign = none ∧
DecimalGoalVocabularyDefault.validNumeric x ∧
DecimalGoalVocabularyDefault.renderNumeric x =
DecimalGoalVocabularyDefault.bytes body ∧
recordRepresents d x)
parseNumber_complete : ∀ (body : Slice Std.U8) x,
SourceValidByteSlice body ->
body.val ≠ [] ->
x.leadingSign = none ->
DecimalGoalVocabularyDefault.validNumeric x ->
DecimalGoalVocabularyDefault.renderNumeric x =
DecimalGoalVocabularyDefault.bytes body ->
∃ d,
parseNumber (DecimalGoalVocabularyDefault.bytes body) = some d ∧
recordRepresents d x
recordRepresents_spec : ∀ d x, recordRepresents d x ->
d.negative = false ∧ d.mantissa.val < 10 ^ 19 ∧
(if d.many_digits then
DecimalGoalVocabularyDefault.decimalMagnitude d <=
DecimalGoalVocabularyDefault.accumulatedMagnitude x ∧
DecimalGoalVocabularyDefault.accumulatedMagnitude x <
(((d.mantissa.val + 1 : Nat) : Real) *
(10 : Real) ^ d.exponent.val)
else
DecimalGoalVocabularyDefault.decimalMagnitude d =
DecimalGoalVocabularyDefault.accumulatedMagnitude x)
parseSpecial_sound : ∀ (body : Slice Std.U8) negative f,
SourceValidByteSlice body ->
parseSpecial (DecimalGoalVocabularyDefault.bytes body) negative = some f ->
∃ nan,
DecimalGoalVocabularyDefault.specialLiteral
(DecimalGoalVocabularyDefault.bytes body) none nan ∧
(if nan then DecimalGoalVocabularyDefault.isNan f
else DecimalGoalVocabularyDefault.isInfinity negative f)
parseSpecial_complete : ∀ (body : Slice Std.U8) negative nan,
SourceValidByteSlice body ->
DecimalGoalVocabularyDefault.specialLiteral
(DecimalGoalVocabularyDefault.bytes body) none nan ->
∃ f,
parseSpecial (DecimalGoalVocabularyDefault.bytes body) negative = some f ∧
(if nan then DecimalGoalVocabularyDefault.isNan f
else DecimalGoalVocabularyDefault.isInfinity negative f)
parseSpecial_reject : ∀ (body : Slice Std.U8) negative,
SourceValidByteSlice body ->
(¬ ∃ nan, DecimalGoalVocabularyDefault.specialLiteral
(DecimalGoalVocabularyDefault.bytes body) none nan) ->
parseSpecial (DecimalGoalVocabularyDefault.bytes body) negative = none
native_spec : ∀ d f, native d = some f ->
d.many_digits = false ∧
∃ magnitude,
DecimalGoalVocabularyDefault.roundsMagnitude
(DecimalGoalVocabularyDefault.decimalMagnitude d) magnitude ∧
magnitude.val < 2 ^ 63 ∧
f = applySign d.negative magnitude
incrementMantissa_spec : ∀ w,
w.val < 10 ^ 19 ->
∃ w', incrementMantissa w = some w' ∧ w'.val = w.val + 1
integer_spec : ∀ q w,
let fp := integer q w
fp.p_biased.val < 0 ∨
(0 <= fp.p_biased.val ∧ fp.p_biased.val <= 2047 ∧
DecimalGoalVocabularyDefault.roundsMagnitude
((w.val : Real) * (10 : Real) ^ q.val) (assemble fp) ∧
(assemble fp).val < 2 ^ 63)
samePair_spec : ∀ a b, samePair a b = true ↔ a = b
recordTarget_spec : ∀ d x, recordRepresents d x ->
(d.many_digits = false ->
∀ target,
(DecimalGoalVocabularyDefault.roundsMagnitude
(DecimalGoalVocabularyDefault.decimalMagnitude d) target ↔
DecimalGoalVocabularyDefault.roundsMagnitude
(DecimalGoalVocabularyDefault.exactMagnitude x) target)) ∧
(d.many_digits = true ->
∀ nextMantissa,
incrementMantissa d.mantissa = some nextMantissa ->
samePair (integer d.exponent d.mantissa)
(integer d.exponent nextMantissa) = true ->
DecimalGoalVocabularyDefault.roundsMagnitude
(DecimalGoalVocabularyDefault.exactMagnitude x)
(assemble (integer d.exponent d.mantissa)))
forceDefer_spec : ∀ fp,
(forceDefer fp).m = fp.m ∧ (forceDefer fp).p_biased.val = -1
slow_spec : ∀ (body : Slice Std.U8) x,
SourceValidByteSlice body ->
x.leadingSign = none ->
DecimalGoalVocabularyDefault.validNumeric x ->
DecimalGoalVocabularyDefault.renderNumeric x =
DecimalGoalVocabularyDefault.bytes body ->
let fp := slow (DecimalGoalVocabularyDefault.bytes body)
0 <= fp.p_biased.val ∧ fp.p_biased.val <= 2047 ∧
DecimalGoalVocabularyDefault.roundsMagnitude
(DecimalGoalVocabularyDefault.accumulatedMagnitude x) (assemble fp) ∧
(assemble fp).val < 2 ^ 63
slowTarget_spec : ∀ (body : Slice Std.U8) x,
SourceValidByteSlice body ->
x.leadingSign = none ->
DecimalGoalVocabularyDefault.validNumeric x ->
DecimalGoalVocabularyDefault.renderNumeric x =
DecimalGoalVocabularyDefault.bytes body ->
DecimalGoalVocabularyDefault.roundsMagnitude
(DecimalGoalVocabularyDefault.exactMagnitude x)
(assemble (slow (DecimalGoalVocabularyDefault.bytes body)))
assembly_spec : ∀ fp,
DecimalGoalVocabularyDefault.assembledWord fp (assemble fp)
sign_spec : ∀ negative magnitude, magnitude.val < 2 ^ 63 ->
DecimalGoalVocabularyDefault.signedMagnitude
negative magnitude (applySign negative magnitude)
flow_spec : ∀ s out,
DecimalGoalVocabularyDefault.sourceString s ->
(flow (DecimalGoalVocabularyDefault.bytes s) out ↔
match stripSign (DecimalGoalVocabularyDefault.bytes s) with
| none => out = none
| some (sign, body) =>
let negative : Bool := decide (sign = some true)
match parseNumber body with
| none => out = parseSpecial body negative
| some parsed =>
let signedParsed := { parsed with negative := negative }
match native signedParsed with
| some f => out = some f
| none =>
let first := integer parsed.exponent parsed.mantissa
let secondGuard : Bool :=
parsed.many_digits && decide (0 <= first.p_biased.val)
let postComparison :=
if secondGuard then
match incrementMantissa parsed.mantissa with
| none => forceDefer first
| some nextMantissa =>
let second := integer parsed.exponent nextMantissa
if samePair first second then first else forceDefer first
else first
let selected :=
if decide (postComparison.p_biased.val < 0) then slow body
else postComparison
out = some (applySign negative (assemble selected)))
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
f64 dispatcher. The laws distinguish numeric completeness from
per-result correctness; special per-result soundness from existential
completeness and rejection; and record, target, native, integer, fallback,
assembly, and sign properties from one another. These are conditions on every
package value, not claims already established for the extracted helpers.
Agreement of the actual helpers with a package, their normal returns, and their
satisfaction of all those laws remain precisely the separate
dispatch_component_compliance obligation.Proof
str is UTF-8 and has
length at most isize::MAX; after removal of at most one leading byte,
the remaining source subslice still satisfies the length bound. Helper inputs
need not themselves be UTF-8. This is exactly the distinction expressed by
SourceValidByteSlice.stripSign_some law supplies both \mathit{body}\ne[] and a
source-valid body-slice witness whose bytes are exactly \mathit{body},
together with the two classification equivalences. The byte observation in
DecimalGoalVocabularyDefault maps every represented slice element
and therefore preserves list length. Thus equality of the witness's observed
bytes with the nonempty \mathit{body} implies that the witness's carrier list
is nonempty. Because invalid classification in
DecimalGoalVocabularyDefault excludes every numeric and special
classification, those equivalences exclude both a valid unsigned numeric
lexeme rendering \mathit{body} and an unsigned special-literal witness on
\mathit{body}.parseNumber on that body. If it
were some of a record, parseNumber_spec, applied to the
body-slice witness with the just-established nonemptiness premise, would
produce a valid unsigned numeric lexeme rendering that body, contradicting the
preceding exclusion. Hence it is none.
The absence of an unsigned special witness and
parseSpecial_reject then give none for the special parser at
the Boolean sign determined from \mathit{sign}. Substitution in
flow_spec gives the abstract invalid result. If sign stripping is
none, stripSign_none gives invalid classification and
flow_spec gives the same abstract result directly. Thus this
derivation holds for every package satisfying its laws; it neither proves a
normal return by the extracted dispatcher nor proves that the extracted
helpers satisfy those laws.Requirement: parser totality
flow_spec exposes an output in every abstract branch on the full source-string domain. This relational totality does not establish normal termination of the extracted dispatcher; that requires the separate concrete-compliance argument.Requirement: parser numeric acceptance
parseNumber_complete place a valid numeric body in the numeric arm of the explicit flow. Agreement and normal return of the extracted numeric parser and dispatcher remain concrete-compliance obligations.Requirement: parser invalid rejection
stripSign_some, then uses invalid classification, the two classification equivalences, a case split on parseNumber, parseNumber_spec, parseSpecial_reject on its unchanged all-slices domain, and flow_spec to obtain that same abstract result. It does not assume that the concrete helpers comply or that the extracted dispatcher returns normally with Err.Requirement: parser nan acceptance
flow_spec returns it directly, without selecting a NaN representation in advance or invoking raw-pair assembly. Concrete parser agreement is not supplied by this definition.Requirement: parser infinity
Requirement: parser non nan results
Requirement: parser numeric sign
Requirement: parser signed zero
Requirement: parser exact rounding
Requirement: parser selected exponent
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
parseNumber_complete requires the abstract operation to return some record for every unsigned numeric body. It identifies the applicable contract clause but does not establish normal return or that parse_number equals that operation.Requirement: number helper rejection
parseNumber and applying parseNumber_spec rules out a some result on a nonnumeric nonempty source-valid slice, without adding UTF-8. Equality and normal return of the extracted numeric helper remain concrete-compliance obligations.Requirement: number helper record bounds
parseNumber_spec turns an abstract returned record into a representation witness and recordRepresents_spec gives false sign and the strict 10^{19} bound. Applying this chain to an extracted return requires the separate equality promised by compliance.Requirement: number helper accumulated value
Requirement: special helper infinity
parseSpecial_complete requires an abstract returned infinity with the separate sign argument, while soundness constrains abstract successful results. This identifies the package clauses; it does not prove the extracted special helper's normal return or agreement.Requirement: special helper nan
parseSpecial_complete requires some abstract NaN result and soundness constrains returned values without equating all NaN representations. Concrete helper satisfaction remains separate.Requirement: special helper rejection
none outside all three unsigned keywords on the source-valid byte-slice domain. It does not itself establish that result for the extracted helper.Requirement: native correct or defer
some result to a nontruncated record-value rounding with sign factored through applySign; none remains deferral. Its application to a normal extracted native return depends on concrete compliance.Requirement: integer correct or defer
Requirement: slow accumulated rounding
slow_spec constrains the abstract slow operation on the unchanged full body to the accumulated-value target and a separately assembled magnitude. Normal return and equality for the extracted slow helper remain concrete-compliance obligations.Requirement: assembly correspondence
Requirement: classification totality
Requirement: classification determinism
Requirement: classification significand digit
Requirement: rounding totality
Requirement: rounding determinism
Requirement: exponent value agreement
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
Inspect related source (44)
- BiasedFp · dec2flt/common.rs:52 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- from_u64 · dec2flt/mod.rs:263 Program Rust
More program dependencies (11)
- 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
- ByteSlice · dec2flt/common.rs:4 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:21 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
Technical checking records
Local closure summary
{
"node": "DispatchContracts",
"closure_version": "patch_c_v1",
"active_decl_hash": "e3f19f87dee10ae3d7189fb30eb9240c48a532a5115b4c7fd807f00367824862",
"active_statement_hash": "67a5f6c557d48dd5fa20604f2e713035daa41ffa492f88885218dfbcdb110322",
"kernel_axioms": [
"Classical.choice",
"Quot.sound",
"propext"
],
"toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
"lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
"checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
"approved_axioms_hash": "d5c04ffa333d9b33b238a527f5beaa2be82e021d3e9c0bbe01b1310280f7f55a",
"axcheck_status": "Agreed",
"accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-15",
"boundary_theorems": {},
"strict_theorem_deps": {},
"strict_definition_deps": {
"DecimalGoalVocabulary": "af7cd54e9bf14dcd",
"DecimalGoalVocabularyDefault": "512f8d0aea894250",
"DecimalLexeme": "250be645520aec86",
"F64": "ec4e25fbaf4e11d4",
"SourceValidByteSlice": "3dc42716a6378d26",
"num_imp_dec2flt_common_BiasedFp": "c43614ff2149ecf2",
"num_imp_dec2flt_decimal_Decimal": "63fd2f021dd0ef41"
}
}Prose assessment
{
"label": "Recorded Sound: VerifierPass",
"assessment_status": "VerifierPass",
"fingerprint_relation": "matches current fingerprint",
"assessment_fingerprint": "preservation-v1:acce2e30ea7c3eb121d3a63eed12bb12df89495e08960d042186d87c2c64f3d9",
"current_fingerprint": "preservation-v1:acce2e30ea7c3eb121d3a63eed12bb12df89495e08960d042186d87c2c64f3d9",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"sound_status": "Pass",
"substantiveness_status": "Pass"
}