P835_T1_PartialRunForwardA

Lean checked

Statement

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

Lemma · Forward on-normal lexical certificate from significand runs

Let s be nonempty with |s|\le3458764513820540928, and suppose s.\mathit{val}=I++(\text{if }p\text{ then }[46]++F++T \text{ else }T). Require every byte of I,F to lie in [48,57], and T to be empty or nondigit-headed. When p is false, require F=[] and any head of T to differ from 46. Suppose the actual partial-number parser returns \texttt{ok}(o). For every o=\texttt{some}(d,k) there are a lexeme x with no leading sign, valid according to DecimalGoalVocabularyDefault, and a byte list R, such that \operatorname{bytes}(s)=\operatorname{renderNumeric}(x)++ \operatorname{map}(\mathit{val},R) and k.\mathit{val}=|\operatorname{renderNumeric}(x)|. R is empty or nondigit-headed. If x has no exponent, every head of R differs from 69 and 101, and also differs from 46 when x has no fraction.

Lean statement

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

import Tablet.P835_T1_PartialContinuationA
import Tablet.P835_T1_FinishOnNormalA
import Tablet.P835_T1_DecodedRuns
import Tablet.P367_T1_NumberHelperScientificScan
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P835_T1_PartialRunForwardA]
theorem P835_T1_PartialRunForwardA
    (s : Slice Std.U8) (integer fraction tail : List Std.U8) (point : Bool)
    (hne : s.val ≠ []) (hlen : s.val.length <= 3458764513820540928)
    (hshape : s.val = integer ++ (if point then 46#u8 :: (fraction ++ tail) else tail))
    (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)
    (ht : forall b rest, tail = b :: rest -> ¬ (48 <= b.val /\ b.val <= 57))
    (hnoPoint : point = false -> forall b rest, tail = b :: rest -> b ≠ 46#u8)
    (result : Option (num.imp.dec2flt.decimal.Decimal × Std.Usize))
    (hnormal : num.imp.dec2flt.parse.parse_partial_number s = ok result) :
     forall d consumed, result = some (d, consumed) ->
        exists (x : DecimalLexeme) (r : List Std.U8),
          x.leadingSign = none /\ DecimalGoalVocabularyDefault.validNumeric x /\
          DecimalGoalVocabularyDefault.bytes s =
            DecimalGoalVocabularyDefault.renderNumeric x ++ r.map (fun b => b.val) /\
          (forall b rest, r = b :: rest -> ¬ (48 <= b.val /\ b.val <= 57)) /\
          (x.exponent = none -> forall b rest, r = b :: rest ->
            b ≠ 69#u8 /\ b ≠ 101#u8 /\
              (x.fractionDigits = none -> b ≠ 46#u8)) /\
          consumed.val = (DecimalGoalVocabularyDefault.renderNumeric x).length := 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 PartialContinuationA to exactly the stated decomposition and guards. Obtain its integer-end slice i, significand-end slice t, word w, count n and base b, with t.\mathit{val}=T and n.\mathit{val}=|I|+|F|, and use the continuation functions C,E specified by that node. Since the given output is Some, its count-zero branch cannot have been taken: substitution would equate ok None and ok Some. Thus n\ne0, and its nonnegative count value makes |I|+|F|>0. The continuation after splitting t equals the given ok Some.
If T=[], split-first returns None by ModelSliceSplitFirst, and the continuation is C(b,0,t). If T has a head other than 101 and 69, the same model split exposes that head and the continuation is again C(b,0,t). In both cases use no exponent and residual R=T. The decomposition says s.\mathit{val}=P++t.\mathit{val} with P=I++(\text{if }p\text{ then }[46]++F\text{ else }[]). Apply FinishOnNormalA to this successful C call and suffix equation: its Some pair has consumed value |P|. Injectivity of Some and of pairs identifies that length with the given k. Apply DecodedRuns with absent exponent. It supplies the unsigned valid x, its point-presence equivalence, and rendering equal to the value map of P. Mapping the source decomposition proves the rendering equation; maps preserve length, giving the consumed-length equation. Nondigit-headedness is the stated condition on T. The residual marker guards follow from the empty or nonmarker case; the point guard follows from the stated absent-point condition and the fraction-presence equivalence.
Otherwise write T=c::U, where c is either 101 or 69. ModelSliceSplitFirst supplies the actual suffix slice u with u.\mathit{val}=U; both marker branches are the identical E(u) computation in the continuation theorem. Apply NumberHelperScientificScan to this u. It supplies optional sign \sigma, digit run J, residual R, optional exponent v and slice r, with u.\mathit{val}=\operatorname{signBytes}(\sigma)++J++R, all J bytes in [48,57], nondigit-headed R, r.\mathit{val}=R, and a successful scientific call. Its statement says v=\texttt{none} exactly when J=[]. If v were None, ModelOptionBranch would choose Break and ModelOptionFromResidual would return None, contradicting the given Some output. Hence v=\texttt{some}(a) and J\ne[]. The Some branch continues by the checked addition b+a. A failure or divergence of that addition propagates through the Result bind, contradicting the given normal result. Its successful case supplies e, and the continuation is C(e,a,r).
Choose the uppercase flag true exactly when c=69; hence the rendered marker is the actual c. Set P=I++(\text{if }p\text{ then }[46]++F\text{ else }[])++ [c]++\operatorname{signBytes}(\sigma)++J. The source and scientific decompositions give s.\mathit{val}=P++r.\mathit{val}. Apply FinishOnNormalA again to get the saved length |P|, identifying its Some pair with the given pair. Apply DecodedRuns with exponent (c=69,\sigma,J): every hypothesis holds by the positive significand count and scientific scan facts. Its rendering is the value map of P, so the source equation and map-length preservation give all claimed equations. Its exponent is present, making the no-exponent guards vacuous. The residual digit guard is the scientific scan's guard. This shared construction retains both marker cases, all optional signs, arbitrarily long J, and every allowed residual.

Lean proof


  obtain ⟨intEnd, sigEnd, word, total, base, hsigEnd, htotal, hparser⟩ :=
    P835_T1_PartialContinuationA s integer fraction tail point hne hlen
      hshape hnoFraction hd hf ht hnoPoint
  let finish := fun (exponent explicit : Std.I64) (rest : Slice Std.U8) => do
    let offset ← SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from rest s
    let len ← lift (IScalar.hcast .Usize offset)
    if total <= 19#isize then
      ok (some (num.imp.dec2flt.decimal.Decimal.mk exponent word false false, len))
    else
      let more ← total - 19#isize
      let adjusted ← num.imp.dec2flt.parse.adjust_many_digit_count s more
      if adjusted > 0#isize then
        let (manyWord, manyExp) ← num.imp.dec2flt.parse.parse_many_digits s intEnd explicit
        ok (some (num.imp.dec2flt.decimal.Decimal.mk manyExp manyWord false true, len))
      else
        ok (some (num.imp.dec2flt.decimal.Decimal.mk exponent word false false, len))
  let scientific := fun (next : Slice Std.U8) => do
    let (value, rest) ← num.imp.dec2flt.parse.parse_scientific next
    let cf ← core.option.Option.Insts.CoreOpsTry_traitTry.branch value
    match cf with
    | core.ops.control_flow.ControlFlow.Continue explicit => do
      let exponent ← base + explicit
      finish exponent explicit rest
    | core.ops.control_flow.ControlFlow.Break residual =>
      core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual
        (num.imp.dec2flt.decimal.Decimal × Std.Usize) residual
  let afterSignificand : Result (Option (num.imp.dec2flt.decimal.Decimal × Std.Usize)) := do
    let o ← core.slice.Slice.split_first sigEnd
    match o with
    | none => finish base 0#i64 sigEnd
    | some (c, next) =>
      if c = 101#u8 then scientific next
      else if c = 69#u8 then scientific next
      else finish base 0#i64 sigEnd
  
  change num.imp.dec2flt.parse.parse_partial_number s =
    (if total = 0#isize then ok none else afterSignificand) at hparser
  intro d consumed hres
  have htne : total ≠ 0#isize := by
    intro hz
    rw [hparser, hz] at hnormal
    simp [hres] at hnormal
  have hpos : 0 < integer.length + fraction.length := by
    have hvalNe : total.val ≠ 0 := by
      intro hz
      apply htne
      apply IScalar.eq_of_val_eq
      simpa using hz
    rw [htotal] at hvalNe
    omega
  have hafterNormal : afterSignificand = ok (some (d, consumed)) := by
    rw [hparser] at hnormal
    simpa [htne, hres] using hnormal
  have emit : forall (exponent explicit : Std.I64) (rest : Slice Std.U8)
      (exps : Option (Bool × Option Bool × List Std.U8)) (r : List Std.U8),
      (forall upper sign digits, exps = some (upper, sign, digits) ->
        digits ≠ [] /\ forall b, b ∈ digits -> 48 <= b.val /\ b.val <= 57) ->
      s.val = (integer ++ (if point then 46#u8 :: fraction else []) ++
        (match (generalizing := false) exps with
        | none => []
        | some (upper, sign, digits) => (if upper then 69#u8 else 101#u8) ::
          (match (generalizing := false) sign with | none => [] | some neg => [if neg then 45#u8 else 43#u8]) ++
          digits)) ++ rest.val ->
      rest.val = r ->
      (forall b bs, r = b :: bs -> ¬ (48 <= b.val /\ b.val <= 57)) ->
      (exps = none -> forall b bs, r = b :: bs ->
        b ≠ 69#u8 /\ b ≠ 101#u8 /\ (point = false -> b ≠ 46#u8)) ->
      finish exponent explicit rest = ok (some (d, consumed)) ->
      exists (x : DecimalLexeme) (r : List Std.U8),
        x.leadingSign = none /\ DecimalGoalVocabularyDefault.validNumeric x /\
        DecimalGoalVocabularyDefault.bytes s =
          DecimalGoalVocabularyDefault.renderNumeric x ++ r.map (fun b => b.val) /\
        (forall b bs, r = b :: bs -> ¬ (48 <= b.val /\ b.val <= 57)) /\
        (x.exponent = none -> forall b bs, r = b :: bs ->
          b ≠ 69#u8 /\ b ≠ 101#u8 /\ (x.fractionDigits = none -> b ≠ 46#u8)) /\
        consumed.val = (DecimalGoalVocabularyDefault.renderNumeric x).length := by
    intro exponent explicit rest exps r he hp hr hrt hguards hfinish
    obtain ⟨x, hsign, hvalid, hfrac, hexp, hrender⟩ :=
      P835_T1_DecodedRuns integer fraction point exps hnoFraction hd hf hpos he
    obtain ⟨d', k, hresult, hk⟩ :=
      P835_T1_FinishOnNormalA s intEnd rest _ word total exponent explicit
        (some (d, consumed)) hlen hp hfinish
    have hc : consumed = k := congrArg Prod.snd (Option.some.inj hresult)
    refine ⟨x, r, hsign, hvalid, ?_, hrt, ?_, ?_⟩
    · change s.val.map (fun b => b.val) = _
      rw [hp, List.map_append, hr, hrender]
      cases exps with
      | none => rfl
      | some p =>
        rcases p with ⟨u, sg, ds⟩
        cases sg <;> rfl
    · intro hx b bs hb
      have hg := hguards (hexp.mp hx) b bs hb
      exact ⟨hg.1, hg.2.1, fun h => hg.2.2 (hfrac.mp h)⟩
    · have hl := congrArg List.length hrender
      simp only [List.length_map] at hl
      rw [hc, hk, hl]
      cases exps with
      | none => rfl
      | some p =>
        rcases p with ⟨u, sg, ds⟩
        cases sg <;> rfl
  have noExponent : forall
      (hm : forall b bs, tail = b :: bs -> b ≠ 69#u8 /\ b ≠ 101#u8),
      finish base 0#i64 sigEnd = ok (some (d, consumed)) ->
      exists (x : DecimalLexeme) (r : List Std.U8),
        x.leadingSign = none /\ DecimalGoalVocabularyDefault.validNumeric x /\
        DecimalGoalVocabularyDefault.bytes s =
          DecimalGoalVocabularyDefault.renderNumeric x ++ r.map (fun b => b.val) /\
        (forall b bs, r = b :: bs -> ¬ (48 <= b.val /\ b.val <= 57)) /\
        (x.exponent = none -> forall b bs, r = b :: bs ->
          b ≠ 69#u8 /\ b ≠ 101#u8 /\ (x.fractionDigits = none -> b ≠ 46#u8)) /\
        consumed.val = (DecimalGoalVocabularyDefault.renderNumeric x).length := by
    intro hm hfinish
    apply emit base 0#i64 sigEnd none tail (by simp)
    · rw [hshape, hsigEnd]
      cases point <;> simp [List.append_assoc]
    · exact hsigEnd
    · exact ht
    · intro _ b bs hb
      exact ⟨(hm b bs hb).1, (hm b bs hb).2, fun hp => hnoPoint hp b bs hb⟩
    · exact hfinish
  cases htval : tail with
  | nil =>
    have hsplit : core.slice.Slice.split_first sigEnd = ok none := by
      have he : sigEnd = (⟨[], by simp⟩ : Slice Std.U8) :=
        (Slice.eq_iff _ _).2 (hsigEnd.trans htval)
      rw [he]
      rfl
    apply noExponent (by simp [htval])
    simpa [afterSignificand, hsplit] using hafterNormal
  | cons b bs =>
    let next : Slice Std.U8 := ⟨bs, by
      have hp := sigEnd.property
      rw [hsigEnd, htval] at hp
      simp only [List.length_cons] at hp
      omega⟩
    have hsplit : core.slice.Slice.split_first sigEnd = ok (some (b, next)) := by
      have he : sigEnd = (⟨b :: bs, by
        rw [← htval, ← hsigEnd]
        exact sigEnd.property⟩ : Slice Std.U8) :=
        (Slice.eq_iff _ _).2 (hsigEnd.trans htval)
      rw [he]
      rfl
    by_cases hm : b = 101#u8 ∨ b = 69#u8
    · have hscient : scientific next = ok (some (d, consumed)) := by
        rcases hm with hlow | hup
        · simpa [afterSignificand, hsplit, hlow] using hafterNormal
        · simpa [afterSignificand, hsplit, hup] using hafterNormal
      obtain ⟨sign, digits, residual, value, rest, hbytesSci,
        hdigits, hresidual, hparse, hrest, hnone, hvalue⟩ :=
        P367_T1_NumberHelperScientificScan next
      cases hv : value with
      | none =>
        simp [scientific, hparse, hv,
          core.option.Option.Insts.CoreOpsTry_traitTry.branch,
          ModelOptionBranch, ModelOptionFromResidual,
          core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual] at hscient
      | some explicit =>
        have hdigitsNe : digits ≠ [] := by
          intro he
          have hnone' := hnone.mpr he
          simp [hv] at hnone'
        cases haddExp : base + explicit with
        | fail err =>
          simp [scientific, hparse, hv,
            core.option.Option.Insts.CoreOpsTry_traitTry.branch,
            ModelOptionBranch, haddExp] at hscient
        | div =>
          simp [scientific, hparse, hv,
            core.option.Option.Insts.CoreOpsTry_traitTry.branch,
            ModelOptionBranch, haddExp] at hscient
        | ok exponent =>
          have hfinish : finish exponent explicit rest = ok (some (d, consumed)) := by
            simpa [scientific, hparse, hv,
              core.option.Option.Insts.CoreOpsTry_traitTry.branch,
              ModelOptionBranch, haddExp] using hscient
          let upper : Bool := if b = 69#u8 then true else false
          have hmarker : b = (if upper then 69#u8 else 101#u8) := by
            rcases hm with hlow | hup
            · simp [upper, hlow]
            · simp [upper, hup]
          apply emit exponent explicit rest (some (upper, sign, digits)) residual
          · intro u sg ds heq
            have hp := Option.some.inj heq
            cases hp
            exact ⟨hdigitsNe, hdigits⟩
          · have hbs : bs =
                (match (generalizing := false) sign with | none => [] | some neg => [if neg then 45#u8 else 43#u8]) ++
                digits ++ residual := hbytesSci
            rw [hshape, htval, hbs, hrest, hmarker]
            cases point <;> simp [List.append_assoc]
          · exact hrest
          · exact hresidual
          · simp
          · exact hfinish
    · have hlow : b ≠ 101#u8 := fun h => hm (Or.inl h)
      have hup : b ≠ 69#u8 := fun h => hm (Or.inr h)
      refine noExponent ?_ ?_
      · intro c cs hc
        have hh := htval.symm.trans hc
        have heq : b = c := List.cons.inj hh |>.1
        subst c
        exact ⟨hup, hlow⟩
      · simpa [afterSignificand, hsplit, hlow, hup] using hafterNormal

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P835_T1_PartialContinuationA
import Tablet.P835_T1_FinishOnNormalA
import Tablet.P835_T1_DecodedRuns
import Tablet.P367_T1_NumberHelperScientificScan
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P835_T1_PartialRunForwardA]
theorem P835_T1_PartialRunForwardA
    (s : Slice Std.U8) (integer fraction tail : List Std.U8) (point : Bool)
    (hne : s.val ≠ []) (hlen : s.val.length <= 3458764513820540928)
    (hshape : s.val = integer ++ (if point then 46#u8 :: (fraction ++ tail) else tail))
    (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)
    (ht : forall b rest, tail = b :: rest -> ¬ (48 <= b.val /\ b.val <= 57))
    (hnoPoint : point = false -> forall b rest, tail = b :: rest -> b ≠ 46#u8)
    (result : Option (num.imp.dec2flt.decimal.Decimal × Std.Usize))
    (hnormal : num.imp.dec2flt.parse.parse_partial_number s = ok result) :
     forall d consumed, result = some (d, consumed) ->
        exists (x : DecimalLexeme) (r : List Std.U8),
          x.leadingSign = none /\ DecimalGoalVocabularyDefault.validNumeric x /\
          DecimalGoalVocabularyDefault.bytes s =
            DecimalGoalVocabularyDefault.renderNumeric x ++ r.map (fun b => b.val) /\
          (forall b rest, r = b :: rest -> ¬ (48 <= b.val /\ b.val <= 57)) /\
          (x.exponent = none -> forall b rest, r = b :: rest ->
            b ≠ 69#u8 /\ b ≠ 101#u8 /\
              (x.fractionDigits = none -> b ≠ 46#u8)) /\
          consumed.val = (DecimalGoalVocabularyDefault.renderNumeric x).length := by
-- BODY
  obtain ⟨intEnd, sigEnd, word, total, base, hsigEnd, htotal, hparser⟩ :=
    P835_T1_PartialContinuationA s integer fraction tail point hne hlen
      hshape hnoFraction hd hf ht hnoPoint
  let finish := fun (exponent explicit : Std.I64) (rest : Slice Std.U8) => do
    let offset ← SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from rest s
    let len ← lift (IScalar.hcast .Usize offset)
    if total <= 19#isize then
      ok (some (num.imp.dec2flt.decimal.Decimal.mk exponent word false false, len))
    else
      let more ← total - 19#isize
      let adjusted ← num.imp.dec2flt.parse.adjust_many_digit_count s more
      if adjusted > 0#isize then
        let (manyWord, manyExp) ← num.imp.dec2flt.parse.parse_many_digits s intEnd explicit
        ok (some (num.imp.dec2flt.decimal.Decimal.mk manyExp manyWord false true, len))
      else
        ok (some (num.imp.dec2flt.decimal.Decimal.mk exponent word false false, len))
  let scientific := fun (next : Slice Std.U8) => do
    let (value, rest) ← num.imp.dec2flt.parse.parse_scientific next
    let cf ← core.option.Option.Insts.CoreOpsTry_traitTry.branch value
    match cf with
    | core.ops.control_flow.ControlFlow.Continue explicit => do
      let exponent ← base + explicit
      finish exponent explicit rest
    | core.ops.control_flow.ControlFlow.Break residual =>
      core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual
        (num.imp.dec2flt.decimal.Decimal × Std.Usize) residual
  let afterSignificand : Result (Option (num.imp.dec2flt.decimal.Decimal × Std.Usize)) := do
    let o ← core.slice.Slice.split_first sigEnd
    match o with
    | none => finish base 0#i64 sigEnd
    | some (c, next) =>
      if c = 101#u8 then scientific next
      else if c = 69#u8 then scientific next
      else finish base 0#i64 sigEnd
  
  change num.imp.dec2flt.parse.parse_partial_number s =
    (if total = 0#isize then ok none else afterSignificand) at hparser
  intro d consumed hres
  have htne : total ≠ 0#isize := by
    intro hz
    rw [hparser, hz] at hnormal
    simp [hres] at hnormal
  have hpos : 0 < integer.length + fraction.length := by
    have hvalNe : total.val ≠ 0 := by
      intro hz
      apply htne
      apply IScalar.eq_of_val_eq
      simpa using hz
    rw [htotal] at hvalNe
    omega
  have hafterNormal : afterSignificand = ok (some (d, consumed)) := by
    rw [hparser] at hnormal
    simpa [htne, hres] using hnormal
  have emit : forall (exponent explicit : Std.I64) (rest : Slice Std.U8)
      (exps : Option (Bool × Option Bool × List Std.U8)) (r : List Std.U8),
      (forall upper sign digits, exps = some (upper, sign, digits) ->
        digits ≠ [] /\ forall b, b ∈ digits -> 48 <= b.val /\ b.val <= 57) ->
      s.val = (integer ++ (if point then 46#u8 :: fraction else []) ++
        (match (generalizing := false) exps with
        | none => []
        | some (upper, sign, digits) => (if upper then 69#u8 else 101#u8) ::
          (match (generalizing := false) sign with | none => [] | some neg => [if neg then 45#u8 else 43#u8]) ++
          digits)) ++ rest.val ->
      rest.val = r ->
      (forall b bs, r = b :: bs -> ¬ (48 <= b.val /\ b.val <= 57)) ->
      (exps = none -> forall b bs, r = b :: bs ->
        b ≠ 69#u8 /\ b ≠ 101#u8 /\ (point = false -> b ≠ 46#u8)) ->
      finish exponent explicit rest = ok (some (d, consumed)) ->
      exists (x : DecimalLexeme) (r : List Std.U8),
        x.leadingSign = none /\ DecimalGoalVocabularyDefault.validNumeric x /\
        DecimalGoalVocabularyDefault.bytes s =
          DecimalGoalVocabularyDefault.renderNumeric x ++ r.map (fun b => b.val) /\
        (forall b bs, r = b :: bs -> ¬ (48 <= b.val /\ b.val <= 57)) /\
        (x.exponent = none -> forall b bs, r = b :: bs ->
          b ≠ 69#u8 /\ b ≠ 101#u8 /\ (x.fractionDigits = none -> b ≠ 46#u8)) /\
        consumed.val = (DecimalGoalVocabularyDefault.renderNumeric x).length := by
    intro exponent explicit rest exps r he hp hr hrt hguards hfinish
    obtain ⟨x, hsign, hvalid, hfrac, hexp, hrender⟩ :=
      P835_T1_DecodedRuns integer fraction point exps hnoFraction hd hf hpos he
    obtain ⟨d', k, hresult, hk⟩ :=
      P835_T1_FinishOnNormalA s intEnd rest _ word total exponent explicit
        (some (d, consumed)) hlen hp hfinish
    have hc : consumed = k := congrArg Prod.snd (Option.some.inj hresult)
    refine ⟨x, r, hsign, hvalid, ?_, hrt, ?_, ?_⟩
    · change s.val.map (fun b => b.val) = _
      rw [hp, List.map_append, hr, hrender]
      cases exps with
      | none => rfl
      | some p =>
        rcases p with ⟨u, sg, ds⟩
        cases sg <;> rfl
    · intro hx b bs hb
      have hg := hguards (hexp.mp hx) b bs hb
      exact ⟨hg.1, hg.2.1, fun h => hg.2.2 (hfrac.mp h)⟩
    · have hl := congrArg List.length hrender
      simp only [List.length_map] at hl
      rw [hc, hk, hl]
      cases exps with
      | none => rfl
      | some p =>
        rcases p with ⟨u, sg, ds⟩
        cases sg <;> rfl
  have noExponent : forall
      (hm : forall b bs, tail = b :: bs -> b ≠ 69#u8 /\ b ≠ 101#u8),
      finish base 0#i64 sigEnd = ok (some (d, consumed)) ->
      exists (x : DecimalLexeme) (r : List Std.U8),
        x.leadingSign = none /\ DecimalGoalVocabularyDefault.validNumeric x /\
        DecimalGoalVocabularyDefault.bytes s =
          DecimalGoalVocabularyDefault.renderNumeric x ++ r.map (fun b => b.val) /\
        (forall b bs, r = b :: bs -> ¬ (48 <= b.val /\ b.val <= 57)) /\
        (x.exponent = none -> forall b bs, r = b :: bs ->
          b ≠ 69#u8 /\ b ≠ 101#u8 /\ (x.fractionDigits = none -> b ≠ 46#u8)) /\
        consumed.val = (DecimalGoalVocabularyDefault.renderNumeric x).length := by
    intro hm hfinish
    apply emit base 0#i64 sigEnd none tail (by simp)
    · rw [hshape, hsigEnd]
      cases point <;> simp [List.append_assoc]
    · exact hsigEnd
    · exact ht
    · intro _ b bs hb
      exact ⟨(hm b bs hb).1, (hm b bs hb).2, fun hp => hnoPoint hp b bs hb⟩
    · exact hfinish
  cases htval : tail with
  | nil =>
    have hsplit : core.slice.Slice.split_first sigEnd = ok none := by
      have he : sigEnd = (⟨[], by simp⟩ : Slice Std.U8) :=
        (Slice.eq_iff _ _).2 (hsigEnd.trans htval)
      rw [he]
      rfl
    apply noExponent (by simp [htval])
    simpa [afterSignificand, hsplit] using hafterNormal
  | cons b bs =>
    let next : Slice Std.U8 := ⟨bs, by
      have hp := sigEnd.property
      rw [hsigEnd, htval] at hp
      simp only [List.length_cons] at hp
      omega⟩
    have hsplit : core.slice.Slice.split_first sigEnd = ok (some (b, next)) := by
      have he : sigEnd = (⟨b :: bs, by
        rw [← htval, ← hsigEnd]
        exact sigEnd.property⟩ : Slice Std.U8) :=
        (Slice.eq_iff _ _).2 (hsigEnd.trans htval)
      rw [he]
      rfl
    by_cases hm : b = 101#u8 ∨ b = 69#u8
    · have hscient : scientific next = ok (some (d, consumed)) := by
        rcases hm with hlow | hup
        · simpa [afterSignificand, hsplit, hlow] using hafterNormal
        · simpa [afterSignificand, hsplit, hup] using hafterNormal
      obtain ⟨sign, digits, residual, value, rest, hbytesSci,
        hdigits, hresidual, hparse, hrest, hnone, hvalue⟩ :=
        P367_T1_NumberHelperScientificScan next
      cases hv : value with
      | none =>
        simp [scientific, hparse, hv,
          core.option.Option.Insts.CoreOpsTry_traitTry.branch,
          ModelOptionBranch, ModelOptionFromResidual,
          core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual] at hscient
      | some explicit =>
        have hdigitsNe : digits ≠ [] := by
          intro he
          have hnone' := hnone.mpr he
          simp [hv] at hnone'
        cases haddExp : base + explicit with
        | fail err =>
          simp [scientific, hparse, hv,
            core.option.Option.Insts.CoreOpsTry_traitTry.branch,
            ModelOptionBranch, haddExp] at hscient
        | div =>
          simp [scientific, hparse, hv,
            core.option.Option.Insts.CoreOpsTry_traitTry.branch,
            ModelOptionBranch, haddExp] at hscient
        | ok exponent =>
          have hfinish : finish exponent explicit rest = ok (some (d, consumed)) := by
            simpa [scientific, hparse, hv,
              core.option.Option.Insts.CoreOpsTry_traitTry.branch,
              ModelOptionBranch, haddExp] using hscient
          let upper : Bool := if b = 69#u8 then true else false
          have hmarker : b = (if upper then 69#u8 else 101#u8) := by
            rcases hm with hlow | hup
            · simp [upper, hlow]
            · simp [upper, hup]
          apply emit exponent explicit rest (some (upper, sign, digits)) residual
          · intro u sg ds heq
            have hp := Option.some.inj heq
            cases hp
            exact ⟨hdigitsNe, hdigits⟩
          · have hbs : bs =
                (match (generalizing := false) sign with | none => [] | some neg => [if neg then 45#u8 else 43#u8]) ++
                digits ++ residual := hbytesSci
            rw [hshape, htval, hbs, hrest, hmarker]
            cases point <;> simp [List.append_assoc]
          · exact hrest
          · exact hresidual
          · simp
          · exact hfinish
    · have hlow : b ≠ 101#u8 := fun h => hm (Or.inl h)
      have hup : b ≠ 69#u8 := fun h => hm (Or.inr h)
      refine noExponent ?_ ?_
      · intro c cs hc
        have hh := htval.symm.trans hc
        have heq : b = c := List.cons.inj hh |>.1
        subst c
        exact ⟨hup, hlow⟩
      · simpa [afterSignificand, hsplit, hlow, hup] using hafterNormal

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (68)
More program dependencies (35)
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 66 entries
Technical checking records
Local closure summary
{
  "node": "P835_T1_PartialRunForwardA",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "f548ce55978a65e570f55a46fc7a62732f0c9f6a595d8b53f0249f89d53d2f5e",
  "active_statement_hash": "b2e94efcf48efb686380ffec457400b64cd6cee4fdf3ee7c517201c1aba15183",
  "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_NumberHelperScientificScan": "dd4ec9ae0f1aa797",
    "P835_T1_DecodedRuns": "175be78737803884",
    "P835_T1_FinishOnNormalA": "4f130f3375cbb311",
    "P835_T1_PartialContinuationA": "d026c1de5ccb78ec"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "c08dd4b4aea4abb4",
    "DecimalGoalVocabularyDefault": "71a18a6c119a3cdc",
    "DecimalLexeme": "8ad754cf2c272e73",
    "ModelOptionBranch": "2b227898dbe15e59",
    "ModelOptionFromResidual": "99bee9493878565f",
    "P367_T1_NumberHelperScientificScan": "28ca0a8ac503ee01",
    "P835_T1_DecodedRuns": "8b6f991187c4d1e3",
    "P835_T1_PartialContinuationA": "a4e982c388531a6e",
    "Preamble": "4adf4172ae751d7d",
    "SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from": "7e7284dc9bc88830",
    "num_imp_dec2flt_decimal_Decimal": "4da4ccbe640ef8e6",
    "num_imp_dec2flt_parse_adjust_many_digit_count": "4e59e3776b6cfdaa",
    "num_imp_dec2flt_parse_parse_many_digits": "50c9ef13b3ed7fe8",
    "num_imp_dec2flt_parse_parse_partial_number": "94ed7b2ff71604ef",
    "num_imp_dec2flt_parse_parse_scientific": "447f722d5841d2c5"
  }
}
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:71fc37364e5d6f86a4f5e78a7471df34faee851cf20e18c822c626ee4514f4ce",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}