DecimalGoalVocabularyDefault

Lean checked

Definition and explanation

This explanation was written alongside the formalization to describe the statement and its reasoning.

Definition

The concrete decimal-goal vocabulary has the following meanings. Bytes are their unsigned values, and an Aeneas 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.
The mathematical explicit exponent is the signed base-ten value of all exponent digits. The accumulated exponent folds digits left-to-right, updating a to 10a+d exactly while a<65536, then applies the exponent sign. Exact and accumulated magnitudes concatenate all significand digits and multiply by 10^{e-f}, where f is the number of fractional digits. A source Decimal has magnitude \mathit{mantissa}\,10^{\mathit{exponent}}.
A binary64 magnitude target is a raw word from positive zero through positive infinity. Below the overflow midpoint 2^{1024}-2^{970} it is a finite word at minimum absolute distance from the real input, with an even low significand bit required at a tie; at or above that midpoint it is positive infinity. Finite-word values use the ordinary binary64 normal and subnormal formulas. NaN, infinity, and negativity inspect the IEEE exponent, fraction, and sign bits. Applying a lexical sign sets that sign bit on a nonnegative magnitude. Finally, unrestricted 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

This vocabulary exactly interprets the GOAL grammar and values, the configured 64-bit Rust-string domain, the source's bounded exponent accumulation, IEEE 754 binary64 round-to-nearest ties-to-even, and the source raw-word observations, without restricting mathematical byte strings, nonnegative reals, or BiasedFp field values.

Proof

The source-string predicate combines precisely the configured \mathtt{isize::MAX} byte-length bound with UTF-8 validity; these are the two Rust 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

The source-string predicate selects exactly length-bounded UTF-8 Rust strings, while the outer result still records panic versus normal return.

Requirement: parser numeric acceptance

On that exact Rust-string domain, rendering and validity are exactly the full-input numeric grammar.

Requirement: parser invalid rejection

On that exact Rust-string domain, invalid classification is precisely failure of both numeric and special full-input grammars.

Requirement: parser nan acceptance

On that exact Rust-string domain, all and only signed case-insensitive NaN spellings are related to the exact NaN bit predicate.

Requirement: parser infinity

On that exact Rust-string domain, all infinity spellings retain the lexical sign used by the signed infinity predicate.

Requirement: parser non nan results

The exact Rust-string domain is retained, and the raw-word NaN predicate recognizes every exponent-all-ones nonzero-fraction word.

Requirement: parser numeric sign

The exact Rust-string domain is retained, and signed-magnitude assembly records the lexical sign even for zero and infinity.

Requirement: parser signed zero

The exact Rust-string domain is retained, and the signed-magnitude relation maps zero to the distinct positive or negative zero word.

Requirement: parser exact rounding

On the exact Rust-string domain, the exact value uses every digit and the unbounded mathematical exponent.

Requirement: parser selected exponent

The exact Rust-string domain is retained, while this vocabulary adds no well-formedness assumption to extracted trace pairs.

Requirement: parser selected magnitude sign

The exact Rust-string domain is retained, and the assembly relation and sign predicate inspect the exact raw words.

Requirement: dispatch abstract composition

The abstract flow domain is exactly the bytes of these length-bounded UTF-8 strings; the classification, exact-value, rounding, and sign relations state the component postconditions without choosing implementations.

Requirement: dispatch component compliance

The whole-dispatch domain is exactly these length-bounded UTF-8 strings, while the concrete relations apply unchanged to each extracted component call and trace guard.

Requirement: parser accumulated rounding

On the exact Rust-string domain, the bounded fold follows the source threshold update while retaining every significand digit.

Requirement: parser equal target rounding

On the exact Rust-string domain, target equality is equality of exact raw magnitude words under one rounding relation.

Requirement: number helper acceptance

Unsigned numeric inputs are valid lexemes whose optional leading sign is absent.

Requirement: number helper rejection

The byte-list grammar places no UTF-8 restriction on helper slices.

Requirement: number helper record bounds

Source record machine bounds are retained independently of mathematical values.

Requirement: number helper accumulated value

The record magnitude and accumulated lexeme magnitude are real powers of ten, so both exact and half-open cases are stated literally.

Requirement: special helper infinity

The separate sign argument is exactly the sign parameter of the special and infinity relations.

Requirement: special helper nan

Every returned NaN word is recognized, without requiring a particular NaN payload.

Requirement: special helper rejection

The relation contains exactly the three unsigned keywords with case variation and no extras.

Requirement: native correct or defer

The exact source-record real value and its lexical sign are both retained.

Requirement: integer correct or defer

Integer inputs embed exactly in the real value w10^q, and pair assembly observes the resulting word.

Requirement: slow accumulated rounding

The accumulated value uses the full significand rather than the bounded record mantissa.

Requirement: assembly correspondence

Modulo cast, shift, and OR have Rust semantics for all signed exponent and unsigned mantissa fields.

Requirement: classification totality

The relation is defined for every finite natural-number byte list, with invalid as the complement.

Requirement: classification determinism

Numeric classifications contain the complete lexeme, so content uniqueness is literal record equality.

Requirement: classification significand digit

Validity explicitly requires a nonempty integer or fractional digit list.

Requirement: rounding totality

The relation's input is an unrestricted real with nonnegativity stated in each goal.

Requirement: rounding determinism

Distance minimization, even-tie selection, and the overflow midpoint determine an exact word.

Requirement: exponent value agreement

Exact and accumulated magnitudes differ only in their explicit-exponent fields.

Download Lean source · Download TeX source

Proof structure

Follow the declared dependencies to read the supporting statements and proofs.

Explore this dependency tree

Inspect related source (44)
More program dependencies (11)
Standard-library dependencies (30)

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

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"
}