NumberHelperTryParse19SafeLength

Lean checked

Statement

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

Lemma · Safe threshold-bounded digit retry

Let a byte slice decompose as a list of decimal digit bytes followed by a tail whose first byte, if any, is not a decimal digit. Starting from an unsigned accumulator at most 10^{19}-1, the extracted try_parse_19digits returns normally. Its returned slice is a remaining digit suffix followed by the same tail, every byte in that suffix is a decimal digit, the suffix is no longer than the original digit list, and the original digit list is the consumed prefix followed by that suffix. The returned accumulator is the ordinary base-ten fold of the consumed prefix from the initial accumulator and is at most 10^{19}-1. If that accumulator is below 10^{18}, the remaining digit suffix is empty. If the initial accumulator is zero and the returned accumulator is at least 10^{18}, at least 19 original digits were consumed.

Lean statement

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

import Tablet.ModelSliceSplitFirst
import Tablet.num_imp_dec2flt_parse_MIN_19DIGIT_INT
import Tablet.num_imp_dec2flt_parse_try_parse_19digits

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperTryParse19SafeLength]
theorem NumberHelperTryParse19SafeLength :
    forall (s : Slice Std.U8) (initial : Std.U64)
      (digits tail : List Std.U8),
      s.val = digits ++ tail ->
      (forall b, List.Mem b digits -> 48 <= b.val /\ b.val <= 57) ->
      (forall b rest, tail = b :: rest ->
        Not (48 <= b.val /\ b.val <= 57)) ->
      initial.val <= 9999999999999999999 ->
      exists (rest : Slice Std.U8) (mantissa : Std.U64)
        (remaining consumed : List Std.U8),
        num.imp.dec2flt.parse.try_parse_19digits s initial =
          ok (rest, mantissa) /\
        digits = consumed ++ remaining /\
        rest.val = remaining ++ tail /\
        mantissa.val = consumed.foldl
          (fun a b => 10 * a + (b.val - 48)) initial.val /\
        (forall b, List.Mem b remaining -> 48 <= b.val /\ b.val <= 57) /\
        remaining.length <= digits.length /\
        mantissa.val <= 9999999999999999999 /\
        (mantissa.val < 1000000000000000000 -> remaining = []) /\
        (initial.val = 0 -> 1000000000000000000 <= mantissa.val ->
          remaining.length + 19 <= digits.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

Unfold the loop in num imp dec2flt parse try parse 19digits. Use the current slice length as a decreasing measure. At each loop head write the current slice as a remaining digit list followed by the fixed tail, and maintain that this list is no longer than the original digit list and that the accumulator is at most 10^{19}-1. Also maintain a consumed prefix whose concatenation with the remaining list is the original digit list and whose base-ten fold from the initial value is the current accumulator.
If the accumulator is already at least the constant 10^{18} from num imp dec2flt parse MIN 19DIGIT INT, the loop stops without changing either component. Otherwise, an empty remaining digit list puts the loop at either the empty tail or its first nondigit. The exact split in ModelSliceSplitFirst therefore stops normally at the fixed tail. In the other case the next byte is between 48 and 57. Wrapping subtraction by 48 consequently has its ordinary value in [0,9], so the digit test continues. Since the old accumulator is below 10^{18}, the checked update is at most 10(10^{18}-1)+9=10^{19}-1<2^{64}. The byte-to-u64 cast, multiplication, and addition all succeed, and removing the head byte strictly decreases the measure while preserving the suffix decomposition.
The well-founded loop therefore terminates normally with the stated suffix and bound. At a terminal state whose accumulator is still below 10^{18}, neither the threshold branch nor a remaining digit can have caused termination; hence the remaining digit list is empty. This proves the low-result clause. Finally, an induction on a consumed list of k decimal digits bounds its base-ten fold from zero strictly below 10^k: the next digit is at most nine, so the next accumulator is less than ten times the previous upper endpoint. Thus a result at least 10^{18} cannot have consumed fewer than 19 digits. The prefix/suffix partition then gives the asserted sharp remaining-length bound.

Lean proof


  intro s initial digits tail hs hdigits htail hinitial
  have loop_safe : forall (t : Slice Std.U8) (x : Std.U64)
      (consumed remaining : List Std.U8),
      digits = consumed ++ remaining ->
      t.val = remaining ++ tail ->
      x.val = consumed.foldl
        (fun a b => 10 * a + (b.val - 48)) initial.val ->
      (forall b, List.Mem b remaining -> 48 <= b.val /\ b.val <= 57) ->
      x.val <= 9999999999999999999 ->
      num.imp.dec2flt.parse.try_parse_19digits_loop x t
        ⦃ p => exists used rem : List Std.U8,
          digits = used ++ rem /\
          p.1.val = rem ++ tail /\
          p.2.val = used.foldl
            (fun a b => 10 * a + (b.val - 48)) initial.val /\
          (forall b, List.Mem b rem -> 48 <= b.val /\ b.val <= 57) /\
          rem.length <= remaining.length /\
          p.2.val <= 9999999999999999999 /\
          (p.2.val < 1000000000000000000 -> rem = []) ⦄ := by
    intro t x consumed remaining hpartition ht hvalue hrem hx
    unfold num.imp.dec2flt.parse.try_parse_19digits_loop
    apply Aeneas.Std.loop.spec_decr_nat
      (fun p : Std.U64 × Slice Std.U8 => p.2.length)
      (fun p => exists used rem : List Std.U8,
        digits = used ++ rem /\
        p.2.val = rem ++ tail /\
        p.1.val = used.foldl
          (fun a b => 10 * a + (b.val - 48)) initial.val /\
        (forall b, List.Mem b rem -> 48 <= b.val /\ b.val <= 57) /\
        rem.length <= remaining.length /\
        p.1.val <= 9999999999999999999)
      (fun p => exists used rem : List Std.U8,
        digits = used ++ rem /\
        p.1.val = rem ++ tail /\
        p.2.val = used.foldl
          (fun a b => 10 * a + (b.val - 48)) initial.val /\
        (forall b, List.Mem b rem -> 48 <= b.val /\ b.val <= 57) /\
        rem.length <= remaining.length /\
        p.2.val <= 9999999999999999999 /\
        (p.2.val < 1000000000000000000 -> rem = []))
      (fun p => num.imp.dec2flt.parse.try_parse_19digits_loop.body p.1 p.2)
      (x, t)
    · intro p hp
      rcases p with ⟨a, u⟩
      rcases hp with
        ⟨used, rem, hpartitionNow, hurem, hvalueNow,
          hrdigits, hremlen, ha⟩
      simp [num.imp.dec2flt.parse.try_parse_19digits_loop.body, WP.spec_ok]
      split
      · rename_i halow
        cases rem with
        | nil =>
          simp at hurem
          cases htailval : tail with
          | nil =>
            have huempty : u.val = [] := by simpa [htailval] using hurem
            let empty : Slice Std.U8 := ⟨[], by simp⟩
            have hueq : u = empty := (Slice.eq_iff _ _).2 huempty
            subst u
            simp only [core.slice.Slice.split_first,
              dec2flt_model.ModelSliceSplitFirst, empty, List.nil_append]
            simp [WP.spec_ok, ha]
            constructor
            · rw [hpartitionNow]
              simpa using hvalueNow
            · exact hrdigits
          | cons b bs =>
            have huval : u.val = b :: bs := by simpa [htailval] using hurem
            have hbnot := htail b bs htailval
            have hbsprop : bs.length <= Usize.max := by
              have := u.property
              simp [huval] at this ⊢
              omega
            have hubound : (b :: bs).length <= Usize.max := by
              simpa [huval] using u.property
            let us : Slice Std.U8 := ⟨b :: bs, hubound⟩
            have hueq : u = us := (Slice.eq_iff _ _).2 huval
            subst u
            have hwrap : (core.num.U8.wrapping_sub b 48#u8).val =
                (b.val + 256 - 48) % 256 := by
              rw [core.num.U8.wrapping_sub_val_eq]
              simp [UScalar.size, U8.size_eq]
            have hnondigit :
                Not ((core.num.U8.wrapping_sub b 48#u8).val < 10) := by
              rw [hwrap]
              scalar_tac
            have hrawnon : Not ((b.val + (256 - 48)) % 256 < 10) := by
              simpa [hwrap] using hnondigit
            simp [core.slice.Slice.split_first,
              dec2flt_model.ModelSliceSplitFirst, us, Aeneas.Std.lift,
              U8.size_eq, hrawnon]
            refine ⟨?_, hrdigits, ha⟩
            rw [hpartitionNow]
            simpa using hvalueNow
        | cons b bs =>
          have huval : u.val = b :: (bs ++ tail) := by simpa using hurem
          have hb := hrdigits b (List.mem_cons_self)
          have htailprop : (bs ++ tail).length <= Usize.max := by
            have := u.property
            simp [huval] at this ⊢
            omega
          have hubound : (b :: (bs ++ tail)).length <= Usize.max := by
            simpa [huval] using u.property
          let us : Slice Std.U8 := ⟨b :: (bs ++ tail), hubound⟩
          have hueq : u = us := (Slice.eq_iff _ _).2 huval
          subst u
          have hdigitval :
              (core.num.U8.wrapping_sub b 48#u8).val = b.val - 48 := by
            rw [core.num.U8.wrapping_sub_val_eq]
            simp [UScalar.size, U8.size_eq]
            omega
          have hdigit :
              (core.num.U8.wrapping_sub b 48#u8).val < 10 := by
            rw [hdigitval]
            omega
          have hraw : (b.val + (256 - 48)) % 256 < 10 := by
            scalar_tac
          have halow_num : a.val < 1000000000000000000 := by
            simpa [num.imp.dec2flt.parse.MIN_19DIGIT_INT.eq_def] using halow
          simp [core.slice.Slice.split_first,
            dec2flt_model.ModelSliceSplitFirst, us]
          step
          have hcast := UScalar.cast_inBounds_spec .U64 digit (by scalar_tac)
          obtain ⟨digit64, hdigit64, hdigit64val⟩ :=
            Aeneas.Std.WP.spec_imp_exists hcast
          rw [hdigit64]
          have hmullo : a.val * 10 <= U64.max := by
            rw [U64.max_eq]
            omega
          have hmul := UScalar.mul_spec (x := a) (y := 10#u64) (by
            simpa using hmullo)
          obtain ⟨prod, hprod, hprodval⟩ :=
            Aeneas.Std.WP.spec_imp_exists hmul
          rw [hprod]
          have hsumlo : prod.val + digit64.val <= U64.max := by
            rw [U64.max_eq]
            simp at hdigit64val hprodval
            rw [digit_post, hdigitval] at hdigit64val
            omega
          have hsum := UScalar.add_spec (x := prod) (y := digit64) (by
            simpa using hsumlo)
          obtain ⟨next, hnext, hnextval⟩ :=
            Aeneas.Std.WP.spec_imp_exists hsum
          simp [digit_post, U8.size_eq, hraw, hnext]
          refine ⟨used ++ [b], ?_, ?_, ?_, ?_, ?_⟩
          · simpa [List.append_assoc] using hpartitionNow
          · simp only [List.foldl_append, List.foldl_cons, List.foldl_nil]
            simp at hprodval hdigit64val hnextval
            simp at hvalueNow
            rw [digit_post, hdigitval] at hdigit64val
            omega
          · intro c hc
            exact hrdigits c (List.mem_cons_of_mem b hc)
          · simp only [List.length_cons] at hremlen
            omega
          · simp at hprodval hdigit64val hnextval
            rw [digit_post, hdigitval] at hdigit64val
            omega
      · rename_i hahigh
        simp [WP.spec_ok]
        simp [num.imp.dec2flt.parse.MIN_19DIGIT_INT.eq_def] at hahigh
        exact ⟨used, rem, hpartitionNow, hurem, hvalueNow,
          hrdigits, hremlen, ha, by omega⟩
    · exact ⟨consumed, remaining, hpartition, ht, hvalue,
        hrem, Nat.le_refl _, hx⟩
  have h := loop_safe s initial [] digits (by simp) hs (by simp) hdigits hinitial
  obtain ⟨p, hp, hpost⟩ := Aeneas.Std.WP.spec_imp_exists h
  rcases p with ⟨rest, mantissa⟩
  rcases hpost with
    ⟨consumed, remaining, hpartition, hrest, hvalue,
      hremaining, hremainingLen, hmantissa, hlow⟩
  have foldUpper : forall (ds : List Std.U8) (a : Nat),
      (forall b, List.Mem b ds -> 48 <= b.val /\ b.val <= 57) ->
      ds.foldl (fun x b => 10 * x + (b.val - 48)) a <
        (a + 1) * 10 ^ ds.length := by
    intro ds
    induction ds with
    | nil =>
      intro a hds
      simp
    | cons b bs ih =>
      intro a hds
      have hb := hds b List.mem_cons_self
      have hbs : forall c, List.Mem c bs -> 48 <= c.val /\ c.val <= 57 := by
        intro c hc
        exact hds c (List.mem_cons_of_mem b hc)
      simp only [List.foldl_cons, List.length_cons, Nat.pow_succ]
      have hrec := ih (10 * a + (b.val - 48)) hbs
      have hcoeff : 10 * a + (b.val - 48) + 1 <= 10 * (a + 1) := by
        omega
      have hmul := Nat.mul_le_mul_right (10 ^ bs.length) hcoeff
      exact hrec.trans_le (by
        simpa [Nat.mul_assoc, Nat.mul_comm, Nat.mul_left_comm] using hmul)
  have hconsumedDigits : forall b, List.Mem b consumed ->
      48 <= b.val /\ b.val <= 57 := by
    intro b hb
    apply hdigits b
    rw [hpartition]
    exact List.mem_append_left _ hb
  have hsharp : initial.val = 0 ->
      1000000000000000000 <= mantissa.val ->
      remaining.length + 19 <= digits.length := by
    intro hinitialZero hthreshold
    have hfoldUpper := foldUpper consumed initial.val hconsumedDigits
    rw [hvalue, hinitialZero] at hthreshold
    rw [hinitialZero] at hfoldUpper
    simp only [Nat.zero_add, Nat.one_mul] at hfoldUpper
    have hconsumedLen : 19 <= consumed.length := by
      by_contra hnot
      have hpow : 10 ^ consumed.length <= 10 ^ 18 :=
        Nat.pow_le_pow_right (by norm_num) (by omega)
      norm_num at hthreshold
      omega
    have hlength := congrArg List.length hpartition
    simp only [List.length_append] at hlength
    omega
  exact ⟨rest, mantissa, remaining, consumed, hp, hpartition, hrest,
    hvalue, hremaining, hremainingLen, hmantissa, hlow, hsharp⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.ModelSliceSplitFirst
import Tablet.num_imp_dec2flt_parse_MIN_19DIGIT_INT
import Tablet.num_imp_dec2flt_parse_try_parse_19digits

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperTryParse19SafeLength]
theorem NumberHelperTryParse19SafeLength :
    forall (s : Slice Std.U8) (initial : Std.U64)
      (digits tail : List Std.U8),
      s.val = digits ++ tail ->
      (forall b, List.Mem b digits -> 48 <= b.val /\ b.val <= 57) ->
      (forall b rest, tail = b :: rest ->
        Not (48 <= b.val /\ b.val <= 57)) ->
      initial.val <= 9999999999999999999 ->
      exists (rest : Slice Std.U8) (mantissa : Std.U64)
        (remaining consumed : List Std.U8),
        num.imp.dec2flt.parse.try_parse_19digits s initial =
          ok (rest, mantissa) /\
        digits = consumed ++ remaining /\
        rest.val = remaining ++ tail /\
        mantissa.val = consumed.foldl
          (fun a b => 10 * a + (b.val - 48)) initial.val /\
        (forall b, List.Mem b remaining -> 48 <= b.val /\ b.val <= 57) /\
        remaining.length <= digits.length /\
        mantissa.val <= 9999999999999999999 /\
        (mantissa.val < 1000000000000000000 -> remaining = []) /\
        (initial.val = 0 -> 1000000000000000000 <= mantissa.val ->
          remaining.length + 19 <= digits.length) := by
-- BODY
  intro s initial digits tail hs hdigits htail hinitial
  have loop_safe : forall (t : Slice Std.U8) (x : Std.U64)
      (consumed remaining : List Std.U8),
      digits = consumed ++ remaining ->
      t.val = remaining ++ tail ->
      x.val = consumed.foldl
        (fun a b => 10 * a + (b.val - 48)) initial.val ->
      (forall b, List.Mem b remaining -> 48 <= b.val /\ b.val <= 57) ->
      x.val <= 9999999999999999999 ->
      num.imp.dec2flt.parse.try_parse_19digits_loop x t
        ⦃ p => exists used rem : List Std.U8,
          digits = used ++ rem /\
          p.1.val = rem ++ tail /\
          p.2.val = used.foldl
            (fun a b => 10 * a + (b.val - 48)) initial.val /\
          (forall b, List.Mem b rem -> 48 <= b.val /\ b.val <= 57) /\
          rem.length <= remaining.length /\
          p.2.val <= 9999999999999999999 /\
          (p.2.val < 1000000000000000000 -> rem = []) ⦄ := by
    intro t x consumed remaining hpartition ht hvalue hrem hx
    unfold num.imp.dec2flt.parse.try_parse_19digits_loop
    apply Aeneas.Std.loop.spec_decr_nat
      (fun p : Std.U64 × Slice Std.U8 => p.2.length)
      (fun p => exists used rem : List Std.U8,
        digits = used ++ rem /\
        p.2.val = rem ++ tail /\
        p.1.val = used.foldl
          (fun a b => 10 * a + (b.val - 48)) initial.val /\
        (forall b, List.Mem b rem -> 48 <= b.val /\ b.val <= 57) /\
        rem.length <= remaining.length /\
        p.1.val <= 9999999999999999999)
      (fun p => exists used rem : List Std.U8,
        digits = used ++ rem /\
        p.1.val = rem ++ tail /\
        p.2.val = used.foldl
          (fun a b => 10 * a + (b.val - 48)) initial.val /\
        (forall b, List.Mem b rem -> 48 <= b.val /\ b.val <= 57) /\
        rem.length <= remaining.length /\
        p.2.val <= 9999999999999999999 /\
        (p.2.val < 1000000000000000000 -> rem = []))
      (fun p => num.imp.dec2flt.parse.try_parse_19digits_loop.body p.1 p.2)
      (x, t)
    · intro p hp
      rcases p with ⟨a, u⟩
      rcases hp with
        ⟨used, rem, hpartitionNow, hurem, hvalueNow,
          hrdigits, hremlen, ha⟩
      simp [num.imp.dec2flt.parse.try_parse_19digits_loop.body, WP.spec_ok]
      split
      · rename_i halow
        cases rem with
        | nil =>
          simp at hurem
          cases htailval : tail with
          | nil =>
            have huempty : u.val = [] := by simpa [htailval] using hurem
            let empty : Slice Std.U8 := ⟨[], by simp⟩
            have hueq : u = empty := (Slice.eq_iff _ _).2 huempty
            subst u
            simp only [core.slice.Slice.split_first,
              dec2flt_model.ModelSliceSplitFirst, empty, List.nil_append]
            simp [WP.spec_ok, ha]
            constructor
            · rw [hpartitionNow]
              simpa using hvalueNow
            · exact hrdigits
          | cons b bs =>
            have huval : u.val = b :: bs := by simpa [htailval] using hurem
            have hbnot := htail b bs htailval
            have hbsprop : bs.length <= Usize.max := by
              have := u.property
              simp [huval] at this ⊢
              omega
            have hubound : (b :: bs).length <= Usize.max := by
              simpa [huval] using u.property
            let us : Slice Std.U8 := ⟨b :: bs, hubound⟩
            have hueq : u = us := (Slice.eq_iff _ _).2 huval
            subst u
            have hwrap : (core.num.U8.wrapping_sub b 48#u8).val =
                (b.val + 256 - 48) % 256 := by
              rw [core.num.U8.wrapping_sub_val_eq]
              simp [UScalar.size, U8.size_eq]
            have hnondigit :
                Not ((core.num.U8.wrapping_sub b 48#u8).val < 10) := by
              rw [hwrap]
              scalar_tac
            have hrawnon : Not ((b.val + (256 - 48)) % 256 < 10) := by
              simpa [hwrap] using hnondigit
            simp [core.slice.Slice.split_first,
              dec2flt_model.ModelSliceSplitFirst, us, Aeneas.Std.lift,
              U8.size_eq, hrawnon]
            refine ⟨?_, hrdigits, ha⟩
            rw [hpartitionNow]
            simpa using hvalueNow
        | cons b bs =>
          have huval : u.val = b :: (bs ++ tail) := by simpa using hurem
          have hb := hrdigits b (List.mem_cons_self)
          have htailprop : (bs ++ tail).length <= Usize.max := by
            have := u.property
            simp [huval] at this ⊢
            omega
          have hubound : (b :: (bs ++ tail)).length <= Usize.max := by
            simpa [huval] using u.property
          let us : Slice Std.U8 := ⟨b :: (bs ++ tail), hubound⟩
          have hueq : u = us := (Slice.eq_iff _ _).2 huval
          subst u
          have hdigitval :
              (core.num.U8.wrapping_sub b 48#u8).val = b.val - 48 := by
            rw [core.num.U8.wrapping_sub_val_eq]
            simp [UScalar.size, U8.size_eq]
            omega
          have hdigit :
              (core.num.U8.wrapping_sub b 48#u8).val < 10 := by
            rw [hdigitval]
            omega
          have hraw : (b.val + (256 - 48)) % 256 < 10 := by
            scalar_tac
          have halow_num : a.val < 1000000000000000000 := by
            simpa [num.imp.dec2flt.parse.MIN_19DIGIT_INT.eq_def] using halow
          simp [core.slice.Slice.split_first,
            dec2flt_model.ModelSliceSplitFirst, us]
          step
          have hcast := UScalar.cast_inBounds_spec .U64 digit (by scalar_tac)
          obtain ⟨digit64, hdigit64, hdigit64val⟩ :=
            Aeneas.Std.WP.spec_imp_exists hcast
          rw [hdigit64]
          have hmullo : a.val * 10 <= U64.max := by
            rw [U64.max_eq]
            omega
          have hmul := UScalar.mul_spec (x := a) (y := 10#u64) (by
            simpa using hmullo)
          obtain ⟨prod, hprod, hprodval⟩ :=
            Aeneas.Std.WP.spec_imp_exists hmul
          rw [hprod]
          have hsumlo : prod.val + digit64.val <= U64.max := by
            rw [U64.max_eq]
            simp at hdigit64val hprodval
            rw [digit_post, hdigitval] at hdigit64val
            omega
          have hsum := UScalar.add_spec (x := prod) (y := digit64) (by
            simpa using hsumlo)
          obtain ⟨next, hnext, hnextval⟩ :=
            Aeneas.Std.WP.spec_imp_exists hsum
          simp [digit_post, U8.size_eq, hraw, hnext]
          refine ⟨used ++ [b], ?_, ?_, ?_, ?_, ?_⟩
          · simpa [List.append_assoc] using hpartitionNow
          · simp only [List.foldl_append, List.foldl_cons, List.foldl_nil]
            simp at hprodval hdigit64val hnextval
            simp at hvalueNow
            rw [digit_post, hdigitval] at hdigit64val
            omega
          · intro c hc
            exact hrdigits c (List.mem_cons_of_mem b hc)
          · simp only [List.length_cons] at hremlen
            omega
          · simp at hprodval hdigit64val hnextval
            rw [digit_post, hdigitval] at hdigit64val
            omega
      · rename_i hahigh
        simp [WP.spec_ok]
        simp [num.imp.dec2flt.parse.MIN_19DIGIT_INT.eq_def] at hahigh
        exact ⟨used, rem, hpartitionNow, hurem, hvalueNow,
          hrdigits, hremlen, ha, by omega⟩
    · exact ⟨consumed, remaining, hpartition, ht, hvalue,
        hrem, Nat.le_refl _, hx⟩
  have h := loop_safe s initial [] digits (by simp) hs (by simp) hdigits hinitial
  obtain ⟨p, hp, hpost⟩ := Aeneas.Std.WP.spec_imp_exists h
  rcases p with ⟨rest, mantissa⟩
  rcases hpost with
    ⟨consumed, remaining, hpartition, hrest, hvalue,
      hremaining, hremainingLen, hmantissa, hlow⟩
  have foldUpper : forall (ds : List Std.U8) (a : Nat),
      (forall b, List.Mem b ds -> 48 <= b.val /\ b.val <= 57) ->
      ds.foldl (fun x b => 10 * x + (b.val - 48)) a <
        (a + 1) * 10 ^ ds.length := by
    intro ds
    induction ds with
    | nil =>
      intro a hds
      simp
    | cons b bs ih =>
      intro a hds
      have hb := hds b List.mem_cons_self
      have hbs : forall c, List.Mem c bs -> 48 <= c.val /\ c.val <= 57 := by
        intro c hc
        exact hds c (List.mem_cons_of_mem b hc)
      simp only [List.foldl_cons, List.length_cons, Nat.pow_succ]
      have hrec := ih (10 * a + (b.val - 48)) hbs
      have hcoeff : 10 * a + (b.val - 48) + 1 <= 10 * (a + 1) := by
        omega
      have hmul := Nat.mul_le_mul_right (10 ^ bs.length) hcoeff
      exact hrec.trans_le (by
        simpa [Nat.mul_assoc, Nat.mul_comm, Nat.mul_left_comm] using hmul)
  have hconsumedDigits : forall b, List.Mem b consumed ->
      48 <= b.val /\ b.val <= 57 := by
    intro b hb
    apply hdigits b
    rw [hpartition]
    exact List.mem_append_left _ hb
  have hsharp : initial.val = 0 ->
      1000000000000000000 <= mantissa.val ->
      remaining.length + 19 <= digits.length := by
    intro hinitialZero hthreshold
    have hfoldUpper := foldUpper consumed initial.val hconsumedDigits
    rw [hvalue, hinitialZero] at hthreshold
    rw [hinitialZero] at hfoldUpper
    simp only [Nat.zero_add, Nat.one_mul] at hfoldUpper
    have hconsumedLen : 19 <= consumed.length := by
      by_contra hnot
      have hpow : 10 ^ consumed.length <= 10 ^ 18 :=
        Nat.pow_le_pow_right (by norm_num) (by omega)
      norm_num at hthreshold
      omega
    have hlength := congrArg List.length hpartition
    simp only [List.length_append] at hlength
    omega
  exact ⟨rest, mantissa, remaining, consumed, hp, hpartition, hrest,
    hvalue, hremaining, hremainingLen, hmantissa, hlow, hsharp⟩

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (48)
More program dependencies (15)
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 32 entries
Technical checking records
Local closure summary
{
  "node": "NumberHelperTryParse19SafeLength",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "f183fdc0996c10ecdc5dfb81db2a1375af95748a28817d49a23adcfb583f5eb8",
  "active_statement_hash": "9cab43e661d3d4bb2ea1d94a0b436fa611013e366214d382a03fa2c14b698078",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-109",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "ModelSliceSplitFirst": "f617ee05dd2925a9",
    "num_imp_dec2flt_parse_MIN_19DIGIT_INT": "8d99761093f40bc7",
    "num_imp_dec2flt_parse_try_parse_19digits": "bcad6df678c024ae"
  },
  "strict_definition_deps": {
    "ModelSliceSplitFirst": "4ed9c51a5bb9fb58",
    "Preamble": "965f15fc36f80938",
    "num_imp_dec2flt_parse_MIN_19DIGIT_INT": "476edc5502ff7bfb",
    "num_imp_dec2flt_parse_try_parse_19digits": "c9c74554a359a9c4"
  }
}
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:b275b3c379661caed48ef2e8ede9ba6084a64daccbf7a55c738fcc808e54ac3e",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}