NumberHelperSharpPartialExecution

Lean checked

Statement

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

Lemma · Sharp witness partial-parser execution

Suppose a nonempty unsigned slice initially stops its digit scan with zero accumulator and zero offset, then splits into a leading point and a fractional slice. Suppose that fractional slice consists of 9223372036854120450 ASCII 1 bytes followed by e-655359, with total length at most 9223372036854120458; the marker-tail slice is exactly e-655359; splitting it exposes e; and parsing the remaining suffix returns -655359. Then the extracted parse_partial_number 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.NumberHelperPartialExponentOverflowPropagation
import Tablet.NumberHelperSharpFractionalPrefix

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperSharpPartialExecution]
theorem NumberHelperSharpPartialExecution
    (s fracSlice markerTail suffix empty : Slice Std.U8)
    (hnotempty : Not (s.val = []))
    (hscanInt : num.imp.dec2flt.parse.try_parse_digits s 0#u64 =
      ok (s, 0#u64))
    (hoffInt :
      SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from s s =
        ok 0#isize)
    (hsplitPoint : core.slice.Slice.split_first s =
      ok (some (46#u8, fracSlice)))
    (hfrac : fracSlice.val =
      List.replicate 9223372036854120450 49#u8 ++
        [101#u8, 45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8])
    (hmarker : markerTail.val =
      [101#u8, 45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8])
    (hfracBound : fracSlice.val.length <= 9223372036854120458)
    (hsplitMarker : core.slice.Slice.split_first markerTail =
      ok (some (101#u8, suffix)))
    (hscientific : num.imp.dec2flt.parse.parse_scientific suffix =
      ok (some ((-655359)#i64), empty)) :
    num.imp.dec2flt.parse.parse_partial_number s = 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

Apply NumberHelperSharpFractionalPrefix to the fractional and marker-tail slices. It supplies the normal fractional scan, an offset of 9223372036854120450, its checked negation and cast with value -9223372036854120450, and the positive checked total digit count. The subsequent explicit-exponent addition has mathematical value
-9223372036854120450-655359=-9223372036854775809=-2^{63}-1.
This lies one below the minimum 64-bit signed value, so the extracted checked addition returns fail integerOverflow.
All hypotheses of NumberHelperPartialExponentOverflowPropagation are now present: the initial scan and offset, the point split, every certified fractional operation, the positive total, the exponent-marker split and scientific parse, and the failing exponent addition. That lemma propagates the failure through the result monad and yields the asserted partial-parser result.

Lean proof


  obtain ⟨mantissa, nAfter, negAfter, totalDigits, fracExponent,
      hscanFrac, hoffFrac, hnAfterEq, hnegAfter, hfracExponent,
      hfracExponentVal, htotal, htotalEq⟩ :=
    NumberHelperSharpFractionalPrefix fracSlice markerTail hfrac hmarker
      hfracBound
  have htotalPos : 0 < totalDigits.val := by
    rw [htotalEq]
    norm_num
  have hoverflow : fracExponent + ((-655359)#i64) = fail integerOverflow := by
    change IScalar.tryMk .I64 (fracExponent.val + ((-655359)#i64).val) =
      fail integerOverflow
    rw [hfracExponentVal]
    norm_num [IScalar.tryMk, IScalar.tryMkOpt, IScalar.check_bounds,
      IScalar.inBounds, IScalar.min, IScalar.max]
  exact NumberHelperPartialExponentOverflowPropagation s fracSlice markerTail
    suffix empty mantissa nAfter negAfter totalDigits fracExponent hnotempty
    hscanInt hoffInt hsplitPoint hscanFrac hoffFrac hnegAfter hfracExponent
    htotal htotalPos hsplitMarker hscientific hoverflow

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.NumberHelperPartialExponentOverflowPropagation
import Tablet.NumberHelperSharpFractionalPrefix

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperSharpPartialExecution]
theorem NumberHelperSharpPartialExecution
    (s fracSlice markerTail suffix empty : Slice Std.U8)
    (hnotempty : Not (s.val = []))
    (hscanInt : num.imp.dec2flt.parse.try_parse_digits s 0#u64 =
      ok (s, 0#u64))
    (hoffInt :
      SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from s s =
        ok 0#isize)
    (hsplitPoint : core.slice.Slice.split_first s =
      ok (some (46#u8, fracSlice)))
    (hfrac : fracSlice.val =
      List.replicate 9223372036854120450 49#u8 ++
        [101#u8, 45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8])
    (hmarker : markerTail.val =
      [101#u8, 45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8])
    (hfracBound : fracSlice.val.length <= 9223372036854120458)
    (hsplitMarker : core.slice.Slice.split_first markerTail =
      ok (some (101#u8, suffix)))
    (hscientific : num.imp.dec2flt.parse.parse_scientific suffix =
      ok (some ((-655359)#i64), empty)) :
    num.imp.dec2flt.parse.parse_partial_number s = fail integerOverflow := by
-- BODY
  obtain ⟨mantissa, nAfter, negAfter, totalDigits, fracExponent,
      hscanFrac, hoffFrac, hnAfterEq, hnegAfter, hfracExponent,
      hfracExponentVal, htotal, htotalEq⟩ :=
    NumberHelperSharpFractionalPrefix fracSlice markerTail hfrac hmarker
      hfracBound
  have htotalPos : 0 < totalDigits.val := by
    rw [htotalEq]
    norm_num
  have hoverflow : fracExponent + ((-655359)#i64) = fail integerOverflow := by
    change IScalar.tryMk .I64 (fracExponent.val + ((-655359)#i64).val) =
      fail integerOverflow
    rw [hfracExponentVal]
    norm_num [IScalar.tryMk, IScalar.tryMkOpt, IScalar.check_bounds,
      IScalar.inBounds, IScalar.min, IScalar.max]
  exact NumberHelperPartialExponentOverflowPropagation s fracSlice markerTail
    suffix empty mantissa nAfter negAfter totalDigits fracExponent hnotempty
    hscanInt hoffInt hsplitPoint hscanFrac hoffFrac hnegAfter hfracExponent
    htotal htotalPos hsplitMarker hscientific hoverflow

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (68)
More program dependencies (35)
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 52 entries
Technical checking records
Local closure summary
{
  "node": "NumberHelperSharpPartialExecution",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "f46e42ee0953954695653c774aa956ec7ca74f887b2bc1df8dc4416a03ffbf32",
  "active_statement_hash": "00a2b48127865c9c59b168dae8584ad2c0814e28f22e86479237834846a2951c",
  "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-111",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "NumberHelperPartialExponentOverflowPropagation": "637a760c5072d6a4",
    "NumberHelperSharpFractionalPrefix": "614449139419466e"
  },
  "strict_definition_deps": {
    "Preamble": "965f15fc36f80938",
    "SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from": "7e7284dc9bc88830",
    "num_imp_dec2flt_decimal_Decimal": "c43614ff2149ecf2",
    "num_imp_dec2flt_parse_parse_partial_number": "94ed7b2ff71604ef",
    "num_imp_dec2flt_parse_parse_scientific": "447f722d5841d2c5",
    "num_imp_dec2flt_parse_try_parse_digits": "238b4a73cd46fc56"
  }
}
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:c94631aa1604f16f4ab8264703657b2e98973e85199305afb4d1fa10484a7577",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}