ParserExactRoundingScientific

Lean checked

Statement

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

Helper · Exact scientific suffix

For a model byte slice whose value is the ASCII digit list [54,53,53,51,54,48], the extracted parse_scientific succeeds with exponent 65536 and an empty remaining slice.

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_parse_parse_scientific

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserExactRoundingScientific]
theorem ParserExactRoundingScientific (s : Slice Std.U8)
    (hs : s.val = [54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) :
    exists rest,
      num.imp.dec2flt.parse.parse_scientific s =
          ok (some 65536#i64, rest) /\
        rest.val = [] := 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

Expand num imp dec2flt parse parse scientific. Its first-byte split sees ASCII `6', so the unsigned branch invokes the scientific digit loop at accumulator zero and index zero. At each of the six iterations, the bounds-checked slice index reads respectively bytes 54,53,53,51,54,48. Subtracting ASCII zero gives digits 6,5,5,3,6,0, and the loop recurrence a\mapsto10a+d therefore produces
0,6,65,655,6553,65536,655360.
The model caps accumulation before accepting a further digit once the pre-digit accumulator exceeds 65535. Thus on the sixth byte it consumes the final zero and returns the previous accumulated value 65536 at index 6. Each index increment is bounded because Aeneas permits pointer widths 32 or 64 and all indices are at most six. The final drop by index six is the empty slice, so the parser returns exponent 65536 and no remaining bytes, as claimed.

Lean proof


  have ht : s = (⟨[54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8], by
      rcases Usize.bounds_eq with q | q <;>
        norm_num [q, U32.max_eq, U64.max_eq]⟩ : Slice Std.U8) := by
    exact (Slice.eq_iff _ _).2 hs
  rw [ht]
  refine ⟨⟨[], by simp⟩, ?_, by rfl⟩
  have addOne (x y : Usize) (hxy : x.val + 1 = y.val) :
      x + 1#usize = ok y := by
    have hmax : x.val + (1#usize).val <= UScalar.max .Usize := by
      rw [show (1#usize).val = 1 by rfl, hxy]
      have hy := UScalar.hrBounds y
      simpa [UScalar.rMax_eq_max] using hy
    obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
      (UScalar.add_spec hmax)
    rw [hz]
    congr 1
    apply UScalar.eq_of_val_eq
    simpa [hxy] using hzval
  simp [num.imp.dec2flt.parse.parse_scientific,
    core.slice.Slice.split_first, dec2flt_model.ModelSliceSplitFirst,
    core.num.U8.is_ascii_digit, dec2flt_model.ModelU8IsAsciiDigit,
    Slice.index_usize]
  simp [num.imp.dec2flt.parse.parse_scientific_loop]
  rw [Aeneas.Std.loop.eq_1]
  have first_product : (10#i64 * 0#i64) = ok 0#i64 := by rfl
  have first_sum : (0#i64 + 6#i64) = ok 6#i64 := by rfl
  have first_digit :
      UScalar.hcast IScalarTy.I64
          (core.num.U8.wrapping_sub 54#u8 48#u8) = 6#i64 := by
    rfl
  have first_sum2 :
      0#i64 + UScalar.hcast IScalarTy.I64
          (core.num.U8.wrapping_sub 54#u8 48#u8) = ok 6#i64 := by
    rfl
  have first_sum3 :
      0#i64 + UScalar.hcast IScalarTy.I64
          (UScalar.wrapping_sub 54#u8 48#u8) = ok 6#i64 := by
    rfl
  have first_count : (0#usize + 1#usize) = ok 1#usize :=
    addOne _ _ (by rfl)
  have second_product : (10#i64 * 6#i64) = ok 60#i64 := by rfl
  have second_sum :
      60#i64 + UScalar.hcast IScalarTy.I64
          (UScalar.wrapping_sub 53#u8 48#u8) = ok 65#i64 := by
    rfl
  have second_count : (1#usize + 1#usize) = ok 2#usize :=
    addOne _ _ (by rfl)
  have third_product : (10#i64 * 65#i64) = ok 650#i64 := by rfl
  have third_sum :
      650#i64 + UScalar.hcast IScalarTy.I64
          (UScalar.wrapping_sub 53#u8 48#u8) = ok 655#i64 := by
    rfl
  have third_count : (2#usize + 1#usize) = ok 3#usize :=
    addOne _ _ (by rfl)
  have fourth_product : (10#i64 * 655#i64) = ok 6550#i64 := by rfl
  have fourth_sum :
      6550#i64 + UScalar.hcast IScalarTy.I64
          (UScalar.wrapping_sub 51#u8 48#u8) = ok 6553#i64 := by
    rfl
  have fourth_count : (3#usize + 1#usize) = ok 4#usize :=
    addOne _ _ (by rfl)
  have fifth_product : (10#i64 * 6553#i64) = ok 65530#i64 := by rfl
  have fifth_sum :
      65530#i64 + UScalar.hcast IScalarTy.I64
          (UScalar.wrapping_sub 54#u8 48#u8) = ok 65536#i64 := by
    rfl
  have fifth_count : (4#usize + 1#usize) = ok 5#usize :=
    addOne _ _ (by rfl)
  have sixth_count : (5#usize + 1#usize) = ok 6#usize :=
    addOne _ _ (by rfl)
  simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
    Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq,
    first_product, first_sum, first_count, first_digit, first_sum2]
  rw [first_sum3]
  simp
  rw [Aeneas.Std.loop.eq_1]
  simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
    Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
  simp [second_product, second_sum, second_count]
  rw [Aeneas.Std.loop.eq_1]
  simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
    Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
  simp [third_product, third_sum, third_count]
  rw [Aeneas.Std.loop.eq_1]
  simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
    Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
  simp [fourth_product, fourth_sum, fourth_count]
  rw [Aeneas.Std.loop.eq_1]
  simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
    Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
  simp [fifth_product, fifth_sum, fifth_count]
  rw [Aeneas.Std.loop.eq_1]
  simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
    Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq, sixth_count]
  rw [Aeneas.Std.loop.eq_1]
  simp [num.imp.dec2flt.parse.parse_scientific_loop.body,
    core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop,
    Slice.length, List.drop]

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.num_imp_dec2flt_parse_parse_scientific

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserExactRoundingScientific]
theorem ParserExactRoundingScientific (s : Slice Std.U8)
    (hs : s.val = [54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) :
    exists rest,
      num.imp.dec2flt.parse.parse_scientific s =
          ok (some 65536#i64, rest) /\
        rest.val = [] := by
-- BODY
  have ht : s = (⟨[54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8], by
      rcases Usize.bounds_eq with q | q <;>
        norm_num [q, U32.max_eq, U64.max_eq]⟩ : Slice Std.U8) := by
    exact (Slice.eq_iff _ _).2 hs
  rw [ht]
  refine ⟨⟨[], by simp⟩, ?_, by rfl⟩
  have addOne (x y : Usize) (hxy : x.val + 1 = y.val) :
      x + 1#usize = ok y := by
    have hmax : x.val + (1#usize).val <= UScalar.max .Usize := by
      rw [show (1#usize).val = 1 by rfl, hxy]
      have hy := UScalar.hrBounds y
      simpa [UScalar.rMax_eq_max] using hy
    obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
      (UScalar.add_spec hmax)
    rw [hz]
    congr 1
    apply UScalar.eq_of_val_eq
    simpa [hxy] using hzval
  simp [num.imp.dec2flt.parse.parse_scientific,
    core.slice.Slice.split_first, dec2flt_model.ModelSliceSplitFirst,
    core.num.U8.is_ascii_digit, dec2flt_model.ModelU8IsAsciiDigit,
    Slice.index_usize]
  simp [num.imp.dec2flt.parse.parse_scientific_loop]
  rw [Aeneas.Std.loop.eq_1]
  have first_product : (10#i64 * 0#i64) = ok 0#i64 := by rfl
  have first_sum : (0#i64 + 6#i64) = ok 6#i64 := by rfl
  have first_digit :
      UScalar.hcast IScalarTy.I64
          (core.num.U8.wrapping_sub 54#u8 48#u8) = 6#i64 := by
    rfl
  have first_sum2 :
      0#i64 + UScalar.hcast IScalarTy.I64
          (core.num.U8.wrapping_sub 54#u8 48#u8) = ok 6#i64 := by
    rfl
  have first_sum3 :
      0#i64 + UScalar.hcast IScalarTy.I64
          (UScalar.wrapping_sub 54#u8 48#u8) = ok 6#i64 := by
    rfl
  have first_count : (0#usize + 1#usize) = ok 1#usize :=
    addOne _ _ (by rfl)
  have second_product : (10#i64 * 6#i64) = ok 60#i64 := by rfl
  have second_sum :
      60#i64 + UScalar.hcast IScalarTy.I64
          (UScalar.wrapping_sub 53#u8 48#u8) = ok 65#i64 := by
    rfl
  have second_count : (1#usize + 1#usize) = ok 2#usize :=
    addOne _ _ (by rfl)
  have third_product : (10#i64 * 65#i64) = ok 650#i64 := by rfl
  have third_sum :
      650#i64 + UScalar.hcast IScalarTy.I64
          (UScalar.wrapping_sub 53#u8 48#u8) = ok 655#i64 := by
    rfl
  have third_count : (2#usize + 1#usize) = ok 3#usize :=
    addOne _ _ (by rfl)
  have fourth_product : (10#i64 * 655#i64) = ok 6550#i64 := by rfl
  have fourth_sum :
      6550#i64 + UScalar.hcast IScalarTy.I64
          (UScalar.wrapping_sub 51#u8 48#u8) = ok 6553#i64 := by
    rfl
  have fourth_count : (3#usize + 1#usize) = ok 4#usize :=
    addOne _ _ (by rfl)
  have fifth_product : (10#i64 * 6553#i64) = ok 65530#i64 := by rfl
  have fifth_sum :
      65530#i64 + UScalar.hcast IScalarTy.I64
          (UScalar.wrapping_sub 54#u8 48#u8) = ok 65536#i64 := by
    rfl
  have fifth_count : (4#usize + 1#usize) = ok 5#usize :=
    addOne _ _ (by rfl)
  have sixth_count : (5#usize + 1#usize) = ok 6#usize :=
    addOne _ _ (by rfl)
  simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
    Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq,
    first_product, first_sum, first_count, first_digit, first_sum2]
  rw [first_sum3]
  simp
  rw [Aeneas.Std.loop.eq_1]
  simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
    Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
  simp [second_product, second_sum, second_count]
  rw [Aeneas.Std.loop.eq_1]
  simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
    Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
  simp [third_product, third_sum, third_count]
  rw [Aeneas.Std.loop.eq_1]
  simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
    Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
  simp [fourth_product, fourth_sum, fourth_count]
  rw [Aeneas.Std.loop.eq_1]
  simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
    Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
  simp [fifth_product, fifth_sum, fifth_count]
  rw [Aeneas.Std.loop.eq_1]
  simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
    Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq, sixth_count]
  rw [Aeneas.Std.loop.eq_1]
  simp [num.imp.dec2flt.parse.parse_scientific_loop.body,
    core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop,
    Slice.length, List.drop]

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (47)
More program dependencies (14)
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 31 entries
Technical checking records
Local closure summary
{
  "node": "ParserExactRoundingScientific",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "f6355057872a7715107cd2a274e90d5059a80f890e8952baf0162cdb934dc4b0",
  "active_statement_hash": "4f56bb3562a2fe1622b37ad61c1c01b309fdcf538f768f0afa0675eb9d2c424a",
  "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-128",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "ModelSliceSplitFirst": "f617ee05dd2925a9",
    "num_imp_dec2flt_parse_parse_scientific": "ba81300a2601d639"
  },
  "strict_definition_deps": {
    "ModelSliceSplitFirst": "4ed9c51a5bb9fb58",
    "ModelU8IsAsciiDigit": "67d39fc6c37cfc41",
    "Preamble": "956f3baee2191107",
    "num_imp_dec2flt_parse_parse_scientific": "76b01b9377828a5f"
  }
}
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:43ecfd0e038b69a344df826374c3bf9a481d6c1f2ab585a32125c8e7b6797c75",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}