ParserNumericAdjustmentCertificate

Lean checked

Statement

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

Helper · Exact many-digit adjustment

Let s begin with the bytes 0., then eleven ASCII zero bytes, then an ASCII 1, followed by an arbitrary suffix. The extracted adjust_many_digit_count operation, started with count 2{,}147{,}483{,}630, returns the exact count 2{,}147{,}483{,}618.

Lean statement

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

import Tablet.NumberHelperAdjustManySourceLength

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

namespace dec2flt_model

-- [TABLET NODE: ParserNumericAdjustmentCertificate]
theorem ParserNumericAdjustmentCertificate (s : Slice Std.U8)
    (tail : List Std.U8)
    (hs : s.val = [48#u8, 46#u8] ++
      List.replicate 11 48#u8 ++ 49#u8 :: tail) :
    num.imp.dec2flt.parse.adjust_many_digit_count s 2147483630#isize =
      ok 2147483618#isize := 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 extracted loop in num imp dec2flt parse adjust many digit count. On the initial 0, subtracting one from its byte value and then saturating at zero produces one, so the checked signed count decreases from 2{,}147{,}483{,}630 to 2{,}147{,}483{,}629. On the point byte the same calculation produces zero, so the count is unchanged. Each of the next eleven zero bytes again produces one, giving the successive counts 2{,}147{,}483{,}628 through 2{,}147{,}483{,}618. The following byte is 1, so its adjusted byte value is two; the loop changes its scanning flag to false without changing the count, and the following loop head returns.
There are thirteen successful index increments, from zero through thirteen. All are within the 64-bit usize range, and all twelve subtractions by one (as well as the subtraction by zero) remain within the 64-bit isize range fixed by Assumptions. Thus every checked operation follows the successful branch and the extracted loop returns the claimed exact count.

Lean proof


  have hcast0 : UScalar.hcast .Isize 0#u8 = 0#isize := by
    apply IScalar.eq_of_val_eq
    have h := UScalar.hcast_inBounds_spec .Isize (0#u8) (by scalar_tac)
    simpa [Aeneas.Std.lift, WP.spec_ok] using h
  have hcast1 : UScalar.hcast .Isize 1#u8 = 1#isize := by
    apply IScalar.eq_of_val_eq
    have h := UScalar.hcast_inBounds_spec .Isize (1#u8) (by scalar_tac)
    simpa [Aeneas.Std.lift, WP.spec_ok] using h
  have hbyteSub : (48#u8 - 1#u8) = ok 47#u8 := by rfl
  have hsat0 : core.num.U8.saturating_sub 46#u8 47#u8 = 0#u8 := by rfl
  have hsat1 : core.num.U8.saturating_sub 48#u8 47#u8 = 1#u8 := 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
    have ha := UScalar.add_spec hmax
    obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists ha
    rw [hz]
    congr 1
    apply UScalar.eq_of_val_eq
    simpa [hxy] using hzval
  have subSmall (x y d : Isize) (hd : d = 0#isize ∨ d = 1#isize)
      (hxy : x.val - d.val = y.val) : x - d = ok y := by
    have hy := IScalar.hBounds y
    have hmin : IScalar.min .Isize ≤ x.val - d.val := by
      rw [hxy]
      simp only [IScalar.min]
      simpa [IScalarTy.numBits, Dec2Flt.configured_x86_64_numBits] using hy.1
    have hmax : x.val - d.val ≤ IScalar.max .Isize := by
      rw [hxy]
      simp only [IScalar.max]
      have := hy.2
      simp [IScalarTy.numBits, Dec2Flt.configured_x86_64_numBits] at this ⊢
      omega
    have hsub := IScalar.sub_spec (x := x) (y := d) hmin hmax
    obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists hsub
    rw [hz]
    congr 1
    apply IScalar.eq_of_val_eq
    simpa [hxy] using hzval
  have hidx0 : 0#usize + 1#usize = ok 1#usize := addOne _ _ (by rfl)
  have hidx1 : 1#usize + 1#usize = ok 2#usize := addOne _ _ (by rfl)
  have hidx2 : 2#usize + 1#usize = ok 3#usize := addOne _ _ (by rfl)
  have hidx3 : 3#usize + 1#usize = ok 4#usize := addOne _ _ (by rfl)
  have hidx4 : 4#usize + 1#usize = ok 5#usize := addOne _ _ (by rfl)
  have hidx5 : 5#usize + 1#usize = ok 6#usize := addOne _ _ (by rfl)
  have hidx6 : 6#usize + 1#usize = ok 7#usize := addOne _ _ (by rfl)
  have hidx7 : 7#usize + 1#usize = ok 8#usize := addOne _ _ (by rfl)
  have hidx8 : 8#usize + 1#usize = ok 9#usize := addOne _ _ (by rfl)
  have hidx9 : 9#usize + 1#usize = ok 10#usize := addOne _ _ (by rfl)
  have hidx10 : 10#usize + 1#usize = ok 11#usize := addOne _ _ (by rfl)
  have hidx11 : 11#usize + 1#usize = ok 12#usize := addOne _ _ (by rfl)
  have hidx12 : 12#usize + 1#usize = ok 13#usize := addOne _ _ (by rfl)
  have hsub0 : 2147483630#isize - 1#isize = ok 2147483629#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsubPoint : 2147483629#isize - 0#isize = ok 2147483629#isize :=
    subSmall _ _ _ (Or.inl rfl) (by scalar_tac)
  have hsub1 : 2147483629#isize - 1#isize = ok 2147483628#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub2 : 2147483628#isize - 1#isize = ok 2147483627#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub3 : 2147483627#isize - 1#isize = ok 2147483626#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub4 : 2147483626#isize - 1#isize = ok 2147483625#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub5 : 2147483625#isize - 1#isize = ok 2147483624#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub6 : 2147483624#isize - 1#isize = ok 2147483623#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub7 : 2147483623#isize - 1#isize = ok 2147483622#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub8 : 2147483622#isize - 1#isize = ok 2147483621#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub9 : 2147483621#isize - 1#isize = ok 2147483620#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub10 : 2147483620#isize - 1#isize = ok 2147483619#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub11 : 2147483619#isize - 1#isize = ok 2147483618#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  unfold num.imp.dec2flt.parse.adjust_many_digit_count
  unfold num.imp.dec2flt.parse.adjust_many_digit_count_loop
  repeat'
    (rw [Aeneas.Std.loop.eq_1]
     simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
       Slice.index_usize, hs, List.replicate_succ,
       hbyteSub, hsat0, hsat1, Aeneas.Std.lift, hcast0, hcast1,
       hidx0, hidx1, hidx2, hidx3, hidx4, hidx5, hidx6, hidx7,
       hidx8, hidx9, hidx10, hidx11, hidx12,
       hsub0, hsubPoint, hsub1, hsub2, hsub3, hsub4, hsub5, hsub6,
       hsub7, hsub8, hsub9, hsub10, hsub11,
       UScalar.sub, UScalar.saturating_sub,
       IScalar.sub, IScalar.tryMk, IScalar.tryMkOpt, IScalar.check_bounds,
       IScalar.inBounds, IScalar.min, IScalar.max,
       UScalar.add, Dec2Flt.configured_x86_64_numBits])

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.NumberHelperAdjustManySourceLength

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

namespace dec2flt_model

-- [TABLET NODE: ParserNumericAdjustmentCertificate]
theorem ParserNumericAdjustmentCertificate (s : Slice Std.U8)
    (tail : List Std.U8)
    (hs : s.val = [48#u8, 46#u8] ++
      List.replicate 11 48#u8 ++ 49#u8 :: tail) :
    num.imp.dec2flt.parse.adjust_many_digit_count s 2147483630#isize =
      ok 2147483618#isize := by
-- BODY
  have hcast0 : UScalar.hcast .Isize 0#u8 = 0#isize := by
    apply IScalar.eq_of_val_eq
    have h := UScalar.hcast_inBounds_spec .Isize (0#u8) (by scalar_tac)
    simpa [Aeneas.Std.lift, WP.spec_ok] using h
  have hcast1 : UScalar.hcast .Isize 1#u8 = 1#isize := by
    apply IScalar.eq_of_val_eq
    have h := UScalar.hcast_inBounds_spec .Isize (1#u8) (by scalar_tac)
    simpa [Aeneas.Std.lift, WP.spec_ok] using h
  have hbyteSub : (48#u8 - 1#u8) = ok 47#u8 := by rfl
  have hsat0 : core.num.U8.saturating_sub 46#u8 47#u8 = 0#u8 := by rfl
  have hsat1 : core.num.U8.saturating_sub 48#u8 47#u8 = 1#u8 := 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
    have ha := UScalar.add_spec hmax
    obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists ha
    rw [hz]
    congr 1
    apply UScalar.eq_of_val_eq
    simpa [hxy] using hzval
  have subSmall (x y d : Isize) (hd : d = 0#isize ∨ d = 1#isize)
      (hxy : x.val - d.val = y.val) : x - d = ok y := by
    have hy := IScalar.hBounds y
    have hmin : IScalar.min .Isize ≤ x.val - d.val := by
      rw [hxy]
      simp only [IScalar.min]
      simpa [IScalarTy.numBits, Dec2Flt.configured_x86_64_numBits] using hy.1
    have hmax : x.val - d.val ≤ IScalar.max .Isize := by
      rw [hxy]
      simp only [IScalar.max]
      have := hy.2
      simp [IScalarTy.numBits, Dec2Flt.configured_x86_64_numBits] at this ⊢
      omega
    have hsub := IScalar.sub_spec (x := x) (y := d) hmin hmax
    obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists hsub
    rw [hz]
    congr 1
    apply IScalar.eq_of_val_eq
    simpa [hxy] using hzval
  have hidx0 : 0#usize + 1#usize = ok 1#usize := addOne _ _ (by rfl)
  have hidx1 : 1#usize + 1#usize = ok 2#usize := addOne _ _ (by rfl)
  have hidx2 : 2#usize + 1#usize = ok 3#usize := addOne _ _ (by rfl)
  have hidx3 : 3#usize + 1#usize = ok 4#usize := addOne _ _ (by rfl)
  have hidx4 : 4#usize + 1#usize = ok 5#usize := addOne _ _ (by rfl)
  have hidx5 : 5#usize + 1#usize = ok 6#usize := addOne _ _ (by rfl)
  have hidx6 : 6#usize + 1#usize = ok 7#usize := addOne _ _ (by rfl)
  have hidx7 : 7#usize + 1#usize = ok 8#usize := addOne _ _ (by rfl)
  have hidx8 : 8#usize + 1#usize = ok 9#usize := addOne _ _ (by rfl)
  have hidx9 : 9#usize + 1#usize = ok 10#usize := addOne _ _ (by rfl)
  have hidx10 : 10#usize + 1#usize = ok 11#usize := addOne _ _ (by rfl)
  have hidx11 : 11#usize + 1#usize = ok 12#usize := addOne _ _ (by rfl)
  have hidx12 : 12#usize + 1#usize = ok 13#usize := addOne _ _ (by rfl)
  have hsub0 : 2147483630#isize - 1#isize = ok 2147483629#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsubPoint : 2147483629#isize - 0#isize = ok 2147483629#isize :=
    subSmall _ _ _ (Or.inl rfl) (by scalar_tac)
  have hsub1 : 2147483629#isize - 1#isize = ok 2147483628#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub2 : 2147483628#isize - 1#isize = ok 2147483627#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub3 : 2147483627#isize - 1#isize = ok 2147483626#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub4 : 2147483626#isize - 1#isize = ok 2147483625#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub5 : 2147483625#isize - 1#isize = ok 2147483624#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub6 : 2147483624#isize - 1#isize = ok 2147483623#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub7 : 2147483623#isize - 1#isize = ok 2147483622#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub8 : 2147483622#isize - 1#isize = ok 2147483621#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub9 : 2147483621#isize - 1#isize = ok 2147483620#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub10 : 2147483620#isize - 1#isize = ok 2147483619#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  have hsub11 : 2147483619#isize - 1#isize = ok 2147483618#isize :=
    subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
  unfold num.imp.dec2flt.parse.adjust_many_digit_count
  unfold num.imp.dec2flt.parse.adjust_many_digit_count_loop
  repeat'
    (rw [Aeneas.Std.loop.eq_1]
     simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
       Slice.index_usize, hs, List.replicate_succ,
       hbyteSub, hsat0, hsat1, Aeneas.Std.lift, hcast0, hcast1,
       hidx0, hidx1, hidx2, hidx3, hidx4, hidx5, hidx6, hidx7,
       hidx8, hidx9, hidx10, hidx11, hidx12,
       hsub0, hsubPoint, hsub1, hsub2, hsub3, hsub4, hsub5, hsub6,
       hsub7, hsub8, hsub9, hsub10, hsub11,
       UScalar.sub, UScalar.saturating_sub,
       IScalar.sub, IScalar.tryMk, IScalar.tryMkOpt, IScalar.check_bounds,
       IScalar.inBounds, IScalar.min, IScalar.max,
       UScalar.add, Dec2Flt.configured_x86_64_numBits])

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
Technical checking records
Local closure summary
{
  "node": "ParserNumericAdjustmentCertificate",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "88ba9abe6a38283fed6d456c3874d79ebd781acbf63eb7d687882a50d9de1a5b",
  "active_statement_hash": "edbbf7b119191e2d95e612db0637624a1d5eed646fd9c648c80563517c6f9a7d",
  "kernel_axioms": [
    "Classical.choice",
    "Dec2Flt.configured_x86_64_numBits",
    "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_parse_adjust_many_digit_count": "faf0081b4c91301b"
  },
  "strict_definition_deps": {
    "num_imp_dec2flt_parse_adjust_many_digit_count": "1bc88a1b016164f3"
  }
}
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:b6b7447bbf333b81e6b7bd00be4135f218bf4fc792ae0448c7ce23b1e65c5a49",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}