P435_T1_RenderedDigitBlocks

Lean checked

Statement

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

Lemma · Rendered numeric prefixes as actual byte blocks

Let B,R be arbitrary U8 lists and x a valid numeric lexeme with no leading sign in DecimalGoalVocabularyDefault. Suppose the value map of B is \texttt{renderNumeric}(x) followed by the value map of R. There exist byte lists I,F,J such that
B=I++\operatorname{fractionBytes}(x,F)++ \operatorname{exponentBytes}(x,J)++R.
Here fractionBytes is empty for an absent fraction and [46]++F for a present fraction. ExponentBytes is empty for an absent exponent and otherwise its own marker (69 for upper case, 101 for lower case), its optional sign (45 for minus, 43 for plus), and J. The value maps of I,F,J are the 48+d encodings of respectively the integer, fraction, and exponent digits of x, with an absent digit list taken empty. Every byte in all three lists is in [48,57]. In particular the absent fraction and exponent lists are empty. There is no length bound on the lists or exponent digits.

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_ByteValueBlocks
import Tablet.NumberHelperSplitExponentSuffix
import Tablet.DecimalGoalVocabularyDefault

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P435_T1_RenderedDigitBlocks]
theorem P435_T1_RenderedDigitBlocks
    (bytes remainder : List Std.U8) (x : DecimalLexeme)
    (hsign : x.leadingSign = none)
    (hvalid : DecimalGoalVocabularyDefault.validNumeric x)
    (hrender : bytes.map (fun b => b.val) =
      DecimalGoalVocabularyDefault.renderNumeric x ++ remainder.map (fun b => b.val)) :
    exists integer fraction exponent : List Std.U8,
      bytes = integer ++
        (match x.fractionDigits with | none => [] | some _ => 46#u8 :: fraction) ++
        (match x.exponent with
        | none => []
        | some (upper, sign, _) =>
          (if upper then 69#u8 else 101#u8) ::
            (match sign with | none => [] | some neg => [if neg then 45#u8 else 43#u8]) ++
            exponent) ++ remainder /\
      integer.map (fun b => b.val) = x.integerDigits.map (fun d => 48 + d) /\
      fraction.map (fun b => b.val) =
        (match x.fractionDigits with | none => [] | some ds => ds).map (fun d => 48 + d) /\
      exponent.map (fun b => b.val) =
        (match x.exponent with | none => [] | some (_, _, ds) => ds).map (fun d => 48 + d) /\
      (forall b, b ∈ integer -> 48 <= b.val /\ b.val <= 57) /\
      (forall b, b ∈ fraction -> 48 <= b.val /\ b.val <= 57) /\
      (forall b, b ∈ exponent -> 48 <= b.val /\ b.val <= 57) := 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

Unfold the rendering in DecimalGoalVocabularyDefault and remove its empty leading-sign block. Apply ByteValueBlocks first at the integer-value block, then at the serialized fraction block, then at the serialized exponent block. This supplies actual byte blocks and a last block whose value map is the value map of R. The uniqueness clause of that lemma equates the last block with R, not merely their lengths.
For an absent fraction its serialized value block is empty, so its byte block is empty. For a present fraction the map equation forces a head of value 46 and a tail with the encoded fractional values; value injectivity identifies that head as the byte 46. Choose the tail as F. Similarly an absent exponent has an empty byte block. For a present exponent its forced first byte is its own 69 or 101 marker. Apply NumberHelperSplitExponentSuffix to the remaining byte block: its map equation is exactly the optional-sign block followed by the encoded exponent digits. It supplies the actual sign bytes and J. These substitutions in the three concatenation equations prove the displayed byte-level decomposition.
Validity supplies that each natural digit in each present digit list is less than ten. If a byte belongs to I, its value belongs to the integer encoded map, hence equals 48+d for one such digit d. Thus its value lies in [48,57]. The identical membership argument applies to F and J, including the vacuous absent-list cases. Empty maps force empty byte lists. Neither this proof nor NumberHelperSplitExponentSuffix restricts the size of a digit list or evaluates its numerical exponent.

Lean proof


  let fv : List Nat := match x.fractionDigits with
    | none => [] | some ds => 46 :: ds.map (fun d => 48 + d)
  let ev : List Nat := 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 (fun d => 48 + d)
  have hmap : bytes.map (fun b => b.val) =
      x.integerDigits.map (fun d => 48 + d) ++
        (fv ++ (ev ++ remainder.map (fun b => b.val))) := by
    dsimp [DecimalGoalVocabularyDefault] at hrender
    simpa [hsign, fv, ev, List.append_assoc] using hrender
  obtain ⟨p, hp, hi, ht, _⟩ := P435_T1_ByteValueBlocks bytes
    (x.integerDigits.map (fun d => 48 + d))
    (fv ++ (ev ++ remainder.map (fun b => b.val))) hmap
  obtain ⟨q, hq, hf, he, _⟩ := P435_T1_ByteValueBlocks p.2 fv
    (ev ++ remainder.map (fun b => b.val)) ht
  obtain ⟨r, hr, hev, hrem, hunique⟩ :=
    P435_T1_ByteValueBlocks q.2 ev (remainder.map (fun b => b.val)) he
  have hremEq : remainder = r.2 := (hunique r.1 remainder hev rfl).2
  obtain ⟨fraction, hfraction, hfm⟩ : exists fraction : List Std.U8,
      q.1 = (match x.fractionDigits with | none => [] | some _ => 46#u8 :: fraction) /\
      fraction.map (fun b => b.val) =
        (match x.fractionDigits with | none => [] | some ds => ds).map (fun d => 48 + d) := by
    cases hx : x.fractionDigits with
    | none =>
      have hnil : q.1 = [] := by simpa [fv, hx] using hf
      exact ⟨[], by simp [hx, hnil]⟩
    | some ds =>
      have hf' : q.1.map (fun b => b.val) = 46 :: ds.map (fun d => 48 + d) := by
        simpa [fv, hx] using hf
      obtain ⟨b, bs, hs, hb, hbs⟩ := List.map_eq_cons_iff.mp hf'
      have hb' : b = 46#u8 := UScalar.eq_of_val_eq (by simpa using hb)
      exact ⟨bs, by simpa [hx, hb'] using hs, by simpa [hx] using hbs⟩
  obtain ⟨exponent, hexponent, hem⟩ : exists exponent : List Std.U8,
      r.1 = (match x.exponent with
        | none => []
        | some (upper, sign, _) => (if upper then 69#u8 else 101#u8) ::
          (match sign with | none => [] | some neg => [if neg then 45#u8 else 43#u8]) ++ exponent) /\
      exponent.map (fun b => b.val) =
        (match x.exponent with | none => [] | some (_, _, ds) => ds).map (fun d => 48 + d) := by
    cases hx : x.exponent with
    | none =>
      have hnil : r.1 = [] := by simpa [ev, hx] using hev
      exact ⟨[], by simp [hx, hnil]⟩
    | some tuple =>
      rcases tuple with ⟨upper, sign, ds⟩
      have he' : r.1.map (fun b => b.val) = (if upper then 69 else 101) ::
          ((match sign with | none => [] | some neg => [if neg then 45 else 43]) ++
            ds.map (fun d => 48 + d)) := by
        simpa [ev, hx] using hev
      obtain ⟨b, bs, hs, hb, hbs⟩ := List.map_eq_cons_iff.mp he'
      have hb' : b = (if upper then 69#u8 else 101#u8) := by
        apply UScalar.eq_of_val_eq
        cases upper <;> simpa using hb
      obtain ⟨es, hbs', hm⟩ := NumberHelperSplitExponentSuffix sign bs ds hbs
      refine ⟨es, ?_, by simpa [hx] using hm⟩
      cases sign with
      | none => simpa [hx, hb', hbs'] using hs
      | some negative => cases negative <;> simpa [hx, hb', hbs'] using hs
  have ranges : forall (bs : List Std.U8) (ds : List Nat),
      bs.map (fun b => b.val) = ds.map (fun d => 48 + d) ->
      (forall d, d ∈ ds -> d < 10) ->
      forall b, b ∈ bs -> 48 <= b.val /\ b.val <= 57 := by
    intro bs ds hm hd b hb
    have hbmap : b.val ∈ bs.map (fun c => c.val) := List.mem_map_of_mem hb
    rw [hm] at hbmap
    obtain ⟨d, hdm, heq⟩ := List.mem_map.mp hbmap
    have := hd d hdm
    omega
  have hv := hvalid
  dsimp [DecimalGoalVocabularyDefault] at hv
  rcases hv with ⟨hints, hfracs, hnonempty, hexps⟩
  refine ⟨p.1, fraction, exponent, ?_, hi, hfm, hem,
    ranges p.1 x.integerDigits hi hints, ?_, ?_⟩
  · rw [hp, hq, hr, hfraction, hexponent, ← hremEq]
    simp only [List.append_assoc]
  · apply ranges fraction _ hfm
    cases hx : x.fractionDigits <;> simpa [hx] using hfracs
  · apply ranges exponent _ hem
    cases hx : x.exponent with
    | none => simp [hx]
    | some tuple =>
      rcases tuple with ⟨upper, sign, ds⟩
      have hexps' : ds ≠ [] /\ (forall d, d ∈ ds -> d < 10) := by
        simpa [hx] using hexps
      exact hexps'.2

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P435_T1_ByteValueBlocks
import Tablet.NumberHelperSplitExponentSuffix
import Tablet.DecimalGoalVocabularyDefault

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P435_T1_RenderedDigitBlocks]
theorem P435_T1_RenderedDigitBlocks
    (bytes remainder : List Std.U8) (x : DecimalLexeme)
    (hsign : x.leadingSign = none)
    (hvalid : DecimalGoalVocabularyDefault.validNumeric x)
    (hrender : bytes.map (fun b => b.val) =
      DecimalGoalVocabularyDefault.renderNumeric x ++ remainder.map (fun b => b.val)) :
    exists integer fraction exponent : List Std.U8,
      bytes = integer ++
        (match x.fractionDigits with | none => [] | some _ => 46#u8 :: fraction) ++
        (match x.exponent with
        | none => []
        | some (upper, sign, _) =>
          (if upper then 69#u8 else 101#u8) ::
            (match sign with | none => [] | some neg => [if neg then 45#u8 else 43#u8]) ++
            exponent) ++ remainder /\
      integer.map (fun b => b.val) = x.integerDigits.map (fun d => 48 + d) /\
      fraction.map (fun b => b.val) =
        (match x.fractionDigits with | none => [] | some ds => ds).map (fun d => 48 + d) /\
      exponent.map (fun b => b.val) =
        (match x.exponent with | none => [] | some (_, _, ds) => ds).map (fun d => 48 + d) /\
      (forall b, b ∈ integer -> 48 <= b.val /\ b.val <= 57) /\
      (forall b, b ∈ fraction -> 48 <= b.val /\ b.val <= 57) /\
      (forall b, b ∈ exponent -> 48 <= b.val /\ b.val <= 57) := by
-- BODY
  let fv : List Nat := match x.fractionDigits with
    | none => [] | some ds => 46 :: ds.map (fun d => 48 + d)
  let ev : List Nat := 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 (fun d => 48 + d)
  have hmap : bytes.map (fun b => b.val) =
      x.integerDigits.map (fun d => 48 + d) ++
        (fv ++ (ev ++ remainder.map (fun b => b.val))) := by
    dsimp [DecimalGoalVocabularyDefault] at hrender
    simpa [hsign, fv, ev, List.append_assoc] using hrender
  obtain ⟨p, hp, hi, ht, _⟩ := P435_T1_ByteValueBlocks bytes
    (x.integerDigits.map (fun d => 48 + d))
    (fv ++ (ev ++ remainder.map (fun b => b.val))) hmap
  obtain ⟨q, hq, hf, he, _⟩ := P435_T1_ByteValueBlocks p.2 fv
    (ev ++ remainder.map (fun b => b.val)) ht
  obtain ⟨r, hr, hev, hrem, hunique⟩ :=
    P435_T1_ByteValueBlocks q.2 ev (remainder.map (fun b => b.val)) he
  have hremEq : remainder = r.2 := (hunique r.1 remainder hev rfl).2
  obtain ⟨fraction, hfraction, hfm⟩ : exists fraction : List Std.U8,
      q.1 = (match x.fractionDigits with | none => [] | some _ => 46#u8 :: fraction) /\
      fraction.map (fun b => b.val) =
        (match x.fractionDigits with | none => [] | some ds => ds).map (fun d => 48 + d) := by
    cases hx : x.fractionDigits with
    | none =>
      have hnil : q.1 = [] := by simpa [fv, hx] using hf
      exact ⟨[], by simp [hx, hnil]⟩
    | some ds =>
      have hf' : q.1.map (fun b => b.val) = 46 :: ds.map (fun d => 48 + d) := by
        simpa [fv, hx] using hf
      obtain ⟨b, bs, hs, hb, hbs⟩ := List.map_eq_cons_iff.mp hf'
      have hb' : b = 46#u8 := UScalar.eq_of_val_eq (by simpa using hb)
      exact ⟨bs, by simpa [hx, hb'] using hs, by simpa [hx] using hbs⟩
  obtain ⟨exponent, hexponent, hem⟩ : exists exponent : List Std.U8,
      r.1 = (match x.exponent with
        | none => []
        | some (upper, sign, _) => (if upper then 69#u8 else 101#u8) ::
          (match sign with | none => [] | some neg => [if neg then 45#u8 else 43#u8]) ++ exponent) /\
      exponent.map (fun b => b.val) =
        (match x.exponent with | none => [] | some (_, _, ds) => ds).map (fun d => 48 + d) := by
    cases hx : x.exponent with
    | none =>
      have hnil : r.1 = [] := by simpa [ev, hx] using hev
      exact ⟨[], by simp [hx, hnil]⟩
    | some tuple =>
      rcases tuple with ⟨upper, sign, ds⟩
      have he' : r.1.map (fun b => b.val) = (if upper then 69 else 101) ::
          ((match sign with | none => [] | some neg => [if neg then 45 else 43]) ++
            ds.map (fun d => 48 + d)) := by
        simpa [ev, hx] using hev
      obtain ⟨b, bs, hs, hb, hbs⟩ := List.map_eq_cons_iff.mp he'
      have hb' : b = (if upper then 69#u8 else 101#u8) := by
        apply UScalar.eq_of_val_eq
        cases upper <;> simpa using hb
      obtain ⟨es, hbs', hm⟩ := NumberHelperSplitExponentSuffix sign bs ds hbs
      refine ⟨es, ?_, by simpa [hx] using hm⟩
      cases sign with
      | none => simpa [hx, hb', hbs'] using hs
      | some negative => cases negative <;> simpa [hx, hb', hbs'] using hs
  have ranges : forall (bs : List Std.U8) (ds : List Nat),
      bs.map (fun b => b.val) = ds.map (fun d => 48 + d) ->
      (forall d, d ∈ ds -> d < 10) ->
      forall b, b ∈ bs -> 48 <= b.val /\ b.val <= 57 := by
    intro bs ds hm hd b hb
    have hbmap : b.val ∈ bs.map (fun c => c.val) := List.mem_map_of_mem hb
    rw [hm] at hbmap
    obtain ⟨d, hdm, heq⟩ := List.mem_map.mp hbmap
    have := hd d hdm
    omega
  have hv := hvalid
  dsimp [DecimalGoalVocabularyDefault] at hv
  rcases hv with ⟨hints, hfracs, hnonempty, hexps⟩
  refine ⟨p.1, fraction, exponent, ?_, hi, hfm, hem,
    ranges p.1 x.integerDigits hi hints, ?_, ?_⟩
  · rw [hp, hq, hr, hfraction, hexponent, ← hremEq]
    simp only [List.append_assoc]
  · apply ranges fraction _ hfm
    cases hx : x.fractionDigits <;> simpa [hx] using hfracs
  · apply ranges exponent _ hem
    cases hx : x.exponent with
    | none => simp [hx]
    | some tuple =>
      rcases tuple with ⟨upper, sign, ds⟩
      have hexps' : ds ≠ [] /\ (forall d, d ∈ ds -> d < 10) := by
        simpa [hx] using hexps
      exact hexps'.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 9 entries
Technical checking records
Local closure summary
{
  "node": "P435_T1_RenderedDigitBlocks",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "13f30a550283ada9a738c134682007d5cda3a5cc521ebff3ac91e3622ebeb4a8",
  "active_statement_hash": "935689ba9ea6cdec45dc773fe324bee899b4a2df4b951143214ad6ecc5d095c8",
  "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-92",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "NumberHelperSplitExponentSuffix": "36f92cf2e9d9f766",
    "P435_T1_ByteValueBlocks": "c7b99f7987408046"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "4da7f295a9b85b50",
    "DecimalGoalVocabularyDefault": "28ca0a8ac503ee01",
    "DecimalLexeme": "250be645520aec86",
    "NumberHelperSplitExponentSuffix": "3a789d080d66f335"
  }
}
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:c5afd44401c99af666699df74c087bef39a94da838a30f98d30b005f8514e3af",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}