P435_T1_ByteValueBlocks

Lean checked

Statement

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

Lemma · Unique lifting of byte-value blocks

Let B be a list of U8 bytes and let P,Q be lists of natural numbers. If \operatorname{map}(b\mapsto b.\mathit{val},B)=P\mathbin{++}Q, there is a pair of byte lists (I,T) such that B=I\mathbin{++}T, their value maps are respectively P,Q, and any byte lists with those two value maps equal I,T, respectively.

Lean statement

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

import Tablet.Preamble

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P435_T1_ByteValueBlocks]
theorem P435_T1_ByteValueBlocks (bytes : List Std.U8) (preValues suffix : List Nat)
    (hmap : bytes.map (fun b => b.val) = preValues ++ suffix) :
    exists unique : List Std.U8 × List Std.U8,
      bytes = unique.1 ++ unique.2 /\
      unique.1.map (fun b => b.val) = preValues /\
      unique.2.map (fun b => b.val) = suffix /\
      (forall first second : List Std.U8,
        first.map (fun b => b.val) = preValues ->
        second.map (fun b => b.val) = suffix ->
        first = unique.1 /\ second = unique.2) := 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

A U8 scalar is determined by its natural value. Consequently equal value maps imply equal byte lists: induct on the first list, exclude an empty/nonempty mismatch by the map equality, equate the two head values and hence the two heads, and apply induction to the tails. To construct the blocks, induct on P. If P=[], take I=[] and T=B. If P=p::P', the equality forces B=b::B' with b.\mathit{val}=p and the value map of B' equal to P'++Q. Apply induction to B', and prepend b to its first block. This proves the concatenation and both map equations. Finally compare any proposed first block with I, and any proposed second block with T, using the value-map injectivity proved above. No bound or alphabet condition on P,Q is assumed: their realizability follows from the given equality to an actual byte list.

Lean proof


  have injective : forall first second : List Std.U8,
      first.map (fun b => b.val) = second.map (fun b => b.val) -> first = second := by
    intro first
    induction first with
    | nil =>
      intro second h
      cases second <;> simp_all
    | cons b first ih =>
      intro second h
      cases second with
      | nil => simp at h
      | cons c second =>
        simp only [List.map_cons, List.cons.injEq] at h
        have hbc : b = c := UScalar.eq_of_val_eq h.1
        exact congrArg₂ List.cons hbc (ih second h.2)
  have split : forall (pre post : List Nat) (bs : List Std.U8),
      bs.map (fun b => b.val) = pre ++ post ->
      exists first second : List Std.U8,
        bs = first ++ second /\ first.map (fun b => b.val) = pre /\
          second.map (fun b => b.val) = post := by
    intro pre
    induction pre with
    | nil =>
      intro post bs h
      exact ⟨[], bs, by simp, rfl, by simpa using h⟩
    | cons value pre ih =>
      intro post bs h
      cases bs with
      | nil => simp at h
      | cons b bs =>
        simp only [List.map_cons, List.cons_append, List.cons.injEq] at h
        obtain ⟨first, second, hsplit, hfirst, hsecond⟩ := ih post bs h.2
        exact ⟨b :: first, second, by simp [hsplit], by simp [h.1, hfirst], hsecond⟩
  obtain ⟨first, second, hsplit, hfirst, hsecond⟩ := split preValues suffix bytes hmap
  refine ⟨(first, second), hsplit, hfirst, hsecond, ?_⟩
  intro first' second' hfirst' hsecond'
  exact ⟨injective first' first (hfirst'.trans hfirst.symm),
    injective second' second (hsecond'.trans hsecond.symm)⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.Preamble

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P435_T1_ByteValueBlocks]
theorem P435_T1_ByteValueBlocks (bytes : List Std.U8) (preValues suffix : List Nat)
    (hmap : bytes.map (fun b => b.val) = preValues ++ suffix) :
    exists unique : List Std.U8 × List Std.U8,
      bytes = unique.1 ++ unique.2 /\
      unique.1.map (fun b => b.val) = preValues /\
      unique.2.map (fun b => b.val) = suffix /\
      (forall first second : List Std.U8,
        first.map (fun b => b.val) = preValues ->
        second.map (fun b => b.val) = suffix ->
        first = unique.1 /\ second = unique.2) := by
-- BODY
  have injective : forall first second : List Std.U8,
      first.map (fun b => b.val) = second.map (fun b => b.val) -> first = second := by
    intro first
    induction first with
    | nil =>
      intro second h
      cases second <;> simp_all
    | cons b first ih =>
      intro second h
      cases second with
      | nil => simp at h
      | cons c second =>
        simp only [List.map_cons, List.cons.injEq] at h
        have hbc : b = c := UScalar.eq_of_val_eq h.1
        exact congrArg₂ List.cons hbc (ih second h.2)
  have split : forall (pre post : List Nat) (bs : List Std.U8),
      bs.map (fun b => b.val) = pre ++ post ->
      exists first second : List Std.U8,
        bs = first ++ second /\ first.map (fun b => b.val) = pre /\
          second.map (fun b => b.val) = post := by
    intro pre
    induction pre with
    | nil =>
      intro post bs h
      exact ⟨[], bs, by simp, rfl, by simpa using h⟩
    | cons value pre ih =>
      intro post bs h
      cases bs with
      | nil => simp at h
      | cons b bs =>
        simp only [List.map_cons, List.cons_append, List.cons.injEq] at h
        obtain ⟨first, second, hsplit, hfirst, hsecond⟩ := ih post bs h.2
        exact ⟨b :: first, second, by simp [hsplit], by simp [h.1, hfirst], hsecond⟩
  obtain ⟨first, second, hsplit, hfirst, hsecond⟩ := split preValues suffix bytes hmap
  refine ⟨(first, second), hsplit, hfirst, hsecond, ?_⟩
  intro first' second' hfirst' hsecond'
  exact ⟨injective first' first (hfirst'.trans hfirst.symm),
    injective second' second (hsecond'.trans hsecond.symm)⟩

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": "P435_T1_ByteValueBlocks",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "de8b75aabe4653a645419eb23d46c0c92d586065f2152a44b6cf45141d18174a",
  "active_statement_hash": "3aef053ad11f31682f369fdc62227525f34314dfee0b52a48d57242498ada86c",
  "kernel_axioms": [
    "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-92",
  "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:258c2da9eb8228fd6f7e90a7376368f22bbaf045dd1603d9756eab212c91566a",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}