ParserNumericTry19Certificate

Lean checked

Statement

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

Helper · Exact nineteen-digit retry

Let first consist of eleven ASCII zeros, the 19-byte word 1000000000000000080, and 2{,}147{,}483{,}618 further ASCII zeros. Then the extracted try_parse_19digits call from accumulator zero returns mantissa 1{,}000{,}000{,}000{,}000{,}000{,}080 and a residual slice consisting exactly of the final replicated zeros.

Lean statement

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

import Tablet.NumberHelperTryParse19SafeLength

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxRecDepth 65536
set_option maxHeartbeats 2000000

namespace dec2flt_model

-- [TABLET NODE: ParserNumericTry19Certificate]
theorem ParserNumericTry19Certificate (first : Slice Std.U8)
    (hfirst : first.val = List.replicate 11 48#u8 ++
      [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 56#u8, 48#u8] ++
      List.replicate 2147483618 48#u8) :
    exists rest : Slice Std.U8,
      rest.val = List.replicate 2147483618 48#u8 /\
      num.imp.dec2flt.parse.try_parse_19digits first 0#u64 =
        ok (rest, 1000000000000000080#u64) := 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

Every byte is an ASCII digit, so apply NumberHelperTryParse19SafeLength with empty nondigit tail. Its consumed-prefix decomposition says the returned accumulator is the decimal fold of the consumed prefix. The folds of the first 29, 30, and 31 bytes are respectively 100000000000000008, 1000000000000000080, and 10000000000000000800. If fewer than 30 bytes were consumed, the accumulator would be below 10^{18} and the cited helper would force the residual empty, contradicting the total length 2^{31}. If at least 31 bytes were consumed, prefix monotonicity of the nonnegative decimal fold would put the accumulator above its certified 9{,}999{,}999{,}999{,}999{,}999{,}999 bound. Thus exactly 30 bytes are consumed. The 30-byte prefix is the eleven zeros followed by the displayed 19-byte word, whose fold is the claimed mantissa; cancellation in the prefix decomposition leaves exactly the final replicated-zero suffix.

Lean proof


  have hdigits : forall b, List.Mem b first.val ->
      48 <= b.val /\ b.val <= 57 := by
    as_aux_lemma =>
    intro b hb
    rw [hfirst] at hb
    rcases List.mem_append.mp hb with hb | hb
    · rcases List.mem_append.mp hb with hb | hb
      · rw [List.mem_replicate] at hb
        rcases hb with ⟨_, rfl⟩
        norm_num
      · simp only [List.mem_cons, List.not_mem_nil, or_false] at hb
        rcases hb with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl |
          rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;>
          norm_num
    · rw [List.mem_replicate] at hb
      rcases hb with ⟨_, rfl⟩
      norm_num
  have htail : forall b rest, ([] : List Std.U8) = b :: rest ->
      Not (48 <= b.val /\ b.val <= 57) := by
    intro b rest h
    simp at h
  obtain ⟨rest, mantissa, remaining, consumed, hparse, hpartition,
      hrest, hvalue, hremaining, hremainingLen, hmantissa, hlow, hsharp⟩ :=
    NumberHelperTryParse19SafeLength first 0#u64 first.val [] (by simp)
      hdigits htail (by norm_num)
  let digitStep : Nat -> Std.U8 -> Nat :=
    fun a b => 10 * a + (b.val - 48)
  change mantissa.val = consumed.foldl digitStep 0 at hvalue
  have fold_ge_start : forall (l : List Std.U8) (a : Nat),
      a <= l.foldl digitStep a := by
    as_aux_lemma =>
    intro l
    induction l with
    | nil => intro a; simp
    | cons b bs ih =>
        intro a
        simp only [List.foldl_cons]
        exact le_trans (by simp [digitStep]; omega) (ih _)
  have fold_prefix_mono : forall (l1 l2 : List Std.U8),
      l1 <+: l2 -> l1.foldl digitStep 0 <= l2.foldl digitStep 0 := by
    as_aux_lemma =>
    intro l1 l2 hp
    rcases hp with ⟨suffix, hsuffix⟩
    rw [← hsuffix, List.foldl_append]
    exact fold_ge_start suffix _
  have hconsumedTake : consumed = first.val.take consumed.length := by
    calc
      consumed = (consumed ++ remaining).take consumed.length := by
        rw [List.take_left]
      _ = first.val.take consumed.length := by rw [hpartition]
  have hdigitsLen : first.val.length = 2147483648 := by
    rw [hfirst]
    simp only [List.length_append, List.length_replicate, List.length_cons,
      List.length_nil]
  have hfold29 : (first.val.take 29).foldl digitStep 0 =
      100000000000000008 := by
    as_aux_lemma =>
    rw [hfirst]
    have hz : (List.replicate 11 48#u8).foldl digitStep 0 = 0 := by
      norm_num [digitStep, List.replicate_succ]
    norm_num [digitStep, List.take_append, hz]
  have hfold30 : (first.val.take 30).foldl digitStep 0 =
      1000000000000000080 := by
    as_aux_lemma =>
    rw [hfirst]
    have hz : (List.replicate 11 48#u8).foldl digitStep 0 = 0 := by
      norm_num [digitStep, List.replicate_succ]
    norm_num [digitStep, List.take_append, hz]
  have hfold31 : (first.val.take 31).foldl digitStep 0 =
      10000000000000000800 := by
    as_aux_lemma =>
    rw [hfirst]
    have hz : (List.replicate 11 48#u8).foldl digitStep 0 = 0 := by
      norm_num [digitStep, List.replicate_succ]
    norm_num [digitStep, List.take_append, hz]
  have hconsumedLower : 30 <= consumed.length := by
    by_contra hn
    have hlen29 : consumed.length <= 29 := by omega
    have hp : consumed <+: first.val.take 29 := by
      rw [hconsumedTake]
      exact List.take_prefix_take_left hlen29
    have hmle := fold_prefix_mono consumed (first.val.take 29) hp
    rw [hfold29] at hmle
    have hmlow : mantissa.val < 1000000000000000000 := by
      rw [hvalue]
      omega
    have hremnil := hlow hmlow
    have hlenEq := congrArg List.length hpartition
    rw [hremnil] at hlenEq
    simp only [List.length_append, List.length_nil, Nat.add_zero] at hlenEq
    rw [hdigitsLen] at hlenEq
    omega
  have hconsumedUpper : consumed.length <= 30 := by
    by_contra hn
    have hlen31 : 31 <= consumed.length := by omega
    have hp : first.val.take 31 <+: consumed := by
      rw [hconsumedTake]
      exact List.take_prefix_take_left hlen31
    have hmge := fold_prefix_mono (first.val.take 31) consumed hp
    rw [hfold31, ← hvalue] at hmge
    omega
  have hconsumedLen : consumed.length = 30 := by omega
  have hprefix : first.val.take 30 = List.replicate 11 48#u8 ++
      [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 56#u8, 48#u8] := by
    rw [hfirst]
    norm_num [List.take_append]
  have hconsumed : consumed = List.replicate 11 48#u8 ++
      [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 56#u8, 48#u8] := by
    rw [hconsumedTake, hconsumedLen, hprefix]
  have hremainingEq : remaining = List.replicate 2147483618 48#u8 := by
    rw [hfirst, hconsumed] at hpartition
    exact (List.append_cancel_left hpartition).symm
  have hmantissaEq : mantissa = 1000000000000000080#u64 := by
    apply UScalar.eq_of_val_eq
    rw [hvalue, hconsumedTake, hconsumedLen, hfold30]
    norm_num
  have hrestEq : rest.val = List.replicate 2147483618 48#u8 := by
    calc
      rest.val = remaining ++ [] := hrest
      _ = remaining := List.append_nil _
      _ = List.replicate 2147483618 48#u8 := hremainingEq
  have hparseEq :
      num.imp.dec2flt.parse.try_parse_19digits first 0#u64 =
        ok (rest, 1000000000000000080#u64) := by
    calc
      num.imp.dec2flt.parse.try_parse_19digits first 0#u64 =
          ok (rest, mantissa) := hparse
      _ = ok (rest, 1000000000000000080#u64) := by rw [hmantissaEq]
  exact ⟨rest, hrestEq, hparseEq⟩


end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.NumberHelperTryParse19SafeLength

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxRecDepth 65536
set_option maxHeartbeats 2000000

namespace dec2flt_model

-- [TABLET NODE: ParserNumericTry19Certificate]
theorem ParserNumericTry19Certificate (first : Slice Std.U8)
    (hfirst : first.val = List.replicate 11 48#u8 ++
      [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 56#u8, 48#u8] ++
      List.replicate 2147483618 48#u8) :
    exists rest : Slice Std.U8,
      rest.val = List.replicate 2147483618 48#u8 /\
      num.imp.dec2flt.parse.try_parse_19digits first 0#u64 =
        ok (rest, 1000000000000000080#u64) := by
-- BODY
  have hdigits : forall b, List.Mem b first.val ->
      48 <= b.val /\ b.val <= 57 := by
    as_aux_lemma =>
    intro b hb
    rw [hfirst] at hb
    rcases List.mem_append.mp hb with hb | hb
    · rcases List.mem_append.mp hb with hb | hb
      · rw [List.mem_replicate] at hb
        rcases hb with ⟨_, rfl⟩
        norm_num
      · simp only [List.mem_cons, List.not_mem_nil, or_false] at hb
        rcases hb with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl |
          rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;>
          norm_num
    · rw [List.mem_replicate] at hb
      rcases hb with ⟨_, rfl⟩
      norm_num
  have htail : forall b rest, ([] : List Std.U8) = b :: rest ->
      Not (48 <= b.val /\ b.val <= 57) := by
    intro b rest h
    simp at h
  obtain ⟨rest, mantissa, remaining, consumed, hparse, hpartition,
      hrest, hvalue, hremaining, hremainingLen, hmantissa, hlow, hsharp⟩ :=
    NumberHelperTryParse19SafeLength first 0#u64 first.val [] (by simp)
      hdigits htail (by norm_num)
  let digitStep : Nat -> Std.U8 -> Nat :=
    fun a b => 10 * a + (b.val - 48)
  change mantissa.val = consumed.foldl digitStep 0 at hvalue
  have fold_ge_start : forall (l : List Std.U8) (a : Nat),
      a <= l.foldl digitStep a := by
    as_aux_lemma =>
    intro l
    induction l with
    | nil => intro a; simp
    | cons b bs ih =>
        intro a
        simp only [List.foldl_cons]
        exact le_trans (by simp [digitStep]; omega) (ih _)
  have fold_prefix_mono : forall (l1 l2 : List Std.U8),
      l1 <+: l2 -> l1.foldl digitStep 0 <= l2.foldl digitStep 0 := by
    as_aux_lemma =>
    intro l1 l2 hp
    rcases hp with ⟨suffix, hsuffix⟩
    rw [← hsuffix, List.foldl_append]
    exact fold_ge_start suffix _
  have hconsumedTake : consumed = first.val.take consumed.length := by
    calc
      consumed = (consumed ++ remaining).take consumed.length := by
        rw [List.take_left]
      _ = first.val.take consumed.length := by rw [hpartition]
  have hdigitsLen : first.val.length = 2147483648 := by
    rw [hfirst]
    simp only [List.length_append, List.length_replicate, List.length_cons,
      List.length_nil]
  have hfold29 : (first.val.take 29).foldl digitStep 0 =
      100000000000000008 := by
    as_aux_lemma =>
    rw [hfirst]
    have hz : (List.replicate 11 48#u8).foldl digitStep 0 = 0 := by
      norm_num [digitStep, List.replicate_succ]
    norm_num [digitStep, List.take_append, hz]
  have hfold30 : (first.val.take 30).foldl digitStep 0 =
      1000000000000000080 := by
    as_aux_lemma =>
    rw [hfirst]
    have hz : (List.replicate 11 48#u8).foldl digitStep 0 = 0 := by
      norm_num [digitStep, List.replicate_succ]
    norm_num [digitStep, List.take_append, hz]
  have hfold31 : (first.val.take 31).foldl digitStep 0 =
      10000000000000000800 := by
    as_aux_lemma =>
    rw [hfirst]
    have hz : (List.replicate 11 48#u8).foldl digitStep 0 = 0 := by
      norm_num [digitStep, List.replicate_succ]
    norm_num [digitStep, List.take_append, hz]
  have hconsumedLower : 30 <= consumed.length := by
    by_contra hn
    have hlen29 : consumed.length <= 29 := by omega
    have hp : consumed <+: first.val.take 29 := by
      rw [hconsumedTake]
      exact List.take_prefix_take_left hlen29
    have hmle := fold_prefix_mono consumed (first.val.take 29) hp
    rw [hfold29] at hmle
    have hmlow : mantissa.val < 1000000000000000000 := by
      rw [hvalue]
      omega
    have hremnil := hlow hmlow
    have hlenEq := congrArg List.length hpartition
    rw [hremnil] at hlenEq
    simp only [List.length_append, List.length_nil, Nat.add_zero] at hlenEq
    rw [hdigitsLen] at hlenEq
    omega
  have hconsumedUpper : consumed.length <= 30 := by
    by_contra hn
    have hlen31 : 31 <= consumed.length := by omega
    have hp : first.val.take 31 <+: consumed := by
      rw [hconsumedTake]
      exact List.take_prefix_take_left hlen31
    have hmge := fold_prefix_mono (first.val.take 31) consumed hp
    rw [hfold31, ← hvalue] at hmge
    omega
  have hconsumedLen : consumed.length = 30 := by omega
  have hprefix : first.val.take 30 = List.replicate 11 48#u8 ++
      [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 56#u8, 48#u8] := by
    rw [hfirst]
    norm_num [List.take_append]
  have hconsumed : consumed = List.replicate 11 48#u8 ++
      [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 56#u8, 48#u8] := by
    rw [hconsumedTake, hconsumedLen, hprefix]
  have hremainingEq : remaining = List.replicate 2147483618 48#u8 := by
    rw [hfirst, hconsumed] at hpartition
    exact (List.append_cancel_left hpartition).symm
  have hmantissaEq : mantissa = 1000000000000000080#u64 := by
    apply UScalar.eq_of_val_eq
    rw [hvalue, hconsumedTake, hconsumedLen, hfold30]
    norm_num
  have hrestEq : rest.val = List.replicate 2147483618 48#u8 := by
    calc
      rest.val = remaining ++ [] := hrest
      _ = remaining := List.append_nil _
      _ = List.replicate 2147483618 48#u8 := hremainingEq
  have hparseEq :
      num.imp.dec2flt.parse.try_parse_19digits first 0#u64 =
        ok (rest, 1000000000000000080#u64) := by
    calc
      num.imp.dec2flt.parse.try_parse_19digits first 0#u64 =
          ok (rest, mantissa) := hparse
      _ = ok (rest, 1000000000000000080#u64) := by rw [hmantissaEq]
  exact ⟨rest, hrestEq, hparseEq⟩


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 33 entries
Technical checking records
Local closure summary
{
  "node": "ParserNumericTry19Certificate",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "334435a85620a7dfe3ef510e91e7dc1477eff532655032923272735ca790b28b",
  "active_statement_hash": "be14fde324d21382a879b2b6ac66de7b10ad45b3cff862bacef210f554f3aa5a",
  "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-126",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "NumberHelperTryParse19SafeLength": "dd334c60b1e032a8"
  },
  "strict_definition_deps": {
    "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:d8451c078a1fd8cee6d8876a2e6ee509303109c494714bf272b0b37da8d89b81",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}