NumberHelperScientificTrailingByte

Lean checked

Statement

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

Helper · Exact scientific prefix with one trailing byte

Let s and r be byte slices with
s=[45,54,53,53,51,53,57,120] \quad\text{and}\quad r=[120].
Then the extracted scientific parser returns the signed exponent -655359 and leaves exactly r:
\texttt{parse\_scientific}(s)=\texttt{ok}(\texttt{some}(-655359),r).

Lean statement

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

import Tablet.Assumptions
import Tablet.ModelSliceSplitFirst
import Tablet.ModelU8IsAsciiDigit
import Tablet.num_imp_dec2flt_parse_parse_scientific

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperScientificTrailingByte]
theorem NumberHelperScientificTrailingByte
    (suffix residual : Slice Std.U8)
    (hsuffix : suffix.val =
      [45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8, 120#u8])
    (hresidual : residual.val = [120#u8]) :
    num.imp.dec2flt.parse.parse_scientific suffix =
      ok (some ((-655359)#i64), residual) := 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

The two displayed lists have lengths eight and one, so the configured 64-bit usize bound in Assumptions supplies both slice carriers. Extensionality identifies the given slices with these concrete carriers.
Unfold num imp dec2flt parse parse scientific. By ModelSliceSplitFirst, the initial split removes byte 45, sets the negative flag, and leaves [54,53,53,51,53,57,120]. Byte 54 is an ASCII digit by ModelU8IsAsciiDigit, so the decimal loop begins with accumulator zero and count zero. Its first six iterations read the bytes 54,53,53,51,53,57. Wrapping subtraction by 48 gives respectively the digits 6,5,5,3,5,9, and the checked recurrences 10a+d give
6, 65, 655, 6553, 65535, 655359.
Every intermediate value is below 2^{63}, and the checked counts advance from zero through six, well within both usize and the seven-byte post-sign slice.
At count six the indexed byte is 120. Subtracting 48 gives 72, which is not below ten, so the loop stops without updating the accumulator or count. The final range operation therefore drops exactly the six digit bytes and leaves the one-byte slice [120]=r. Finally, checked signed negation maps 655359 to -655359, which is strictly inside the i64 range. Thus the extracted function returns precisely the claimed option, exponent, and residual slice.

Lean proof


  have hbound :
      [45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8,
        120#u8].length <= Usize.max := by
    have h := Usize.max_succ_eq_pow
    rw [Dec2Flt.configured_x86_64_numBits] at h
    norm_num at h ⊢
    omega
  let concrete : Slice Std.U8 :=
    ⟨[45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8,
      120#u8], hbound⟩
  have hsuffixEq : suffix = concrete :=
    (Slice.eq_iff _ _).2 (by simpa [concrete] using hsuffix)
  have hresBound : [120#u8].length <= Usize.max := by
    have h := Usize.max_succ_eq_pow
    rw [Dec2Flt.configured_x86_64_numBits] at h
    norm_num at h ⊢
    omega
  let concreteResidual : Slice Std.U8 := ⟨[120#u8], hresBound⟩
  have hresidualEq : residual = concreteResidual :=
    (Slice.eq_iff _ _).2 (by simpa [concreteResidual] using hresidual)
  rw [hsuffixEq, hresidualEq]
  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, concrete]
  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 := by
    change UScalar.add (0#usize) (1#usize) = ok 1#usize
    unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
    simp [Result.ofOption, UScalar.check_bounds,
      Dec2Flt.configured_x86_64_numBits]
  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 := by
    change UScalar.add (1#usize) (1#usize) = ok 2#usize
    unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
    simp [Result.ofOption, UScalar.check_bounds,
      Dec2Flt.configured_x86_64_numBits]
  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 := by
    change UScalar.add (2#usize) (1#usize) = ok 3#usize
    unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
    simp [Result.ofOption, UScalar.check_bounds,
      Dec2Flt.configured_x86_64_numBits]
  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 := by
    change UScalar.add (3#usize) (1#usize) = ok 4#usize
    unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
    simp [Result.ofOption, UScalar.check_bounds,
      Dec2Flt.configured_x86_64_numBits]
  have fifth_product : (10#i64 * 6553#i64) = ok 65530#i64 := by rfl
  have fifth_sum :
      (65530#i64 + UScalar.hcast IScalarTy.I64
        (UScalar.wrapping_sub 53#u8 48#u8)) = ok 65535#i64 := by rfl
  have fifth_count : (4#usize + 1#usize) = ok 5#usize := by
    change UScalar.add (4#usize) (1#usize) = ok 5#usize
    unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
    simp [Result.ofOption, UScalar.check_bounds,
      Dec2Flt.configured_x86_64_numBits]
  have sixth_product :
      (10#i64 * 65535#i64) = ok 655350#i64 := by rfl
  have sixth_sum :
      (655350#i64 + UScalar.hcast IScalarTy.I64
        (UScalar.wrapping_sub 57#u8 48#u8)) = ok 655359#i64 := by rfl
  have sixth_count : (5#usize + 1#usize) = ok 6#usize := by
    change UScalar.add (5#usize) (1#usize) = ok 6#usize
    unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
    simp [Result.ofOption, UScalar.check_bounds,
      Dec2Flt.configured_x86_64_numBits]
  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, 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, 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, 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, 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_product, sixth_sum, sixth_count]
  rw [Aeneas.Std.loop.eq_1]
  have neg_final :
      IScalar.neg (655359#i64) = ok ((-655359)#i64) := by rfl
  simp [num.imp.dec2flt.parse.parse_scientific_loop.body,
    core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop,
    Slice.length, List.drop, HNeg.hNeg, IScalar.neg, neg_final,
    IScalar.tryMk, IScalar.tryMkOpt, Result.ofOption,
    IScalar.check_bounds, Dec2Flt.configured_x86_64_numBits,
    concreteResidual]

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.Assumptions
import Tablet.ModelSliceSplitFirst
import Tablet.ModelU8IsAsciiDigit
import Tablet.num_imp_dec2flt_parse_parse_scientific

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperScientificTrailingByte]
theorem NumberHelperScientificTrailingByte
    (suffix residual : Slice Std.U8)
    (hsuffix : suffix.val =
      [45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8, 120#u8])
    (hresidual : residual.val = [120#u8]) :
    num.imp.dec2flt.parse.parse_scientific suffix =
      ok (some ((-655359)#i64), residual) := by
-- BODY
  have hbound :
      [45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8,
        120#u8].length <= Usize.max := by
    have h := Usize.max_succ_eq_pow
    rw [Dec2Flt.configured_x86_64_numBits] at h
    norm_num at h ⊢
    omega
  let concrete : Slice Std.U8 :=
    ⟨[45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8,
      120#u8], hbound⟩
  have hsuffixEq : suffix = concrete :=
    (Slice.eq_iff _ _).2 (by simpa [concrete] using hsuffix)
  have hresBound : [120#u8].length <= Usize.max := by
    have h := Usize.max_succ_eq_pow
    rw [Dec2Flt.configured_x86_64_numBits] at h
    norm_num at h ⊢
    omega
  let concreteResidual : Slice Std.U8 := ⟨[120#u8], hresBound⟩
  have hresidualEq : residual = concreteResidual :=
    (Slice.eq_iff _ _).2 (by simpa [concreteResidual] using hresidual)
  rw [hsuffixEq, hresidualEq]
  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, concrete]
  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 := by
    change UScalar.add (0#usize) (1#usize) = ok 1#usize
    unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
    simp [Result.ofOption, UScalar.check_bounds,
      Dec2Flt.configured_x86_64_numBits]
  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 := by
    change UScalar.add (1#usize) (1#usize) = ok 2#usize
    unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
    simp [Result.ofOption, UScalar.check_bounds,
      Dec2Flt.configured_x86_64_numBits]
  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 := by
    change UScalar.add (2#usize) (1#usize) = ok 3#usize
    unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
    simp [Result.ofOption, UScalar.check_bounds,
      Dec2Flt.configured_x86_64_numBits]
  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 := by
    change UScalar.add (3#usize) (1#usize) = ok 4#usize
    unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
    simp [Result.ofOption, UScalar.check_bounds,
      Dec2Flt.configured_x86_64_numBits]
  have fifth_product : (10#i64 * 6553#i64) = ok 65530#i64 := by rfl
  have fifth_sum :
      (65530#i64 + UScalar.hcast IScalarTy.I64
        (UScalar.wrapping_sub 53#u8 48#u8)) = ok 65535#i64 := by rfl
  have fifth_count : (4#usize + 1#usize) = ok 5#usize := by
    change UScalar.add (4#usize) (1#usize) = ok 5#usize
    unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
    simp [Result.ofOption, UScalar.check_bounds,
      Dec2Flt.configured_x86_64_numBits]
  have sixth_product :
      (10#i64 * 65535#i64) = ok 655350#i64 := by rfl
  have sixth_sum :
      (655350#i64 + UScalar.hcast IScalarTy.I64
        (UScalar.wrapping_sub 57#u8 48#u8)) = ok 655359#i64 := by rfl
  have sixth_count : (5#usize + 1#usize) = ok 6#usize := by
    change UScalar.add (5#usize) (1#usize) = ok 6#usize
    unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
    simp [Result.ofOption, UScalar.check_bounds,
      Dec2Flt.configured_x86_64_numBits]
  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, 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, 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, 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, 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_product, sixth_sum, sixth_count]
  rw [Aeneas.Std.loop.eq_1]
  have neg_final :
      IScalar.neg (655359#i64) = ok ((-655359)#i64) := by rfl
  simp [num.imp.dec2flt.parse.parse_scientific_loop.body,
    core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop,
    Slice.length, List.drop, HNeg.hNeg, IScalar.neg, neg_final,
    IScalar.tryMk, IScalar.tryMkOpt, Result.ofOption,
    IScalar.check_bounds, Dec2Flt.configured_x86_64_numBits,
    concreteResidual]

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": "NumberHelperScientificTrailingByte",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "3641756bc956a120af3bec8cc363aec4745d01acb69d16c8e018d3b8d1c4dc6c",
  "active_statement_hash": "ab587051eef686008d2d429db6bb7275c66359a92ad213de32a683fec1e3cb96",
  "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-118",
  "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:aa60b4710346fcd4d797dd88f8d602100a1603dc59e60ad5ae1ee742892e3a63",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}