NumberHelperSplitExponentSuffix

Lean checked

Statement

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

Lemma · Exact exponent-suffix byte decomposition

Let d_1,\ldots,d_k be an arbitrary finite list of natural numbers, possibly empty. Suppose mapping an unsigned-byte list to its numeric byte values gives an optional sign value (45 when its Boolean is true and 43 when it is false), followed by 48+d_1,\ldots,48+d_k. Then the byte list itself is the corresponding optional ASCII sign byte followed by a byte list whose numeric values are exactly 48+d_1,\ldots,48+d_k.

Lean statement

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

import Tablet.DecimalGoalVocabularyDefault

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperSplitExponentSuffix]
theorem NumberHelperSplitExponentSuffix (sign : Option Bool)
    (suffix : List Std.U8) (digits : List Nat)
    (hmap : List.map (fun b : Std.U8 => b.val) suffix =
      (match sign with
      | none => []
      | some negative => [if negative then 45 else 43]) ++
        List.map (fun d : Nat => 48 + d) digits) :
    exists digitBytes : List Std.U8,
      suffix =
        (match sign with
        | none => []
        | some negative => [if negative then 45#u8 else 43#u8]) ++
          digitBytes /\
      List.map (fun b : Std.U8 => b.val) digitBytes =
        List.map (fun d : Nat => 48 + d) digits := 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 the optional sign. With no sign, the assumed map equality already has the required form, so take the whole suffix as the remaining byte list. With a sign, split further on its Boolean value. The map equality begins with 43 in the nonnegative case and 45 in the negative case. The list map/cons decomposition therefore supplies a first byte with that value and a remaining list with exactly the map of the values 48+d_i. Unsigned bytes are determined by their numeric values, so the first byte is respectively the ASCII plus byte (43) or minus byte (45). The remaining list is the required byte list in both cases. No upper bound such as d_i\leq9 on the natural entries is used.

Lean proof


  cases sign with
  | none =>
    simp only [List.nil_append] at hmap ⊢
    exact ⟨suffix, rfl, hmap⟩
  | some negative =>
    cases negative <;> simp at hmap ⊢
    · obtain ⟨b, bs, hsuffix, hb, htail⟩ :=
        List.map_eq_cons_iff.mp hmap
      have hb' : b = 43#u8 := by
        apply UScalar.eq_of_val_eq
        simpa using hb
      subst b
      exact ⟨bs, hsuffix, htail⟩
    · obtain ⟨b, bs, hsuffix, hb, htail⟩ :=
        List.map_eq_cons_iff.mp hmap
      have hb' : b = 45#u8 := by
        apply UScalar.eq_of_val_eq
        simpa using hb
      subst b
      exact ⟨bs, hsuffix, htail⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperSplitExponentSuffix]
theorem NumberHelperSplitExponentSuffix (sign : Option Bool)
    (suffix : List Std.U8) (digits : List Nat)
    (hmap : List.map (fun b : Std.U8 => b.val) suffix =
      (match sign with
      | none => []
      | some negative => [if negative then 45 else 43]) ++
        List.map (fun d : Nat => 48 + d) digits) :
    exists digitBytes : List Std.U8,
      suffix =
        (match sign with
        | none => []
        | some negative => [if negative then 45#u8 else 43#u8]) ++
          digitBytes /\
      List.map (fun b : Std.U8 => b.val) digitBytes =
        List.map (fun d : Nat => 48 + d) digits := by
-- BODY
  cases sign with
  | none =>
    simp only [List.nil_append] at hmap ⊢
    exact ⟨suffix, rfl, hmap⟩
  | some negative =>
    cases negative <;> simp at hmap ⊢
    · obtain ⟨b, bs, hsuffix, hb, htail⟩ :=
        List.map_eq_cons_iff.mp hmap
      have hb' : b = 43#u8 := by
        apply UScalar.eq_of_val_eq
        simpa using hb
      subst b
      exact ⟨bs, hsuffix, htail⟩
    · obtain ⟨b, bs, hsuffix, hb, htail⟩ :=
        List.map_eq_cons_iff.mp hmap
      have hb' : b = 45#u8 := by
        apply UScalar.eq_of_val_eq
        simpa using hb
      subst b
      exact ⟨bs, hsuffix, htail⟩

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (44)
More program dependencies (11)
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
Technical checking records
Local closure summary
{
  "node": "NumberHelperSplitExponentSuffix",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "c5f9e8815a8f79ac98b73531919a2a5898bbcb3bb5a1dc7b6ac1ba164d1fd4dd",
  "active_statement_hash": "c391800617ff68bb6d4434c010eb2c12a1de6edbfbdec3dc85f9931115f98e83",
  "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-110",
  "boundary_theorems": {},
  "strict_theorem_deps": {},
  "strict_definition_deps": {}
}
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:99a083867eb0b6ca93609285715d07ec237cdcd73df6e939afa07503706c144d",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}