P495_T1_DecimalSeqReconstruction

Lean checked

Statement

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

Theorem · Execution-based decimal-sequence reconstruction

Let s be any source-valid byte slice rendering an unsigned valid numeric lexeme x. Put L=|s.\mathit{val}|, let F be its full fractional digit list (empty when absent), S=I\mathbin{++}F, C its leading-zero deletion, T its subsequent terminal-zero trim, and E=\texttt{accumulatedExplicitExponent}(x). There exist a normally returned record d, a scan record a, saved Usize operands n,f, and an I64 operand e satisfying all of the following:
\texttt{parse\_decimal\_seq}(s)=\texttt{ok}\ d,\quad n=a.\mathit{num\_digits},\quad n.\mathit{val}=|C|,\quad f.\mathit{val}=|F|,\quad e.\mathit{val}=E.
The counts n.\mathit{val}, f.\mathit{val}, and |S| are at most L. The actual saved-count finalizer equation is \texttt{final\_decimal\_point}(n,f,e)=\texttt{ok}\ d.\mathit{decimal\_point}; its value is zero when |C|=0, otherwise \max(-2047,\min(2047,|C|-|F|+E)). The returned count is r=\min(|T|,768)\le768; its retained value list is \operatorname{take}(r,T), and its sticky flag is true iff 768<|T|. The scan record has point zero, false flag, and stored value prefix \operatorname{take}(\min(|C|,768),C). The result preserves the first r actual U8 scan cells, changes precisely cells r\le j<19 to U8 zero, and preserves every other scan cell below 768. Every output cell value is below ten. Moreover C=[] iff r=0. In that case the returned point and flag are zero and false, and cells j<19 are zero. If C\ne[], it has a first digit h with 1\le h<10, and the first stored output cell has value h. This construction has no A/B bound or public-reachability premise. Because Result's normal constructor is injective, the certificate identifies every normally returned record for this same call, not just an arbitrary ideal decimal record.

Lean statement

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

import Tablet.P495_T1_SignificandScan
import Tablet.P495_T1_ExponentSuffix
import Tablet.P495_T1_TrailingCount
import Tablet.P495_T1_FinalizationExact
import Tablet.P800_T1_ParserFactorization

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P495_T1_DecimalSeqReconstruction]
theorem P495_T1_DecimalSeqReconstruction (s : Slice Std.U8) (x : DecimalLexeme)
    (hsource : SourceValidByteSlice s) (hsign : x.leadingSign = none)
    (hvalid : DecimalGoalVocabularyDefault.validNumeric x)
    (hbytes : DecimalGoalVocabularyDefault.renderNumeric x =
      DecimalGoalVocabularyDefault.bytes s) :
    let F := match x.fractionDigits with | none => [] | some ds => ds
    let S := x.integerDigits ++ F
    let C := S.dropWhile (fun z => z == 0)
    let T := (C.reverse.dropWhile (fun z => z == 0)).reverse
    exists (d scan : num.imp.dec2flt.decimal_seq.DecimalSeq)
      (n f : Std.Usize) (e : Std.I64),
      num.imp.dec2flt.decimal_seq.parse_decimal_seq s = ok d /\
      n = scan.num_digits /\ n.val = C.length /\ f.val = F.length /\
      e.val = DecimalGoalVocabularyDefault.accumulatedExplicitExponent x /\
      n.val <= s.val.length /\ f.val <= s.val.length /\ S.length <= s.val.length /\
      num.imp.dec2flt.decimal_seq.final_decimal_point n f e = ok d.decimal_point /\
      d.decimal_point.val = (if C.length = 0 then 0 else
        max (-2047) (min 2047 ((C.length : Int) - F.length +
          DecimalGoalVocabularyDefault.accumulatedExplicitExponent x))) /\
      d.num_digits.val = min T.length 768 /\ d.num_digits.val <= 768 /\
      (d.digits.val.take d.num_digits.val).map (fun b => b.val) =
        T.take d.num_digits.val /\
      (d.truncated = true <-> 768 < T.length) /\
      scan.decimal_point = 0#i32 /\ scan.truncated = false /\
      (scan.digits.val.take (min C.length 768)).map (fun b => b.val) =
        C.take (min C.length 768) /\
      d.digits.val.take d.num_digits.val = scan.digits.val.take d.num_digits.val /\
      (forall j, j < 768 -> d.digits.val[j]? =
        if d.num_digits.val <= j /\ j < 19 then some 0#u8 else scan.digits.val[j]?) /\
      (forall b, b ∈ d.digits.val -> b.val < 10) /\
      (C = [] <-> d.num_digits.val = 0) /\
      (C = [] -> d.decimal_point = 0#i32 /\ d.truncated = false /\
        forall j, j < 19 -> d.digits.val[j]? = some 0#u8) /\
      (C ≠ [] -> exists digit : Nat,
        C[0]? = some digit /\ 1 <= digit /\ digit < 10 /\
        (d.digits.val[0]?).map (fun b => b.val) = some digit) := 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

Apply SignificandScan with the given source, sign, validity, and rendering premises. It constructs the actual normal prefix results: exponent residual u, scan record a, and fractional operand f. Set n=a.\mathit{num\_digits}. Its conclusions give n.\mathit{val}=|C|, f.\mathit{val}=|F|, n.\mathit{val},f.\mathit{val}, |S|\le L, zero scan point, false flag, and all-cell digit bounds. The scan cell equation, restricted to its first \min(|C|,768) cells and combined with their exact array length 768, gives its claimed stored prefix by list extensionality. Nothing here assumes retained-point semantics.
Apply ExponentSuffix to u and x. Its slice premise is the exponent residual conclusion of the scan theorem. This gives the actual normal explicit-exponent result e, of value E. It applies equally to zero significands and scans any present suffix completely. With no exponent it returns I64 zero. The source's duplicated exponent computations have precisely the same empty, index, marker, drop, scientific, and unwrap operations. In a fractional branch their fresh empty test is the one in the suffix theorem. In the integer branch the earlier empty test and earlier head read concern the SAME unchanged residual u; substituting their deterministic results gives this same exponent equation. In the initially empty branch the exponent computation selects zero without indexing, again the same result. Thus these witnesses identify the actual operands, not a replacement suffix computation.
Use DecimalDigitTrimDecomposition on S to obtain C=T\mathbin{++}0^q with q=|C|-|T|, and a nonzero first entry when C is nonempty. Suppose first C\ne[]. The residual premise for TrailingCount is supplied by the scan theorem. That principal provides the actual normal length difference c and reverse count z, with z.\mathit{val}=q. The split therefore is C=T\mathbin{++}0^{z.\mathit{val}}. If C=[], the decomposition makes T=[] and q=0. Choose Usize zero for z. The rendering equations give |s|=H+|u|, where H is the significand byte length, so the checked length difference still has a normal value c=H. No reverse-count equation is required in this case: the source and the finalization theorem both skip that call.
SourceValidByteSlice gives L\le2^{63}-1. Hence the count bounds just derived discharge the two saved-count hypotheses of FinalizationExact. Its other hypotheses are the scan flag, prefix and all-cell bounds, the split, the actual length difference, and, only in the nonzero case, the reverse-count equation established above. Apply it to s,u,a,f,e,c,z,C,T. It supplies the normal finalized d, actual finalizer equation with operand a.\mathit{num\_digits}=n, exact clamped point, retained count and values, sticky equivalence, and exact fill effects. Replacing f.\mathit{val} and e.\mathit{val} by |F|,E gives the point formula in the statement.
To identify its normal computation with the WHOLE pinned parser, unfold num imp dec2flt decimal seq parse decimal seq and split at the exact guards already resolved in the prefix proof. If the integer residual is empty, the source finalizes a with fractional count zero and fill loop 1. If it is nonempty and nonpoint-headed, it is e/E-headed and the source finalizes a with fractional count zero and fill loop 7. If it is point-headed with zero integer count, the prefix gives exactly loop 2, loop 3, scalar remainder, and full fractional difference, and the source uses fill loop 4. If it is point-headed with nonzero integer count, the prefix gives loop 5, scalar remainder, and the same full difference, and the source uses fill loop 6. The fill equations of DecimalSeqDuplicateLoops replace loops 7, 4, and 6 by loop 1 on these SAME arrays and selected counts. Every arm's trim/cap operation is the one in the finalization theorem and uses the untrimmed scan count in its finalizer, even when the stored count is already capped. Substitute the actual exponent equation in each arm. Its execution is normal, so sequencing it after the trim/cap and before the finalizer (as the source does) yields exactly the normal results constructed above. Thus all binds return the shown values in the source order, proving \texttt{parse\_decimal\_seq}(s)=\texttt{ok}\ d.
For the last clauses, if C=[] then T=[], hence r=0, false flag, point value zero and therefore I32 zero. The fill cell equation sets all j<19 to zero. Conversely if C\ne[], T cannot be empty: its decomposition would otherwise make C a nonempty zero list, contradicting its nonzero head. Thus r=\min(|T|,768)>0. Trimming trailing zeros from this nonempty C leaves its first digit unchanged. That digit is nonzero and below ten by validity, so it is at least one. The stored prefix equation at index zero supplies the claimed output cell. This also proves the equivalence C=[]\leftrightarrow r=0.
All normality statements used here were CONSTRUCTED from digit and source length bounds; no normal public trace, A/B hypothesis, or slow-correctness theorem was used. For any other equation of this same parser to \texttt{ok}\ d', equality with the constructed normal equation and injectivity give d'=d, transporting all of the certificate. In particular the normal-existence conjunct is already available on every A-bounded numeric body, as a restriction of this stronger source-valid construction.

Lean proof


  classical
  dsimp only
  let F := match x.fractionDigits with | none => [] | some ds => ds
  let S := x.integerDigits ++ F
  let C := S.dropWhile (fun z => z == 0)
  let T := (C.reverse.dropWhile (fun z => z == 0)).reverse
  obtain ⟨rest, scan, f, hscan, hrest, hcount, hfval, hcursorBound,
    hfsource, hSsource, hscanpoint, hscanflag, hscancells, hscandigits⟩ :=
    P495_T1_SignificandScan s x hsource hsign hvalid hbytes
  change scan.num_digits.val = C.length at hcount
  change f.val = F.length at hfval
  change S.length <= s.val.length at hSsource
  change (forall j, j < 768 -> (scan.digits.val[j]?).map (fun b => b.val) =
    if j < min C.length 768 then C[j]? else some 0) at hscancells
  obtain ⟨e, hexp, heval⟩ := P495_T1_ExponentSuffix rest x hvalid hrest
  have hstored : (scan.digits.val.take (min C.length 768)).map (fun b => b.val) =
      C.take (min C.length 768) := by
    apply List.ext_getElem?
    intro j
    by_cases hj : j < min C.length 768
    · have hj768 : j < 768 := lt_of_lt_of_le hj (Nat.min_le_right _ _)
      simpa only [List.getElem?_map, List.getElem?_take, hj, if_true] using
        (hscancells j hj768)
    · simp only [List.getElem?_map, List.getElem?_take, hj, if_false, Option.map_none]
  have hnsource : scan.num_digits.val <= s.val.length := by omega
  have hrestle : rest.val.length <= s.val.length := by omega
  obtain ⟨consumed, hconsumed, _⟩ := WP.spec_imp_exists
    (UScalar.sub_spec (x := Slice.len s) (y := Slice.len rest) (by
      simpa only [Slice.len_val] using hrestle))
  obtain ⟨ell, q, hell, hq, hSsplit, hCsplit, hChead, hTlast⟩ :=
    DecimalDigitTrimDecomposition S
  change C = T ++ List.replicate q 0 at hCsplit
  change q = C.length - T.length at hq
  change C = [] ∨ C.head? ≠ some 0 at hChead
  have hzerosExists : exists zeros : Std.Usize,
      C = T ++ List.replicate zeros.val 0 /\
      (C ≠ [] -> num.imp.dec2flt.decimal_seq.count_trailing_zeros s consumed =
        ok zeros) := by
    by_cases hC : C = []
    · refine ⟨0#usize, ?_, ?_⟩
      · have hT : T = [] := by simp only [T, hC, List.reverse_nil, List.dropWhile_nil]
        simp [hC, hT]
      · intro hne
        exact False.elim (hne hC)
    · obtain ⟨c, zeros, hc, hz, hzval, _, _⟩ :=
        P495_T1_TrailingCount s rest x hsource hsign hvalid hbytes hrest hC
      have hcEq : consumed = c := Result.ok.inj (hconsumed.symm.trans hc)
      refine ⟨zeros, ?_, ?_⟩
      · change zeros.val = C.length - T.length at hzval
        rw [hzval, ← hq]
        exact hCsplit
      · intro _
        simpa only [hcEq] using hz
  obtain ⟨zeros, hsplit, hzeros⟩ := hzerosExists
  obtain ⟨d, hfinish, hpoint, hpointval, hdcount, hdprefix, hdflag,
    hpreserved, hcells, hdigits⟩ :=
    P495_T1_FinalizationExact s rest scan f e consumed zeros C T hcount
      (le_trans hnsource hsource) (le_trans hfsource hsource) hscanflag hsplit
      hconsumed hzeros hstored hscandigits
  have hfactor := P800_T1_ParserFactorization s
  dsimp only at hfactor
  simp only [hscan, bind_tc_ok, uncurry_apply_pair, hexp] at hfactor
  have hparse : num.imp.dec2flt.decimal_seq.parse_decimal_seq s = ok d :=
    hfactor.trans hfinish
  have hTzero (hC : C = []) : T = [] := by
    simp only [T, hC, List.reverse_nil, List.dropWhile_nil]
  have hTnonzero (hC : C ≠ []) : T ≠ [] := by
    intro hT
    have hrep : C = List.replicate zeros.val 0 := by
      simpa only [hT, List.nil_append] using hsplit
    have hhead := hChead.resolve_left hC
    cases hz : zeros.val with
    | zero => exact hC (by simpa only [hz, List.replicate_zero] using hrep)
    | succ k =>
        apply hhead
        simp only [hrep, hz, List.replicate_succ, List.head?_cons]
  have hcountpos (hC : C ≠ []) : 0 < d.num_digits.val := by
    have hTpos : 0 < T.length := List.length_pos_iff.mpr (hTnonzero hC)
    rw [hdcount]
    omega
  refine ⟨d, scan, scan.num_digits, f, e, hparse, rfl, hcount, hfval, heval,
    hnsource, hfsource, hSsource, hpoint, ?_, hdcount, ?_, hdprefix, hdflag,
    hscanpoint, hscanflag, hstored, hpreserved, hcells, hdigits, ?_, ?_, ?_⟩
  · simpa only [hfval, heval] using hpointval
  · rw [hdcount]
    exact Nat.min_le_right _ _
  · constructor
    · intro hC
      simp only [hdcount, hTzero hC, List.length_nil, Nat.zero_min]
    · intro hz
      by_contra hC
      have := hcountpos hC
      omega
  · intro hC
    change C = [] at hC
    have hz : d.num_digits.val = 0 := by
      simp only [hdcount, hTzero hC, List.length_nil, Nat.zero_min]
    refine ⟨?_, ?_, ?_⟩
    · apply IScalar.eq_of_val_eq
      simpa only [hC, List.length_nil, if_true] using hpointval
    · have hnot : ¬ d.truncated = true := by
        rw [hdflag, hTzero hC]
        simp only [List.length_nil]
        omega
      cases hb : d.truncated
      · rfl
      · exact False.elim (hnot hb)
    · intro j hj
      have hj768 : j < 768 := by omega
      simpa only [hz, Nat.zero_le, hj, and_self, if_true] using hcells j hj768
  · intro hC
    change C ≠ [] at hC
    have hpositive := hcountpos hC
    cases hc : C with
    | nil => exact False.elim (hC hc)
    | cons digit tail =>
        have hdne : digit ≠ 0 := by
          have hh := hChead.resolve_left hC
          simpa only [hc, List.head?_cons, ne_eq, Option.some.injEq] using hh
        have hscan0 : (scan.digits.val[0]?).map (fun b => b.val) = some digit := by
          have hj : 0 < min C.length 768 := by simp only [hc, List.length_cons]; omega
          have hcell := hscancells 0 (by omega)
          rw [if_pos hj] at hcell
          simpa only [hc, List.getElem?_cons_zero] using hcell
        have hdlt : digit < 10 := by
          cases hb : scan.digits.val[0]? with
          | none =>
              simp only [hb, Option.map_none] at hscan0
              cases hscan0
          | some b =>
              have hbval : b.val = digit := by
                simpa only [hb, Option.map_some, Option.some.injEq] using hscan0
              rw [← hbval]
              exact hscandigits b (List.mem_of_getElem? hb)
        refine ⟨digit, ?_, by omega, hdlt, ?_⟩
        · change C[0]? = some digit
          rw [hc]
          rfl
        · have hpreserve0 : d.digits.val[0]? = scan.digits.val[0]? := by
            have hnot : ¬ (d.num_digits.val <= 0 /\ 0 < 19) := by omega
            simpa only [hnot, if_false] using hcells 0 (by omega)
          rw [hpreserve0]
          exact hscan0

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P495_T1_SignificandScan
import Tablet.P495_T1_ExponentSuffix
import Tablet.P495_T1_TrailingCount
import Tablet.P495_T1_FinalizationExact
import Tablet.P800_T1_ParserFactorization

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P495_T1_DecimalSeqReconstruction]
theorem P495_T1_DecimalSeqReconstruction (s : Slice Std.U8) (x : DecimalLexeme)
    (hsource : SourceValidByteSlice s) (hsign : x.leadingSign = none)
    (hvalid : DecimalGoalVocabularyDefault.validNumeric x)
    (hbytes : DecimalGoalVocabularyDefault.renderNumeric x =
      DecimalGoalVocabularyDefault.bytes s) :
    let F := match x.fractionDigits with | none => [] | some ds => ds
    let S := x.integerDigits ++ F
    let C := S.dropWhile (fun z => z == 0)
    let T := (C.reverse.dropWhile (fun z => z == 0)).reverse
    exists (d scan : num.imp.dec2flt.decimal_seq.DecimalSeq)
      (n f : Std.Usize) (e : Std.I64),
      num.imp.dec2flt.decimal_seq.parse_decimal_seq s = ok d /\
      n = scan.num_digits /\ n.val = C.length /\ f.val = F.length /\
      e.val = DecimalGoalVocabularyDefault.accumulatedExplicitExponent x /\
      n.val <= s.val.length /\ f.val <= s.val.length /\ S.length <= s.val.length /\
      num.imp.dec2flt.decimal_seq.final_decimal_point n f e = ok d.decimal_point /\
      d.decimal_point.val = (if C.length = 0 then 0 else
        max (-2047) (min 2047 ((C.length : Int) - F.length +
          DecimalGoalVocabularyDefault.accumulatedExplicitExponent x))) /\
      d.num_digits.val = min T.length 768 /\ d.num_digits.val <= 768 /\
      (d.digits.val.take d.num_digits.val).map (fun b => b.val) =
        T.take d.num_digits.val /\
      (d.truncated = true <-> 768 < T.length) /\
      scan.decimal_point = 0#i32 /\ scan.truncated = false /\
      (scan.digits.val.take (min C.length 768)).map (fun b => b.val) =
        C.take (min C.length 768) /\
      d.digits.val.take d.num_digits.val = scan.digits.val.take d.num_digits.val /\
      (forall j, j < 768 -> d.digits.val[j]? =
        if d.num_digits.val <= j /\ j < 19 then some 0#u8 else scan.digits.val[j]?) /\
      (forall b, b ∈ d.digits.val -> b.val < 10) /\
      (C = [] <-> d.num_digits.val = 0) /\
      (C = [] -> d.decimal_point = 0#i32 /\ d.truncated = false /\
        forall j, j < 19 -> d.digits.val[j]? = some 0#u8) /\
      (C ≠ [] -> exists digit : Nat,
        C[0]? = some digit /\ 1 <= digit /\ digit < 10 /\
        (d.digits.val[0]?).map (fun b => b.val) = some digit) := by
-- BODY
  classical
  dsimp only
  let F := match x.fractionDigits with | none => [] | some ds => ds
  let S := x.integerDigits ++ F
  let C := S.dropWhile (fun z => z == 0)
  let T := (C.reverse.dropWhile (fun z => z == 0)).reverse
  obtain ⟨rest, scan, f, hscan, hrest, hcount, hfval, hcursorBound,
    hfsource, hSsource, hscanpoint, hscanflag, hscancells, hscandigits⟩ :=
    P495_T1_SignificandScan s x hsource hsign hvalid hbytes
  change scan.num_digits.val = C.length at hcount
  change f.val = F.length at hfval
  change S.length <= s.val.length at hSsource
  change (forall j, j < 768 -> (scan.digits.val[j]?).map (fun b => b.val) =
    if j < min C.length 768 then C[j]? else some 0) at hscancells
  obtain ⟨e, hexp, heval⟩ := P495_T1_ExponentSuffix rest x hvalid hrest
  have hstored : (scan.digits.val.take (min C.length 768)).map (fun b => b.val) =
      C.take (min C.length 768) := by
    apply List.ext_getElem?
    intro j
    by_cases hj : j < min C.length 768
    · have hj768 : j < 768 := lt_of_lt_of_le hj (Nat.min_le_right _ _)
      simpa only [List.getElem?_map, List.getElem?_take, hj, if_true] using
        (hscancells j hj768)
    · simp only [List.getElem?_map, List.getElem?_take, hj, if_false, Option.map_none]
  have hnsource : scan.num_digits.val <= s.val.length := by omega
  have hrestle : rest.val.length <= s.val.length := by omega
  obtain ⟨consumed, hconsumed, _⟩ := WP.spec_imp_exists
    (UScalar.sub_spec (x := Slice.len s) (y := Slice.len rest) (by
      simpa only [Slice.len_val] using hrestle))
  obtain ⟨ell, q, hell, hq, hSsplit, hCsplit, hChead, hTlast⟩ :=
    DecimalDigitTrimDecomposition S
  change C = T ++ List.replicate q 0 at hCsplit
  change q = C.length - T.length at hq
  change C = [] ∨ C.head? ≠ some 0 at hChead
  have hzerosExists : exists zeros : Std.Usize,
      C = T ++ List.replicate zeros.val 0 /\
      (C ≠ [] -> num.imp.dec2flt.decimal_seq.count_trailing_zeros s consumed =
        ok zeros) := by
    by_cases hC : C = []
    · refine ⟨0#usize, ?_, ?_⟩
      · have hT : T = [] := by simp only [T, hC, List.reverse_nil, List.dropWhile_nil]
        simp [hC, hT]
      · intro hne
        exact False.elim (hne hC)
    · obtain ⟨c, zeros, hc, hz, hzval, _, _⟩ :=
        P495_T1_TrailingCount s rest x hsource hsign hvalid hbytes hrest hC
      have hcEq : consumed = c := Result.ok.inj (hconsumed.symm.trans hc)
      refine ⟨zeros, ?_, ?_⟩
      · change zeros.val = C.length - T.length at hzval
        rw [hzval, ← hq]
        exact hCsplit
      · intro _
        simpa only [hcEq] using hz
  obtain ⟨zeros, hsplit, hzeros⟩ := hzerosExists
  obtain ⟨d, hfinish, hpoint, hpointval, hdcount, hdprefix, hdflag,
    hpreserved, hcells, hdigits⟩ :=
    P495_T1_FinalizationExact s rest scan f e consumed zeros C T hcount
      (le_trans hnsource hsource) (le_trans hfsource hsource) hscanflag hsplit
      hconsumed hzeros hstored hscandigits
  have hfactor := P800_T1_ParserFactorization s
  dsimp only at hfactor
  simp only [hscan, bind_tc_ok, uncurry_apply_pair, hexp] at hfactor
  have hparse : num.imp.dec2flt.decimal_seq.parse_decimal_seq s = ok d :=
    hfactor.trans hfinish
  have hTzero (hC : C = []) : T = [] := by
    simp only [T, hC, List.reverse_nil, List.dropWhile_nil]
  have hTnonzero (hC : C ≠ []) : T ≠ [] := by
    intro hT
    have hrep : C = List.replicate zeros.val 0 := by
      simpa only [hT, List.nil_append] using hsplit
    have hhead := hChead.resolve_left hC
    cases hz : zeros.val with
    | zero => exact hC (by simpa only [hz, List.replicate_zero] using hrep)
    | succ k =>
        apply hhead
        simp only [hrep, hz, List.replicate_succ, List.head?_cons]
  have hcountpos (hC : C ≠ []) : 0 < d.num_digits.val := by
    have hTpos : 0 < T.length := List.length_pos_iff.mpr (hTnonzero hC)
    rw [hdcount]
    omega
  refine ⟨d, scan, scan.num_digits, f, e, hparse, rfl, hcount, hfval, heval,
    hnsource, hfsource, hSsource, hpoint, ?_, hdcount, ?_, hdprefix, hdflag,
    hscanpoint, hscanflag, hstored, hpreserved, hcells, hdigits, ?_, ?_, ?_⟩
  · simpa only [hfval, heval] using hpointval
  · rw [hdcount]
    exact Nat.min_le_right _ _
  · constructor
    · intro hC
      simp only [hdcount, hTzero hC, List.length_nil, Nat.zero_min]
    · intro hz
      by_contra hC
      have := hcountpos hC
      omega
  · intro hC
    change C = [] at hC
    have hz : d.num_digits.val = 0 := by
      simp only [hdcount, hTzero hC, List.length_nil, Nat.zero_min]
    refine ⟨?_, ?_, ?_⟩
    · apply IScalar.eq_of_val_eq
      simpa only [hC, List.length_nil, if_true] using hpointval
    · have hnot : ¬ d.truncated = true := by
        rw [hdflag, hTzero hC]
        simp only [List.length_nil]
        omega
      cases hb : d.truncated
      · rfl
      · exact False.elim (hnot hb)
    · intro j hj
      have hj768 : j < 768 := by omega
      simpa only [hz, Nat.zero_le, hj, and_self, if_true] using hcells j hj768
  · intro hC
    change C ≠ [] at hC
    have hpositive := hcountpos hC
    cases hc : C with
    | nil => exact False.elim (hC hc)
    | cons digit tail =>
        have hdne : digit ≠ 0 := by
          have hh := hChead.resolve_left hC
          simpa only [hc, List.head?_cons, ne_eq, Option.some.injEq] using hh
        have hscan0 : (scan.digits.val[0]?).map (fun b => b.val) = some digit := by
          have hj : 0 < min C.length 768 := by simp only [hc, List.length_cons]; omega
          have hcell := hscancells 0 (by omega)
          rw [if_pos hj] at hcell
          simpa only [hc, List.getElem?_cons_zero] using hcell
        have hdlt : digit < 10 := by
          cases hb : scan.digits.val[0]? with
          | none =>
              simp only [hb, Option.map_none] at hscan0
              cases hscan0
          | some b =>
              have hbval : b.val = digit := by
                simpa only [hb, Option.map_some, Option.some.injEq] using hscan0
              rw [← hbval]
              exact hscandigits b (List.mem_of_getElem? hb)
        refine ⟨digit, ?_, by omega, hdlt, ?_⟩
        · change C[0]? = some digit
          rw [hc]
          rfl
        · have hpreserve0 : d.digits.val[0]? = scan.digits.val[0]? := by
            have hnot : ¬ (d.num_digits.val <= 0 /\ 0 < 19) := by omega
            simpa only [hnot, if_false] using hcells 0 (by omega)
          rw [hpreserve0]
          exact hscan0

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (79)
More program dependencies (46)
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 79 entries
Technical checking records
Local closure summary
{
  "node": "P495_T1_DecimalSeqReconstruction",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "699ff912602cb5491e81f0291c95b8de7855abb9b872abf214a16393a7233fab",
  "active_statement_hash": "ce8a8ee04db04bc0a3d7f863dc840cd9439747ff3afe495d133cb849e07b10f6",
  "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-189",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalDigitTrimDecomposition": "74d5424585de54f0",
    "P495_T1_ExponentSuffix": "8623b3a9ab4699aa",
    "P495_T1_FinalizationExact": "5357e368ceddec3e",
    "P495_T1_SignificandScan": "ba2621f7b2882a3d",
    "P495_T1_TrailingCount": "fc2f48988132719a",
    "P800_T1_ParserFactorization": "e622a8cbbd0f7b00"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "4da7f295a9b85b50",
    "DecimalGoalVocabularyDefault": "71a18a6c119a3cdc",
    "DecimalLexeme": "303e59678842cea4",
    "P495_T1_SignificandScan": "55eb6bce0e8a4131",
    "P495_T1_TrailingCount": "55eb6bce0e8a4131",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "13e3cec939d02f51",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_Insts_CoreDefaultDefault_default": "7b9921904495bc2a",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS": "39f6cb231ef80388",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS_WITHOUT_OVERFLOW": "65634ac95536dcca",
    "num_imp_dec2flt_decimal_seq_count_trailing_zeros": "7a77bc9e01c1a09b",
    "num_imp_dec2flt_decimal_seq_final_decimal_point": "4f8088dec06d629a",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "89c1cc8d6b6338d0",
    "num_imp_dec2flt_decimal_seq_parse_digits_into_seq": "8b2cc3a350f40ce1",
    "num_imp_dec2flt_parse_parse_scientific": "447f722d5841d2c5"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:c068b23e9086013bea50998082090fe208da2705454b93c70a916488bcdef6d9",
  "current_fingerprint": "sound-v2:c068b23e9086013bea50998082090fe208da2705454b93c70a916488bcdef6d9",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}