P835_T1_DecodedRuns

Lean checked

Statement

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

Lemma · Unsigned lexeme from digit runs

Let I,F be byte lists, p a Boolean, and E an optional triple (u,\sigma,J), where u is the uppercase-marker flag, \sigma an optional sign Boolean, and J a byte list. Suppose all bytes of I,F lie in [48,57], |I|+|F|>0, and p=\texttt{false} implies F=[]. For every present E, suppose J\ne[] and its bytes lie in [48,57]. Define P to be I, followed by [46]++F when p is true, followed when E is present by the marker 69 if u is true and 101 otherwise, the sign bytes ([] for absent, [43] for plus, [45] for minus), and J. Then there exists a lexeme x with no leading sign, valid according to DecimalGoalVocabularyDefault, with fraction absent exactly when p is false and exponent absent exactly when E is absent, such that \operatorname{renderNumeric}(x) is \operatorname{map}(\mathit{val},P).

Lean statement

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

import Tablet.P435_T1_DigitDecoding
import Tablet.DecimalGoalVocabularyDefault

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P835_T1_DecodedRuns]
theorem P835_T1_DecodedRuns (integer fraction : List Std.U8) (point : Bool)
    (exponent : Option (Bool × Option Bool × List Std.U8))
    (hnoFraction : point = false -> fraction = [])
    (hd : forall b, b ∈ integer -> 48 <= b.val /\ b.val <= 57)
    (hf : forall b, b ∈ fraction -> 48 <= b.val /\ b.val <= 57)
    (hpos : 0 < integer.length + fraction.length)
    (he : forall upper sign digits, exponent = some (upper, sign, digits) ->
      digits ≠ [] /\ forall b, b ∈ digits -> 48 <= b.val /\ b.val <= 57) :
    exists x : DecimalLexeme,
      x.leadingSign = none /\ DecimalGoalVocabularyDefault.validNumeric x /\
      (x.fractionDigits = none ↔ point = false) /\
      (x.exponent = none ↔ exponent = none) /\
      DecimalGoalVocabularyDefault.renderNumeric x =
        (integer ++ (if point then 46#u8 :: fraction else []) ++
          (match (generalizing := false) exponent with
          | none => []
          | some (upper, sign, digits) =>
            (if upper then 69#u8 else 101#u8) ::
              (match (generalizing := false) sign with
              | none => [] | some negative => [if negative then 45#u8 else 43#u8]) ++
              digits)).map (fun b => b.val) := 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

Decode each digit byte b as b.\mathit{val}-48. By DigitDecoding, the resulting digits are below ten and their reencoding 48+d recovers the byte-value map. Use the decoded I as integer digits; use decoded F as a present fraction exactly when p is true. For present E=(u,\sigma,J), use exponent (u,\sigma,\operatorname{decode}(J)). Set the leading sign to absent. Maps preserve list lengths, so |I|+|F|>0 ensures a nonempty decoded integer or decoded fraction; in the latter case F\ne[] forces p to be true by the absent- fraction hypothesis. A present decoded exponent is nonempty because J\ne[]. The digit-range conclusions and these two nonemptiness observations prove all four validity clauses of DecimalGoalVocabularyDefault. The constructed options are absent exactly in the stated cases. Expanding that vocabulary's rendering definition, reencoding the integer, fraction and exponent blocks gives their value maps. The point renders as 46, the marker as 69 or 101 according to u, and the absent/plus/minus sign renders as []/[43]/[45] according to \sigma. Mapping a concatenation concatenates these maps, which proves the claimed rendering equality, including empty integer or fractional blocks and both marker cases.

Lean proof


  let x : DecimalLexeme := {
    leadingSign := none
    integerDigits := integer.map (fun b => b.val - 48)
    fractionDigits := if point then some (fraction.map (fun b => b.val - 48)) else none
    exponent := exponent.map (fun (upper, sign, ds) =>
      (upper, sign, ds.map (fun b => b.val - 48)))
  }
  have hiFacts := (P435_T1_DigitDecoding integer).1 hd
  have hfFacts := (P435_T1_DigitDecoding fraction).1 hf
  have hvalid : DecimalGoalVocabularyDefault.validNumeric x := by
    change _ ∧ _ ∧ _ ∧ _
    refine ⟨hiFacts.1, ?_, ?_, ?_⟩
    · cases point with
      | false => trivial
      | true => exact hfFacts.1
    · by_cases hi : integer = []
      · right
        have hfr : fraction ≠ [] := by intro h; simp [hi, h] at hpos
        cases hp : point with
        | false => exact (hfr (hnoFraction hp)).elim
        | true => simpa [x, hp] using hfr
      · left
        simpa [x] using hi
    · dsimp only [x]
      cases hx : exponent with
      | none => trivial
      | some p =>
        rcases p with ⟨upper, sign, ds⟩
        have facts := he upper sign ds hx
        have hdFacts := (P435_T1_DigitDecoding ds).1 facts.2
        exact ⟨by simpa using facts.1, hdFacts.1⟩
  refine ⟨x, rfl, hvalid, ?_, ?_, ?_⟩
  · cases point <;> simp [x]
  · cases exponent <;> simp [x]
  · dsimp only [x]
    cases exponent with
    | none =>
      cases point <;>
        simp [DecimalGoalVocabularyDefault, List.map_append,
          hiFacts.2, hfFacts.2]
    | some p =>
      rcases p with ⟨upper, sign, ds⟩
      have hdFacts := (P435_T1_DigitDecoding ds).1 (he upper sign ds rfl).2
      cases point <;> cases upper <;> cases sign with
      | none =>
        simp [DecimalGoalVocabularyDefault, List.map_append,
          hiFacts.2, hfFacts.2, hdFacts.2]
      | some neg =>
        cases neg <;>
          simp [DecimalGoalVocabularyDefault, List.map_append,
            hiFacts.2, hfFacts.2, hdFacts.2]

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P435_T1_DigitDecoding
import Tablet.DecimalGoalVocabularyDefault

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P835_T1_DecodedRuns]
theorem P835_T1_DecodedRuns (integer fraction : List Std.U8) (point : Bool)
    (exponent : Option (Bool × Option Bool × List Std.U8))
    (hnoFraction : point = false -> fraction = [])
    (hd : forall b, b ∈ integer -> 48 <= b.val /\ b.val <= 57)
    (hf : forall b, b ∈ fraction -> 48 <= b.val /\ b.val <= 57)
    (hpos : 0 < integer.length + fraction.length)
    (he : forall upper sign digits, exponent = some (upper, sign, digits) ->
      digits ≠ [] /\ forall b, b ∈ digits -> 48 <= b.val /\ b.val <= 57) :
    exists x : DecimalLexeme,
      x.leadingSign = none /\ DecimalGoalVocabularyDefault.validNumeric x /\
      (x.fractionDigits = none ↔ point = false) /\
      (x.exponent = none ↔ exponent = none) /\
      DecimalGoalVocabularyDefault.renderNumeric x =
        (integer ++ (if point then 46#u8 :: fraction else []) ++
          (match (generalizing := false) exponent with
          | none => []
          | some (upper, sign, digits) =>
            (if upper then 69#u8 else 101#u8) ::
              (match (generalizing := false) sign with
              | none => [] | some negative => [if negative then 45#u8 else 43#u8]) ++
              digits)).map (fun b => b.val) := by
-- BODY
  let x : DecimalLexeme := {
    leadingSign := none
    integerDigits := integer.map (fun b => b.val - 48)
    fractionDigits := if point then some (fraction.map (fun b => b.val - 48)) else none
    exponent := exponent.map (fun (upper, sign, ds) =>
      (upper, sign, ds.map (fun b => b.val - 48)))
  }
  have hiFacts := (P435_T1_DigitDecoding integer).1 hd
  have hfFacts := (P435_T1_DigitDecoding fraction).1 hf
  have hvalid : DecimalGoalVocabularyDefault.validNumeric x := by
    change _ ∧ _ ∧ _ ∧ _
    refine ⟨hiFacts.1, ?_, ?_, ?_⟩
    · cases point with
      | false => trivial
      | true => exact hfFacts.1
    · by_cases hi : integer = []
      · right
        have hfr : fraction ≠ [] := by intro h; simp [hi, h] at hpos
        cases hp : point with
        | false => exact (hfr (hnoFraction hp)).elim
        | true => simpa [x, hp] using hfr
      · left
        simpa [x] using hi
    · dsimp only [x]
      cases hx : exponent with
      | none => trivial
      | some p =>
        rcases p with ⟨upper, sign, ds⟩
        have facts := he upper sign ds hx
        have hdFacts := (P435_T1_DigitDecoding ds).1 facts.2
        exact ⟨by simpa using facts.1, hdFacts.1⟩
  refine ⟨x, rfl, hvalid, ?_, ?_, ?_⟩
  · cases point <;> simp [x]
  · cases exponent <;> simp [x]
  · dsimp only [x]
    cases exponent with
    | none =>
      cases point <;>
        simp [DecimalGoalVocabularyDefault, List.map_append,
          hiFacts.2, hfFacts.2]
    | some p =>
      rcases p with ⟨upper, sign, ds⟩
      have hdFacts := (P435_T1_DigitDecoding ds).1 (he upper sign ds rfl).2
      cases point <;> cases upper <;> cases sign with
      | none =>
        simp [DecimalGoalVocabularyDefault, List.map_append,
          hiFacts.2, hfFacts.2, hdFacts.2]
      | some neg =>
        cases neg <;>
          simp [DecimalGoalVocabularyDefault, List.map_append,
            hiFacts.2, hfFacts.2, hdFacts.2]

end dec2flt_model

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
All 8 entries
Technical checking records
Local closure summary
{
  "node": "P835_T1_DecodedRuns",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "d6e5970e83baa6750fcafa8844ea543e7a6d6d2c1c0bdb3d251179800f3735ed",
  "active_statement_hash": "8de6241cab0f5b5b821152ff414a5afb8e9a6e1dbe1093e320ad6a1c8fdcac70",
  "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": {
    "DecimalGoalVocabularyDefault": "94cb4c406f8efb78",
    "P435_T1_DigitDecoding": "0b69e5fe3215de46"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "c08dd4b4aea4abb4",
    "DecimalGoalVocabularyDefault": "b9386c8d0fd53e6e",
    "DecimalLexeme": "250be645520aec86",
    "F64": "ec4e25fbaf4e11d4",
    "num_imp_dec2flt_common_BiasedFp": "5c88d5d7976c5e8f",
    "num_imp_dec2flt_decimal_Decimal": "4c41a56bf44cb31e"
  }
}
Prose assessment
{
  "label": "Lean proof closed; predictive prose review no longer required",
  "assessment_status": null,
  "fingerprint_relation": "unknown",
  "assessment_fingerprint": null,
  "current_fingerprint": "sound-v2:27c74fe0cf401d56133b4cffa7232d223cbd4c4ea88c8398171f61544ed1da1b",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}