DecimalLiteral

Lean checked

Definition and explanation

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

Definition

A decimal literal witness records a finite byte string together with its optional leading sign, integral and fractional ASCII digits, optional decimal point, optional e/E marker, optional exponent sign, and exponent digits. Every recorded digit lies in 0,\ldots,9, the significand has at least one digit, fractional digits occur only with a point, and exponent digits are nonempty exactly when an exponent marker occurs. Re-encoding these fields gives the recorded bytes. Its lexical sign is negative exactly for a leading minus. Its mathematical exponent is the signed integer represented by all exponent digits. Its accumulated exponent folds those same digits from zero, performing a\mapsto10a+d only while the prior accumulator is below 65536, and then applies the exponent sign. The witness's exact and accumulated values use all significand digits, subtract the fractional digit count from the corresponding exponent, multiply by the resulting power of ten, and apply the lexical sign.

Lean definition

Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.

import Tablet.Preamble
import Mathlib.Data.Real.Basic

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: DecimalLiteral]
structure DecimalLiteral where
-- BODY
  bytes : List Std.U8
  sign : Option Bool
  negative : Bool
  integralDigits : List Nat
  fractionalDigits : List Nat
  decimalPointPresent : Bool
  exponentMarker : Option Bool
  exponentSign : Option Bool
  exponentDigits : List Nat
  mathematicalExponent : Int
  accumulatedExponent : Int
  exactValue : Real
  accumulatedValue : Real
  negative_eq : negative = sign.getD false
  integral_digits : ∀ d ∈ integralDigits, d < 10
  fractional_digits : ∀ d ∈ fractionalDigits, d < 10
  exponent_digits : ∀ d ∈ exponentDigits, d < 10
  significand_nonempty : integralDigits ≠ [] ∨ fractionalDigits ≠ []
  fractional_empty_without_point :
    decimalPointPresent = false → fractionalDigits = []
  exponent_shape :
    exponentMarker = none ↔ exponentSign = none ∧ exponentDigits = []
  exponent_digits_nonempty :
    exponentMarker ≠ none → exponentDigits ≠ []
  bytes_eq :
    bytes.map (fun b => b.val) =
      (match sign with
       | none => []
       | some true => [45]
       | some false => [43]) ++
      integralDigits.map (fun d => d + 48) ++
      (if decimalPointPresent
       then [46] ++ fractionalDigits.map (fun d => d + 48)
       else []) ++
      (match exponentMarker with
       | none => []
       | some upper =>
           [if upper then 69 else 101] ++
           (match exponentSign with
            | none => []
            | some true => [45]
            | some false => [43]) ++
           exponentDigits.map (fun d => d + 48))
  mathematicalExponent_eq :
    mathematicalExponent =
      let n : Nat := exponentDigits.foldl (fun a d => 10 * a + d) 0
      if exponentSign.getD false then -(n : Int) else (n : Int)
  accumulatedExponent_eq :
    accumulatedExponent =
      let n : Nat := exponentDigits.foldl
        (fun a d => if a < 65536 then 10 * a + d else a) 0
      if exponentSign.getD false then -(n : Int) else (n : Int)
  exactValue_eq :
    exactValue =
      let n : Nat := (integralDigits ++ fractionalDigits).foldl
        (fun a d => 10 * a + d) 0
      let magnitude := (n : Real) *
        10 ^ (mathematicalExponent - (fractionalDigits.length : Int))
      if negative then -magnitude else magnitude
  accumulatedValue_eq :
    accumulatedValue =
      let n : Nat := (integralDigits ++ fractionalDigits).foldl
        (fun a d => 10 * a + d) 0
      let magnitude := (n : Real) *
        10 ^ (accumulatedExponent - (fractionalDigits.length : Int))
      if negative then -magnitude else magnitude

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

The witness describes exactly the numeric grammar and the two decimal-value notions fixed in GOAL.md; it neither accepts extra bytes nor identifies the unbounded mathematical exponent with the source's bounded accumulator.

Proof

The byte reconstruction has precisely the optional sign, digit-bearing significand with at most one point, and optional digit-bearing exponent from the reference grammar. The two exponent equations respectively use the ordinary base-ten fold and the guarded fold in parse_scientific; both consume every digit. The value equations retain every significand digit and adjust for the decimal point. These facts follow directly from the definition and the frozen grammar and loop recorded in reference/model-evidence/decimal-specification.txt.

Requirement: parser totality

The witness only classifies inputs and adds no execution premise.

Requirement: parser numeric acceptance

Existence of a witness is exactly the numeric-literal domain.

Requirement: parser invalid rejection

Nonexistence of numeric and special witnesses expresses being outside the grammar.

Requirement: parser nan acceptance

Numeric witnesses are disjoint from the separately defined special grammar.

Requirement: parser infinity

Numeric witnesses are disjoint from the separately defined special grammar.

Requirement: parser non nan results

The witness identifies exactly which successful inputs are numeric rather than NaN literals.

Requirement: parser numeric sign

Its negative field is precisely the literal's lexical sign.

Requirement: parser signed zero

Its exact value and lexical sign retain the two observations needed for signed zero.

Requirement: parser exact rounding

Its exact value is the ordinary unbounded mathematical decimal value.

Requirement: parser selected exponent

The witness supplies exactly the successful numeric input domain for trace observations.

Requirement: parser selected magnitude sign

The witness supplies exactly the successful numeric input domain for trace observations.

Requirement: dispatch abstract composition

Lexical contracts can quantify over the complete numeric grammar and both value notions.

Requirement: dispatch component compliance

The actual lexical component can be compared with the witness byte-for-byte.

Requirement: parser accumulated rounding

Its accumulated value uses the source's guarded exponent fold while retaining all significand digits.

Requirement: parser equal target rounding

Both distinct values are available on the same witness for the bridge premise.

Requirement: number helper acceptance

Requiring no leading sign gives exactly an unsigned numeric literal.

Requirement: number helper rejection

Failure of an unsigned witness gives exactly the helper's rejection domain.

Requirement: number helper record bounds

The witness does not restrict arbitrary returned records; the theorem retains its nonempty-slice domain.

Requirement: number helper accumulated value

The accumulated value and all significand digits are explicit on the witness.

Requirement: special helper infinity

Numeric syntax is separate from the unsigned special-keyword domain.

Requirement: special helper nan

Numeric syntax is separate from the unsigned special-keyword domain.

Requirement: special helper rejection

Numeric witnesses do not enlarge the special helper's keyword set.

Requirement: native correct or defer

This goal uses a decimal record directly, so the literal witness is noninterfering.

Requirement: integer correct or defer

This goal quantifies directly over an i64 and u64, so the witness is noninterfering.

Requirement: slow accumulated rounding

An unsigned witness provides the full-significand accumulated value of the helper input.

Requirement: assembly correspondence

Assembly is independent of literal syntax.

Requirement: classification totality

Witness existence is the numeric arm of the exhaustive classification.

Requirement: classification determinism

All parsed content is recorded, so uniqueness can be stated as witness equality.

Requirement: classification significand digit

The nonempty-significand field states the required digit property.

Requirement: rounding totality

Literal syntax is independent of existence of a binary64 target.

Requirement: rounding determinism

Literal syntax is independent of uniqueness of a binary64 target.

Requirement: exponent value agreement

The two explicit exponents and two values are retained separately for the agreement premise and conclusion.

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 (21)
More program dependencies (10)
Standard-library dependencies (8)

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": "DecimalLiteral",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "c35ed168338e712086834df219578b85d396ccd8a96ff95cc69a582108ebd4e1",
  "active_statement_hash": "a808f3f76a9241dc0d5b187edd07df517d3f7aa2a349ef3ede6222f654bb98d5",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "b3d2e5a7a57ad9d2abdfb1c60bd76050a5cafa6a2be969c219d3ae71b2a8ade5",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-3",
  "boundary_theorems": {},
  "strict_theorem_deps": {},
  "strict_definition_deps": {}
}
Prose assessment
{
  "label": "Prose review has no verdict in this snapshot",
  "assessment_status": null,
  "fingerprint_relation": "unknown",
  "assessment_fingerprint": null,
  "current_fingerprint": "preservation-v1:58022bc102f020fdb12f711e1d0c5ba2dc97e09f53f22bfa3f00d61842efa37b",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}