ParserNumericElevenZeroCertificate

Lean checked

Statement

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

Helper · Eleven fractional zeroes

For any slice consisting of eleven ASCII zeroes followed by byte 1 and an arbitrary tail, the fractional leading-zero loop succeeds and returns precisely the suffix beginning with that 1 byte.

Lean statement

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

import Tablet.num_imp_dec2flt_decimal_seq_parse_decimal_seq

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserNumericElevenZeroCertificate]
theorem ParserNumericElevenZeroCertificate (first : Slice Std.U8)
    (tail : List Std.U8)
    (hfirst : first.val = List.replicate 11 48#u8 ++ 49#u8 :: tail) :
    exists significant : Slice Std.U8,
      significant.val = 49#u8 :: tail /\
      num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop2 first =
        ok significant := 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

Use the fractional leading-zero loop from num imp dec2flt decimal seq parse decimal seq. Induct on the number k\leq11 of zeroes still preceding the suffix, using the current slice length as the decreasing measure. If k>0, the slice is nonempty, its first byte is 48, and the in-bounds one-byte drop leaves k-1 zeroes followed by the same suffix; hence the loop continues and the measure decreases. When k=0, the suffix begins with byte 49, so the loop returns it unchanged. The initial state has k=11, which proves both normal termination and the exact residual contents.

Lean proof


  have hloop : num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop2 first
      ⦃ s => s.val = 49#u8 :: tail ⦄ := by
    unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop2
    apply Aeneas.Std.loop.spec_decr_nat
      (fun s : Slice Std.U8 => s.val.length)
      (fun s => exists k : Nat, k <= 11 /\
        s.val = List.replicate k 48#u8 ++ 49#u8 :: tail)
      (fun s => s.val = 49#u8 :: tail)
      num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop2.body
      first
    · intro s hs
      rcases hs with ⟨k, hk, hs⟩
      cases k with
      | zero =>
          have hbound : (49#u8 :: tail).length <= Usize.max := by
            have hp := s.property
            rw [hs] at hp
            simpa using hp
          let stop : Slice Std.U8 := ⟨49#u8 :: tail, hbound⟩
          have hstop : s = stop := (Slice.eq_iff _ _).2 (by
            simpa [stop] using hs)
          subst s
          unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop2.body
          simp [stop, Slice.index_usize, WP.spec_ok]
      | succ k =>
          have hnonempty : 0 < s.val.length := by
            rw [hs]
            simp [List.replicate_succ]
          have hdrop : (Slice.drop s 1#usize).val =
              List.replicate k 48#u8 ++ 49#u8 :: tail := by
            simp [Slice.drop, hs, List.replicate_succ]
          unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop2.body
          simp [core.slice.Slice.is_empty, hnonempty, Slice.index_usize,
            hs, List.replicate_succ,
            core.slice.index.SliceIndexRangeFromUsizeSlice.index,
            Slice.length, WP.spec_ok]
          omega
    · exact ⟨11, by omega, hfirst⟩
  obtain ⟨significant, hsignificant, hval⟩ :=
    Aeneas.Std.WP.spec_imp_exists hloop
  exact ⟨significant, hval, hsignificant⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.num_imp_dec2flt_decimal_seq_parse_decimal_seq

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserNumericElevenZeroCertificate]
theorem ParserNumericElevenZeroCertificate (first : Slice Std.U8)
    (tail : List Std.U8)
    (hfirst : first.val = List.replicate 11 48#u8 ++ 49#u8 :: tail) :
    exists significant : Slice Std.U8,
      significant.val = 49#u8 :: tail /\
      num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop2 first =
        ok significant := by
-- BODY
  have hloop : num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop2 first
      ⦃ s => s.val = 49#u8 :: tail ⦄ := by
    unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop2
    apply Aeneas.Std.loop.spec_decr_nat
      (fun s : Slice Std.U8 => s.val.length)
      (fun s => exists k : Nat, k <= 11 /\
        s.val = List.replicate k 48#u8 ++ 49#u8 :: tail)
      (fun s => s.val = 49#u8 :: tail)
      num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop2.body
      first
    · intro s hs
      rcases hs with ⟨k, hk, hs⟩
      cases k with
      | zero =>
          have hbound : (49#u8 :: tail).length <= Usize.max := by
            have hp := s.property
            rw [hs] at hp
            simpa using hp
          let stop : Slice Std.U8 := ⟨49#u8 :: tail, hbound⟩
          have hstop : s = stop := (Slice.eq_iff _ _).2 (by
            simpa [stop] using hs)
          subst s
          unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop2.body
          simp [stop, Slice.index_usize, WP.spec_ok]
      | succ k =>
          have hnonempty : 0 < s.val.length := by
            rw [hs]
            simp [List.replicate_succ]
          have hdrop : (Slice.drop s 1#usize).val =
              List.replicate k 48#u8 ++ 49#u8 :: tail := by
            simp [Slice.drop, hs, List.replicate_succ]
          unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop2.body
          simp [core.slice.Slice.is_empty, hnonempty, Slice.index_usize,
            hs, List.replicate_succ,
            core.slice.index.SliceIndexRangeFromUsizeSlice.index,
            Slice.length, WP.spec_ok]
          omega
    · exact ⟨11, by omega, hfirst⟩
  obtain ⟨significant, hsignificant, hval⟩ :=
    Aeneas.Std.WP.spec_imp_exists hloop
  exact ⟨significant, hval, hsignificant⟩

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (77)
More program dependencies (44)
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 13 entries
Technical checking records
Local closure summary
{
  "node": "ParserNumericElevenZeroCertificate",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "076df0e2ed93e4aedf0e45d11b539bc1f7600ce7501daeee6be4f3bb11cdb209",
  "active_statement_hash": "cdfc302290908ec072c1a79fd42f6301971d0c9f541f591b2fd9fc327963fdee",
  "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": {
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "7a20708611001f01"
  },
  "strict_definition_deps": {
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "15eb2db9d4385140"
  }
}
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:a7bcd4daa662fc59ad3b1f53f9e8d4865a8ba3a0feed44754d679da41b38f742",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}