NumberHelperScientificRenderedSuffixSafeLength

Lean checked

Statement

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

Lemma · Scientific parsing from rendered digit values

Let an Aeneas byte slice have byte values equal to the standard rendering of an optional exponent sign followed by a nonempty list of decimal digits. If every digit is below ten, then parse_scientific consumes the whole slice and returns an exponent in ([-5764607523034234879,5764607523034234879]). When at most five digits are rendered, the returned exponent lies in the sharper interval ([-99999,99999]). Unless the optional sign is a minus sign, the exponent is nonnegative.

Lean statement

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

import Tablet.NumberHelperScientificPrefixSafeLength
import Tablet.NumberHelperSplitExponentSuffix

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperScientificRenderedSuffixSafeLength]
theorem NumberHelperScientificRenderedSuffixSafeLength (s : Slice Std.U8)
    (sign : Option Bool) (digits : List Nat)
    (hne : digits != [])
    (hdigits : forall d, List.Mem d digits -> d < 10)
    (hs : List.map (fun b : Std.U8 => b.val) s.val =
      (match sign with
      | none => []
      | some negative => [if negative then 45 else 43]) ++
        List.map (fun d : Nat => 48 + d) digits) :
    exists (exponent : Std.I64) (rest : Slice Std.U8),
      num.imp.dec2flt.parse.parse_scientific s = ok (some exponent, rest) /\
      rest.val = [] /\
      -5764607523034234879 <= exponent.val /\ exponent.val <= 5764607523034234879 /\
      (digits.length <= 5 ->
        -99999 <= exponent.val /\ exponent.val <= 99999) /\
      (sign ≠ some true -> 0 <= exponent.val) := 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 NumberHelperSplitExponentSuffix to the assumed byte-value equality. It produces the exact optional ASCII sign prefix and a byte list whose values are the rendered digit values. Every such byte has value (48+d) for a stated digit (d<10), so it lies from 48 through 57. The digit-byte list is nonempty because equality of its mapped length with the nonempty source digit list rules out the empty list; the same length equality shows that the two digit counts coincide.
Apply NumberHelperScientificPrefixSafeLength once to this exact byte decomposition with an empty tail. The digit-byte list is nonempty and consists of decimal bytes, and the empty tail has no first byte, so its nondigit condition is vacuous. The theorem returns one exponent and residual slice together with the coarse interval, short-list refinement, and nonnegativity unless the sign is minus. Its exact residual-tail equality gives complete consumption. Transporting the established digit-list length equality makes the short-list refinement apply whenever the original natural digit list has length at most five. Thus the same returned exponent satisfies all three bounds and sign claims without any additional length restriction.

Lean proof


  obtain ⟨digitBytes, hsval, hmap⟩ :=
    NumberHelperSplitExponentSuffix sign s.val digits hs
  have hbyteDigits : forall b, List.Mem b digitBytes ->
      48 <= b.val /\ b.val <= 57 := by
    intro b hb
    have hbmap : b.val ∈ List.map (fun c : Std.U8 => c.val) digitBytes :=
      List.mem_map_of_mem hb
    rw [hmap] at hbmap
    obtain ⟨d, hd, hdval⟩ := List.mem_map.mp hbmap
    have hdlt := hdigits d hd
    omega
  have hbytesNe : digitBytes != [] := by
    simp only [bne_iff_ne]
    intro hnil
    subst digitBytes
    cases digits with
    | nil => simp at hne
    | cons d ds => simp at hmap
  have hlength : digitBytes.length = digits.length := by
    have := congrArg List.length hmap
    simpa using this
  obtain ⟨exponent, rest, hparse, hrest, hlo, hhi, hshort, hnonnegative⟩ :=
    NumberHelperScientificPrefixSafeLength s sign digitBytes [] hbytesNe
      hbyteDigits (by simp) (by cases sign <;> simpa using hsval)
  exact ⟨exponent, rest, hparse, hrest, hlo, hhi,
    fun h => hshort (by simpa [hlength] using h), hnonnegative⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.NumberHelperScientificPrefixSafeLength
import Tablet.NumberHelperSplitExponentSuffix

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperScientificRenderedSuffixSafeLength]
theorem NumberHelperScientificRenderedSuffixSafeLength (s : Slice Std.U8)
    (sign : Option Bool) (digits : List Nat)
    (hne : digits != [])
    (hdigits : forall d, List.Mem d digits -> d < 10)
    (hs : List.map (fun b : Std.U8 => b.val) s.val =
      (match sign with
      | none => []
      | some negative => [if negative then 45 else 43]) ++
        List.map (fun d : Nat => 48 + d) digits) :
    exists (exponent : Std.I64) (rest : Slice Std.U8),
      num.imp.dec2flt.parse.parse_scientific s = ok (some exponent, rest) /\
      rest.val = [] /\
      -5764607523034234879 <= exponent.val /\ exponent.val <= 5764607523034234879 /\
      (digits.length <= 5 ->
        -99999 <= exponent.val /\ exponent.val <= 99999) /\
      (sign ≠ some true -> 0 <= exponent.val) := by
-- BODY
  obtain ⟨digitBytes, hsval, hmap⟩ :=
    NumberHelperSplitExponentSuffix sign s.val digits hs
  have hbyteDigits : forall b, List.Mem b digitBytes ->
      48 <= b.val /\ b.val <= 57 := by
    intro b hb
    have hbmap : b.val ∈ List.map (fun c : Std.U8 => c.val) digitBytes :=
      List.mem_map_of_mem hb
    rw [hmap] at hbmap
    obtain ⟨d, hd, hdval⟩ := List.mem_map.mp hbmap
    have hdlt := hdigits d hd
    omega
  have hbytesNe : digitBytes != [] := by
    simp only [bne_iff_ne]
    intro hnil
    subst digitBytes
    cases digits with
    | nil => simp at hne
    | cons d ds => simp at hmap
  have hlength : digitBytes.length = digits.length := by
    have := congrArg List.length hmap
    simpa using this
  obtain ⟨exponent, rest, hparse, hrest, hlo, hhi, hshort, hnonnegative⟩ :=
    NumberHelperScientificPrefixSafeLength s sign digitBytes [] hbytesNe
      hbyteDigits (by simp) (by cases sign <;> simpa using hsval)
  exact ⟨exponent, rest, hparse, hrest, hlo, hhi,
    fun h => hshort (by simpa [hlength] using h), hnonnegative⟩

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": "NumberHelperScientificRenderedSuffixSafeLength",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "8612ecac399c94234462e2ec31eac12c5e5fff20b6ac5967bb5bd8d12c21fd06",
  "active_statement_hash": "c8262c5dd6b71fff8b22fef4850ac07c8c47c310e3b53b18145c2110f9c03689",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "576e6bf9480cfd32f53c309c7ac8fb115c1ba6e413f299ed5ff9fa7c647e6769",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-181",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "NumberHelperScientificPrefixSafeLength": "2081afb9bfe32845",
    "NumberHelperSplitExponentSuffix": "36f92cf2e9d9f766"
  },
  "strict_definition_deps": {
    "NumberHelperScientificPrefixSafeLength": "28ca0a8ac503ee01",
    "NumberHelperSplitExponentSuffix": "3a789d080d66f335",
    "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:d756c5d13acd1f57b6e89d539f5ca44aea2146d28f9fb25554dedd66eb1ff2e8",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}