P367_T1_NumberHelperWholeClassificationA

Lean checked

Statement

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

Lemma · Whole-input unsigned classification through A

For every nonempty byte-slice carrier s of length at most A=3458764513820540928, there exists an optional Decimal o such that the actual specialized numeric call in ActualDispatchOperations returns \texttt{ok}(o). Moreover o is Some of a record if and only if there exists a \texttt{DecimalLexeme} x with x.\mathit{leadingSign}=\texttt{none}, \texttt{validNumeric}(x), and \texttt{renderNumeric}(x)=\texttt{bytes}(s), using DecimalGoalVocabularyDefault. This is whole-input grammar, not prefix recognition. Independent plus or minus signs in the exponent are allowed, with no exponent-digit limit. All bytes of an invalid input are included in the domain, and None is a normal rejection, not failure or divergence.

Lean statement

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

import Tablet.P367_T1_NumberHelperPartialNormalA
import Tablet.P435_T1_PartialLexicalCertificateA
import Tablet.DecimalGoalVocabularyDefault
import Tablet.P9_T1_ActualDispatchOperations
import Tablet.num_imp_dec2flt_parse_parse_number

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P367_T1_NumberHelperWholeClassificationA]
theorem P367_T1_NumberHelperWholeClassificationA (s : Slice Std.U8)
    (hne : s.val ≠ []) (hlen : s.val.length <= 3458764513820540928) :
    exists result : Option num.imp.dec2flt.decimal.Decimal,
      P9_T1_ActualDispatchOperations.parseNumber s = ok result /\
      ((exists d, result = some d) ↔
        exists x : DecimalLexeme, x.leadingSign = none /\
          DecimalGoalVocabularyDefault.validNumeric x /\
          DecimalGoalVocabularyDefault.renderNumeric x =
            DecimalGoalVocabularyDefault.bytes s) := by
Proof

Natural-language proof

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.

Proof

By NumberHelperPartialNormalA, the partial call has a normal optional result. Unfold num imp dec2flt parse parse number: None is passed through normally; Some (d,k) is kept exactly when k=\texttt{Slice.len}(s), and is otherwise replaced by None. The length comparison is pure and total. ActualDispatchOperations identifies the specialized call with this exact extracted function. Hence a normal optional result o exists on every input in the statement.
Apply PartialLexicalCertificateA to that normal partial result; its nonempty and A-bound premises are the hypotheses of this lemma. If the wrapper keeps a partial Some (d,k), then k=\texttt{Slice.len}(s). The certificate supplies a valid unsigned lexeme x and residual bytes R with \texttt{bytes}(s)=\texttt{renderNumeric}(x)++\operatorname{map}(\mathit{val},R) and k.\mathit{val}=|\texttt{renderNumeric}(x)|. The bytes definition in DecimalGoalVocabularyDefault is the value map, which preserves list length. Taking lengths of the first equation gives |s|=|\texttt{renderNumeric}(x)|+|R|; the kept-length equality gives k.\mathit{val}=|s|. Hence |R|=0, so R=[] and x renders the whole input.
Conversely, a valid unsigned x rendering all the bytes satisfies the reverse certificate with R=[]. Its nondigit-head and reserved marker/point guards are then vacuous. The certificate supplies a partial Some (d,k) with k.\mathit{val}=|\texttt{renderNumeric}(x)|=|s|. Since \texttt{Slice.len}(s) has value |s|, Usize value injectivity gives k=\texttt{Slice.len}(s), so the wrapper keeps this record. These arguments cover every partial-result constructor: a supplied full rendering forces a full-length Some by the reverse certificate, and every kept Some produces a full rendering by the forward certificate. This proves both directions and normality of the whole call. All lexical reconstruction, arbitrary signed exponent suffixes, maximal-prefix comparisons, and exact offset accounting are the statement-level conclusions of the cited partial certificate. No normality hypothesis is added to the grammar or to this lemma.

Lean proof


  obtain ⟨parsed, hparsed⟩ := P367_T1_NumberHelperPartialNormalA s hne hlen
  obtain ⟨hforward, hreverse⟩ :=
    P435_T1_PartialLexicalCertificateA s hne hlen parsed hparsed
  have hfull : (exists d consumed, parsed = some (d, consumed) /\
      consumed = Slice.len s) ↔
      exists x : DecimalLexeme, x.leadingSign = none /\
        DecimalGoalVocabularyDefault.validNumeric x /\
        DecimalGoalVocabularyDefault.renderNumeric x =
          DecimalGoalVocabularyDefault.bytes s := by
    constructor
    · rintro ⟨d, consumed, hp, hc⟩
      obtain ⟨x, tail, hsign, hvalid, hbytes, htail, hguards, hcount⟩ :=
        hforward d consumed hp
      change s.val.map (fun b => b.val) =
        DecimalGoalVocabularyDefault.renderNumeric x ++ tail.map (fun b => b.val) at hbytes
      have hl := congrArg List.length hbytes
      simp only [List.length_append, List.length_map] at hl
      have hcval : consumed.val = s.val.length := by rw [hc]; simp
      have ht : tail = [] := List.eq_nil_of_length_eq_zero (by omega)
      refine ⟨x, hsign, hvalid, ?_⟩
      simpa [ht] using hbytes.symm
    · rintro ⟨x, hsign, hvalid, hrender⟩
      obtain ⟨d, consumed, hp, hc⟩ := hreverse x [] hsign hvalid
        (by simpa using hrender.symm) (by simp) (by simp)
      refine ⟨d, consumed, hp, ?_⟩
      apply UScalar.eq_of_val_eq
      change consumed.val = s.val.length
      change DecimalGoalVocabularyDefault.renderNumeric x =
        s.val.map (fun b => b.val) at hrender
      have hl := congrArg List.length hrender
      simp only [List.length_map] at hl
      omega
  let result : Option num.imp.dec2flt.decimal.Decimal :=
    parsed.bind (fun pair => if pair.2 = Slice.len s then some pair.1 else none)
  refine ⟨result, ?_, ?_⟩
  · change num.imp.dec2flt.parse.parse_number s = ok result
    unfold num.imp.dec2flt.parse.parse_number
    rw [hparsed]
    cases parsed with
    | none => rfl
    | some pair =>
      rcases pair with ⟨d, consumed⟩
      by_cases hc : consumed = Slice.len s <;> simp [result, hc]
  · have hkeep : (exists d, result = some d) ↔
        (exists d consumed, parsed = some (d, consumed) /\ consumed = Slice.len s) := by
      cases parsed with
      | none => simp [result]
      | some pair =>
        rcases pair with ⟨d, consumed⟩
        by_cases hc : consumed = Slice.len s <;> simp [result, hc]
    exact hkeep.trans hfull

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P367_T1_NumberHelperPartialNormalA
import Tablet.P435_T1_PartialLexicalCertificateA
import Tablet.DecimalGoalVocabularyDefault
import Tablet.P9_T1_ActualDispatchOperations
import Tablet.num_imp_dec2flt_parse_parse_number

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P367_T1_NumberHelperWholeClassificationA]
theorem P367_T1_NumberHelperWholeClassificationA (s : Slice Std.U8)
    (hne : s.val ≠ []) (hlen : s.val.length <= 3458764513820540928) :
    exists result : Option num.imp.dec2flt.decimal.Decimal,
      P9_T1_ActualDispatchOperations.parseNumber s = ok result /\
      ((exists d, result = some d) ↔
        exists x : DecimalLexeme, x.leadingSign = none /\
          DecimalGoalVocabularyDefault.validNumeric x /\
          DecimalGoalVocabularyDefault.renderNumeric x =
            DecimalGoalVocabularyDefault.bytes s) := by
-- BODY
  obtain ⟨parsed, hparsed⟩ := P367_T1_NumberHelperPartialNormalA s hne hlen
  obtain ⟨hforward, hreverse⟩ :=
    P435_T1_PartialLexicalCertificateA s hne hlen parsed hparsed
  have hfull : (exists d consumed, parsed = some (d, consumed) /\
      consumed = Slice.len s) ↔
      exists x : DecimalLexeme, x.leadingSign = none /\
        DecimalGoalVocabularyDefault.validNumeric x /\
        DecimalGoalVocabularyDefault.renderNumeric x =
          DecimalGoalVocabularyDefault.bytes s := by
    constructor
    · rintro ⟨d, consumed, hp, hc⟩
      obtain ⟨x, tail, hsign, hvalid, hbytes, htail, hguards, hcount⟩ :=
        hforward d consumed hp
      change s.val.map (fun b => b.val) =
        DecimalGoalVocabularyDefault.renderNumeric x ++ tail.map (fun b => b.val) at hbytes
      have hl := congrArg List.length hbytes
      simp only [List.length_append, List.length_map] at hl
      have hcval : consumed.val = s.val.length := by rw [hc]; simp
      have ht : tail = [] := List.eq_nil_of_length_eq_zero (by omega)
      refine ⟨x, hsign, hvalid, ?_⟩
      simpa [ht] using hbytes.symm
    · rintro ⟨x, hsign, hvalid, hrender⟩
      obtain ⟨d, consumed, hp, hc⟩ := hreverse x [] hsign hvalid
        (by simpa using hrender.symm) (by simp) (by simp)
      refine ⟨d, consumed, hp, ?_⟩
      apply UScalar.eq_of_val_eq
      change consumed.val = s.val.length
      change DecimalGoalVocabularyDefault.renderNumeric x =
        s.val.map (fun b => b.val) at hrender
      have hl := congrArg List.length hrender
      simp only [List.length_map] at hl
      omega
  let result : Option num.imp.dec2flt.decimal.Decimal :=
    parsed.bind (fun pair => if pair.2 = Slice.len s then some pair.1 else none)
  refine ⟨result, ?_, ?_⟩
  · change num.imp.dec2flt.parse.parse_number s = ok result
    unfold num.imp.dec2flt.parse.parse_number
    rw [hparsed]
    cases parsed with
    | none => rfl
    | some pair =>
      rcases pair with ⟨d, consumed⟩
      by_cases hc : consumed = Slice.len s <;> simp [result, hc]
  · have hkeep : (exists d, result = some d) ↔
        (exists d consumed, parsed = some (d, consumed) /\ consumed = Slice.len s) := by
      cases parsed with
      | none => simp [result]
      | some pair =>
        rcases pair with ⟨d, consumed⟩
        by_cases hc : consumed = Slice.len s <;> simp [result, hc]
    exact hkeep.trans hfull

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (198)
More program dependencies (156)
Standard-library dependencies (39)

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
All 175 entries
Technical checking records
Local closure summary
{
  "node": "P367_T1_NumberHelperWholeClassificationA",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "f9d4c851f7a735039ec92147a3833f39408b6beffad76a9485367413e8a0ba61",
  "active_statement_hash": "7be9f7fc94094c5152d7bbc4ab39f7706001034c125eca82299afe1030f5693a",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "576e6bf9480cfd32f53c309c7ac8fb115c1ba6e413f299ed5ff9fa7c647e6769",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-194",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "P367_T1_NumberHelperPartialNormalA": "e3f0a77f5c8e974c",
    "P435_T1_PartialLexicalCertificateA": "341c1be26bc98c29"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "4da7f295a9b85b50",
    "DecimalGoalVocabularyDefault": "71a18a6c119a3cdc",
    "DecimalLexeme": "8127b3eaeae00dd2",
    "P9_T1_ActualDispatchOperations": "d8bf51ebbbf153ac",
    "P9_T1_DispatchOperations": "9b177bb1b830a655",
    "num_imp_dec2flt_decimal_Decimal": "c43614ff2149ecf2",
    "num_imp_dec2flt_parse_parse_number": "b8693ec58f01c43c",
    "num_imp_dec2flt_parse_parse_partial_number": "94ed7b2ff71604ef"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "differs from current fingerprint",
  "assessment_fingerprint": "sound-v2:609e6d77d40a85ffdb105bc2cd65037259dadb772cbe7ffc830a132dcceb4fbd",
  "current_fingerprint": "sound-v2:bf687883f513c922d3a4eb612c65f4830e703232b67de92712ce507981f9956c",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}