NumberHelperMaximalManyDigits

Lean checked

Statement

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

Helper · Maximal many-digit retry overflow

Let start be the maximal witness bytes and intEnd its seven-byte suffix e655360. The extracted parse_many_digits(start,intEnd,65536) returns fail integerOverflow.

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.NumberHelperMaximalRetryOffset
import Tablet.NumberHelperMaximalRetryScan
import Tablet.num_imp_dec2flt_parse_parse_many_digits

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperMaximalManyDigits]
theorem NumberHelperMaximalManyDigits (start intEnd : Slice Std.U8)
    (hstart : start.val = List.replicate 9223372036854775800 49#u8 ++
      [101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8])
    (hintEnd : intEnd.val =
      [101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) :
    num.imp.dec2flt.parse.parse_many_digits start intEnd 65536#i64 =
      fail integerOverflow := 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

By NumberHelperMaximalRetryScan, the fresh retry from zero returns mantissa 1111111111111111111 and a residual of length 9223372036854775781+7=9223372036854775788. The mantissa is at least the cutoff 10^{18} from num imp dec2flt parse MIN 19DIGIT INT, so num imp dec2flt parse parse many digits selects its first branch.
Apply the first conjunct of NumberHelperMaximalRetryOffset to this residual and the seven-byte integer-end suffix. It returns an isize offset of 9223372036854775781. This value lies in the signed 64-bit range by Assumptions, so the extracted cast to i64 succeeds and preserves it. The second conjunct of the same lemma states that adding the scientific exponent 65536 to this value returns exactly fail integerOverflow. The preceding extracted binds all succeeded, so this failure is propagated as the result of parse_many_digits.

Lean proof


  obtain ⟨rest, hscan, hrest⟩ := NumberHelperMaximalRetryScan start hstart
  have hrestLen : rest.val.length = 9223372036854775788 := by
    rw [hrest, List.length_append, List.length_replicate]
    norm_num
  have hintEndLen : intEnd.val.length = 7 := by
    rw [hintEnd]
    norm_num
  obtain ⟨offset, hoffsetVal, hoffset⟩ :=
    NumberHelperMaximalRetryOffset.1 rest intEnd hrestLen hintEndLen
  have hcast : lift (IScalar.cast .I64 offset) =
      ok 9223372036854775781#i64 := by
    have hbound : IScalar.min .I64 <= offset.val /\
        offset.val <= IScalar.max .I64 := by
      rw [hoffsetVal]
      simp [I64.min_eq, I64.max_eq]
    obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
      (IScalar.cast_inBounds_spec .I64 offset hbound)
    rw [hz]
    congr 2
    apply IScalar.eq_of_val_eq
    simpa [hoffsetVal] using hzval
  have hoverflow := NumberHelperMaximalRetryOffset.2
  unfold num.imp.dec2flt.parse.parse_many_digits
  simp [hscan, num.imp.dec2flt.parse.MIN_19DIGIT_INT.eq_def,
    hoffset, hcast, hoverflow]

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.Assumptions
import Tablet.NumberHelperMaximalRetryOffset
import Tablet.NumberHelperMaximalRetryScan
import Tablet.num_imp_dec2flt_parse_parse_many_digits

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperMaximalManyDigits]
theorem NumberHelperMaximalManyDigits (start intEnd : Slice Std.U8)
    (hstart : start.val = List.replicate 9223372036854775800 49#u8 ++
      [101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8])
    (hintEnd : intEnd.val =
      [101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) :
    num.imp.dec2flt.parse.parse_many_digits start intEnd 65536#i64 =
      fail integerOverflow := by
-- BODY
  obtain ⟨rest, hscan, hrest⟩ := NumberHelperMaximalRetryScan start hstart
  have hrestLen : rest.val.length = 9223372036854775788 := by
    rw [hrest, List.length_append, List.length_replicate]
    norm_num
  have hintEndLen : intEnd.val.length = 7 := by
    rw [hintEnd]
    norm_num
  obtain ⟨offset, hoffsetVal, hoffset⟩ :=
    NumberHelperMaximalRetryOffset.1 rest intEnd hrestLen hintEndLen
  have hcast : lift (IScalar.cast .I64 offset) =
      ok 9223372036854775781#i64 := by
    have hbound : IScalar.min .I64 <= offset.val /\
        offset.val <= IScalar.max .I64 := by
      rw [hoffsetVal]
      simp [I64.min_eq, I64.max_eq]
    obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
      (IScalar.cast_inBounds_spec .I64 offset hbound)
    rw [hz]
    congr 2
    apply IScalar.eq_of_val_eq
    simpa [hoffsetVal] using hzval
  have hoverflow := NumberHelperMaximalRetryOffset.2
  unfold num.imp.dec2flt.parse.parse_many_digits
  simp [hscan, num.imp.dec2flt.parse.MIN_19DIGIT_INT.eq_def,
    hoffset, hcast, hoverflow]

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (50)
More program dependencies (17)
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 37 entries
Technical checking records
Local closure summary
{
  "node": "NumberHelperMaximalManyDigits",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "484b32ba453b50e754ab6e75bd40d04cd83d4eb223dd042dd98541e2b9f4f88e",
  "active_statement_hash": "08146994a057dc8ae7491881d7119e5e8864c745338af9eae37220bf15a18c3e",
  "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-115",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "NumberHelperMaximalRetryOffset": "2d0f60666e00e4b4",
    "NumberHelperMaximalRetryScan": "6453bc0e5601fb3c",
    "num_imp_dec2flt_parse_MIN_19DIGIT_INT": "8d99761093f40bc7",
    "num_imp_dec2flt_parse_parse_many_digits": "faf0081b4c91301b"
  },
  "strict_definition_deps": {
    "SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from": "7e7284dc9bc88830",
    "num_imp_dec2flt_parse_MIN_19DIGIT_INT": "476edc5502ff7bfb",
    "num_imp_dec2flt_parse_parse_many_digits": "50c9ef13b3ed7fe8",
    "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:229e77f676569a0e6ce776646319f34c803044fd2b4ec1e6adaf9bdf4351280a",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}