NumberHelperScientificSuffixSharpSafeLength

Lean checked

Statement

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

Lemma · Sharp short scientific-suffix bound

Let a byte slice of length at most (9223372036854120458) consist exactly of an optional ASCII plus or minus sign followed by a nonempty list of ASCII decimal digit bytes. The extracted parse_scientific call returns Some of an exponent, consumes the complete slice, and returns an exponent in ([-655359,655359]). If the digit list has length at most five, the sharper interval ([-99999,99999]) also holds.

Lean statement

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

import Tablet.NumberHelperScientificShortSuffixSafeLength
import Tablet.NumberHelperScientificSuffixSafeLength

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperScientificSuffixSharpSafeLength]
theorem NumberHelperScientificSuffixSharpSafeLength (s : Slice Std.U8)
    (sign : Option Bool) (digits : List Std.U8)
    (hne : digits != [])
    (hdigits : forall b, List.Mem b digits -> 48 <= b.val /\ b.val <= 57)
    (hs : s.val =
      (match sign with
      | none => []
      | some negative => [if negative then 45#u8 else 43#u8]) ++ digits)
    (hlen : s.val.length <= 9223372036854120458) :
    exists (exponent : Std.I64) (rest : Slice Std.U8),
      num.imp.dec2flt.parse.parse_scientific s = ok (some exponent, rest) /\
      rest.val = [] /\
      -655359 <= exponent.val /\ exponent.val <= 655359 /\
      (digits.length <= 5 ->
        -99999 <= exponent.val /\ exponent.val <= 99999) := 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

Split on whether the digit-list length is at most five. In the short case, NumberHelperScientificShortSuffixSafeLength gives exact complete consumption and the interval ([-99999,99999]); both endpoints lie inside the required coarse interval ([-655359,655359]). In the remaining case, NumberHelperScientificSuffixSafeLength gives exact complete consumption and the coarse interval directly. The conditional sharp claim then has a false antecedent. These two cases establish every conjunct of the statement.

Lean proof


  by_cases hshort : digits.length <= 5
  · obtain ⟨exponent, rest, hparse, hrest, hlo, hhi⟩ :=
      NumberHelperScientificShortSuffixSafeLength s sign digits hne hdigits hs hshort
    exact ⟨exponent, rest, hparse, hrest, by omega, by omega,
      fun _ => ⟨hlo, hhi⟩⟩
  · obtain ⟨exponent, rest, hparse, hrest, hlo, hhi⟩ :=
      NumberHelperScientificSuffixSafeLength s sign digits hne hdigits hs hlen
    exact ⟨exponent, rest, hparse, hrest, hlo, hhi, fun h => False.elim (hshort h)⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.NumberHelperScientificShortSuffixSafeLength
import Tablet.NumberHelperScientificSuffixSafeLength

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperScientificSuffixSharpSafeLength]
theorem NumberHelperScientificSuffixSharpSafeLength (s : Slice Std.U8)
    (sign : Option Bool) (digits : List Std.U8)
    (hne : digits != [])
    (hdigits : forall b, List.Mem b digits -> 48 <= b.val /\ b.val <= 57)
    (hs : s.val =
      (match sign with
      | none => []
      | some negative => [if negative then 45#u8 else 43#u8]) ++ digits)
    (hlen : s.val.length <= 9223372036854120458) :
    exists (exponent : Std.I64) (rest : Slice Std.U8),
      num.imp.dec2flt.parse.parse_scientific s = ok (some exponent, rest) /\
      rest.val = [] /\
      -655359 <= exponent.val /\ exponent.val <= 655359 /\
      (digits.length <= 5 ->
        -99999 <= exponent.val /\ exponent.val <= 99999) := by
-- BODY
  by_cases hshort : digits.length <= 5
  · obtain ⟨exponent, rest, hparse, hrest, hlo, hhi⟩ :=
      NumberHelperScientificShortSuffixSafeLength s sign digits hne hdigits hs hshort
    exact ⟨exponent, rest, hparse, hrest, by omega, by omega,
      fun _ => ⟨hlo, hhi⟩⟩
  · obtain ⟨exponent, rest, hparse, hrest, hlo, hhi⟩ :=
      NumberHelperScientificSuffixSafeLength s sign digits hne hdigits hs hlen
    exact ⟨exponent, rest, hparse, hrest, hlo, hhi, fun h => False.elim (hshort h)⟩

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 33 entries
Technical checking records
Local closure summary
{
  "node": "NumberHelperScientificSuffixSharpSafeLength",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "96081adb007ac43d6cdd45bebd400b0cfb65feb42e6bfa94090d3bdd733f9044",
  "active_statement_hash": "35cce17dcda6b444a0243744f9db497be4596a534c173c505321c8b97e129b9a",
  "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-109",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "NumberHelperScientificShortSuffixSafeLength": "d4007e9e2476cce7",
    "NumberHelperScientificSuffixSafeLength": "bac5584cec53e203"
  },
  "strict_definition_deps": {
    "num_imp_dec2flt_parse_parse_scientific": "447f722d5841d2c5"
  }
}
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:7584fd00b5ef59f49b7f3932a8fcc806d4741824c2dc64fd221eca0d1752f91b",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}