Definition and explanation
This explanation was written alongside the formalization to describe the statement and its reasoning.
Definition
Str is source-valid
exactly when its byte list has length at most
\mathtt{isize::MAX}=9223372036854775807 and is the UTF-8 encoding of a Lean
string. A numeric
lexeme has an optional minus or plus sign and is valid exactly when every
recorded digit is in 0,\ldots,9, at least
one digit occurs on either side of the optional point, and a present exponent
has at least one digit. Rendering uses ASCII, an optional leading sign, the
recorded optional point, and an optional e/E exponent with
its optional sign. Special literals are optionally signed
inf, infinity, or nan, ASCII case-insensitively.
Classification is numeric with its complete lexeme, special with its sign and
kind, or invalid exactly when neither grammar matches.Decimal has magnitude \mathit{mantissa}\,10^{\mathit{exponent}}.BiasedFp assembly is the low 64 bits of the
mantissa OR the Rust two's-complement i32-to-u64 cast of the
biased exponent shifted left by 52.Lean definition
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.DecimalGoalVocabulary
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: DecimalGoalVocabularyDefault]
noncomputable def DecimalGoalVocabularyDefault : DecimalGoalVocabulary :=
-- BODY
let signBytes := fun sign : Option Bool =>
match sign with | none => [] | some negative => [if negative then 45 else 43]
let digitByte := fun d : Nat => 48 + d
let allDigits := fun ds : List Nat => ∀ d ∈ ds, d < 10
let validNumeric := fun x : DecimalLexeme =>
allDigits x.integerDigits ∧
(match x.fractionDigits with | none => True | some ds => allDigits ds) ∧
(x.integerDigits ≠ [] ∨
match x.fractionDigits with | none => False | some ds => ds ≠ []) ∧
(match x.exponent with | none => True | some (_, _, ds) => ds ≠ [] ∧ allDigits ds)
let renderNumeric := fun x : DecimalLexeme =>
signBytes x.leadingSign ++ x.integerDigits.map digitByte ++
(match x.fractionDigits with | none => [] | some ds => 46 :: ds.map digitByte) ++
(match x.exponent with
| none => []
| some (upper, sign, ds) =>
(if upper then 69 else 101) ::
(match sign with | none => [] | some neg => [if neg then 45 else 43]) ++
ds.map digitByte)
let asciiCaseEq := fun xs ys : List Nat =>
List.Forall₂ (fun actual lower => actual = lower ∨ actual + 32 = lower) xs ys
let specialLiteral := fun bs : List Nat => fun sign : Option Bool => fun nan : Bool =>
∃ body, bs = signBytes sign ++ body ∧
if nan then asciiCaseEq body [110, 97, 110]
else asciiCaseEq body [105, 110, 102] ∨
asciiCaseEq body [105, 110, 102, 105, 110, 105, 116, 121]
let numericLiteral := fun bs : List Nat => fun x : DecimalLexeme =>
validNumeric x ∧ renderNumeric x = bs
let classifies := fun bs : List Nat =>
fun c : Option (Sum DecimalLexeme (Option Bool × Bool)) =>
match c with
| some (Sum.inl x) => numericLiteral bs x
| some (Sum.inr (sign, nan)) => specialLiteral bs sign nan
| none => (¬ ∃ x, numericLiteral bs x) ∧ (¬ ∃ sign nan, specialLiteral bs sign nan)
let digitsValue : List Nat -> Nat :=
fun ds => ds.foldl (fun (n d : Nat) => 10 * n + d) 0
let exponentValue := fun x : DecimalLexeme =>
match x.exponent with
| none => 0
| some (_, sign, ds) =>
let n : Int := digitsValue ds
match sign with | some true => -n | _ => n
let accumulatedExponentValue := fun x : DecimalLexeme =>
match x.exponent with
| none => 0
| some (_, sign, ds) =>
let n : Nat := ds.foldl
(fun (n d : Nat) => if n < 65536 then 10 * n + d else n) 0
match sign with | some true => -(n : Int) | _ => (n : Int)
let fractionCount := fun x : DecimalLexeme =>
match x.fractionDigits with | none => 0 | some ds => ds.length
let significandDigits := fun x : DecimalLexeme =>
x.integerDigits ++ match x.fractionDigits with | none => [] | some ds => ds
let magnitudeWithExponent := fun x : DecimalLexeme => fun e : Int =>
(digitsValue (significandDigits x) : Real) *
(10 : Real) ^ (e - (fractionCount x : Int))
let signBit : Nat := 2 ^ 63
let fractionUnit : Nat := 2 ^ 52
let infinityBits : Nat := 2047 * fractionUnit
let finiteMagnitudeValue := fun bits : Nat =>
let e := bits / fractionUnit
let m := bits % fractionUnit
if e = 0 then
(m : Real) / ((2 : Real) ^ (1074 : Nat))
else if 1075 <= e then
((fractionUnit + m : Nat) : Real) * ((2 : Real) ^ (e - 1075))
else
((fractionUnit + m : Nat) : Real) / ((2 : Real) ^ (1075 - e))
let overflowThreshold : Real :=
((2 : Real) ^ (1024 : Nat)) - ((2 : Real) ^ (970 : Nat))
let roundsMagnitude := fun x : Real => fun w : F64 =>
0 <= x ∧ w.val <= infinityBits ∧
if w.val = infinityBits then overflowThreshold <= x
else x < overflowThreshold ∧
∀ v : F64, v.val < infinityBits -> v ≠ w ->
abs (x - finiteMagnitudeValue w.val) <= abs (x - finiteMagnitudeValue v.val) ∧
(abs (x - finiteMagnitudeValue w.val) = abs (x - finiteMagnitudeValue v.val) ->
w.val % 2 = 0)
{
bytes := fun s => s.val.map (fun b => b.val)
sourceString := fun s => s.val.length <= 9223372036854775807 ∧
∃ t : String, s.val.map (fun b => b.val) = t.toUTF8.toList.map UInt8.toNat
validNumeric := validNumeric
renderNumeric := renderNumeric
lexicalNegative := fun x => x.leadingSign = some true
specialLiteral := specialLiteral
classifies := classifies
mathExplicitExponent := exponentValue
accumulatedExplicitExponent := accumulatedExponentValue
exactMagnitude := fun x => magnitudeWithExponent x (exponentValue x)
accumulatedMagnitude := fun x => magnitudeWithExponent x (accumulatedExponentValue x)
decimalMagnitude := fun d => (d.mantissa.val : Real) * (10 : Real) ^ d.exponent.val
roundsMagnitude := roundsMagnitude
isNan := fun w =>
(w.val % signBit) / fractionUnit = 2047 ∧ w.val % fractionUnit ≠ 0
isInfinity := fun negative w =>
w.val = infinityBits + if negative then signBit else 0
isNegative := fun w => signBit <= w.val
signedMagnitude := fun negative magnitude result =>
magnitude.val < signBit ∧ result.val = magnitude.val + if negative then signBit else 0
assembledWord := fun fp w =>
w.val = Nat.lor fp.m.val
(((fp.p_biased.val.emod (2 ^ 64)).toNat * (2 ^ 52)) % (2 ^ 64))
}
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
BiasedFp field values.Proof
str representation conditions recorded in
reference/model-evidence/source-valid-byte-slice.txt. The numeric
renderer is a literal transcription of the grammar in GOAL.md:
its validity conditions require a significand digit and exponent digit when
needed, and rendering admits no whitespace or trailing bytes. The special
relation compares each ASCII letter with exactly its upper- or lowercase form.
The accumulated fold is the condition and update in
reference/model-evidence/goal-vocabulary.txt; the mathematical
fold never saturates. The binary64 formulas include subnormals, both midpoint
tie cases through low-bit parity, and the standard overflow midpoint. Word
classification uses the fixed 11-bit exponent and 52-bit fraction fields.
Assembly uses modulo 2^{64} for the Rust signed cast and left shift, followed
by bitwise OR, exactly matching the source expression for every field value.Requirement: parser totality
Requirement: parser numeric acceptance
Requirement: parser invalid rejection
Requirement: parser nan acceptance
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
Requirement: number helper rejection
Requirement: number helper record bounds
Requirement: number helper accumulated value
Requirement: special helper infinity
Requirement: special helper nan
Requirement: special helper rejection
Requirement: native correct or defer
Requirement: integer correct or defer
Requirement: slow accumulated rounding
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.
Used by
- AssemblyCorrespondence
- ClassificationDeterminism
- ClassificationSignificandDigit
- ClassificationTotality
- DispatchAbstractComposition
- DispatchComponentCompliance
All 33 entries
- AssemblyCorrespondence
- ClassificationDeterminism
- ClassificationSignificandDigit
- ClassificationTotality
- DispatchAbstractComposition
- DispatchComponentCompliance
- DispatchContracts
- ExponentValueAgreement
- IntegerCorrectOrDefer
- NativeCorrectOrDefer
- NumberHelperAcceptance
- NumberHelperAccumulatedValue
- NumberHelperRecordBounds
- NumberHelperRejection
- ParserAccumulatedRounding
- ParserEqualTargetRounding
- ParserExactRounding
- ParserInfinity
- ParserInvalidRejection
- ParserNanAcceptance
- ParserNonNanResults
- ParserNumericAcceptance
- ParserNumericSign
- ParserSelectedExponent
- ParserSelectedMagnitudeSign
- ParserSignedZero
- ParserTotality
- RoundingDeterminism
- RoundingTotality
- SlowAccumulatedRounding
- SpecialHelperInfinity
- SpecialHelperNan
- SpecialHelperRejection
Inspect related source (44)
- BiasedFp · dec2flt/common.rs:52 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- from_u64 · dec2flt/mod.rs:260 Program Rust
More program dependencies (11)
- FloatErrorKind · num/mod.rs:18 Program Rust
- ParseFloatError · num/mod.rs:13 Program Rust
- Dec2FltAssemblyTrace · dec2flt/mod.rs:326 Program Rust
- Dec2FltTrace · dec2flt/mod.rs:292 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": "DecimalGoalVocabularyDefault",
"closure_version": "patch_c_v1",
"active_decl_hash": "0fc3bc42a98cddc7f4b8e735912575cad8fa52d17b4459a1f5856fc044078e9b",
"active_statement_hash": "1f4a57e3e6bcced640f91efb7b2bc986c4ab343cf4b9b69c33e8f0e53f3ca9a7",
"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-18",
"boundary_theorems": {},
"strict_theorem_deps": {},
"strict_definition_deps": {
"DecimalGoalVocabulary": "0717fd246d7ea78a",
"DecimalLexeme": "303e59678842cea4",
"F64": "ec4e25fbaf4e11d4",
"num_imp_dec2flt_common_BiasedFp": "5c88d5d7976c5e8f",
"num_imp_dec2flt_decimal_Decimal": "4c41a56bf44cb31e"
}
}Prose assessment
{
"label": "Prose review has no verdict in this snapshot",
"assessment_status": null,
"fingerprint_relation": "unknown",
"assessment_fingerprint": null,
"current_fingerprint": "preservation-v1:f5c5376fe477dd402c7963db918b30761b6da6272588b28a78f32ebe55777928",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}