P435_T1_DigitPrefixUnique

Lean checked

Statement

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

Lemma · Uniqueness of a maximal decimal-byte prefix

Suppose D++T=D'++T' are byte-list decompositions. All members of D,D' have values in [48,57], and each of T,T' is empty or has a head whose value is outside [48,57]. Then D=D' and T=T'.

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_DigitPrefixUnique]
theorem P435_T1_DigitPrefixUnique (digits tail digits' tail' : List Std.U8)
    (hsplit : digits ++ tail = digits' ++ tail')
    (hdigits : forall b, b ∈ digits -> 48 <= b.val /\ b.val <= 57)
    (htail : forall b rest, tail = b :: rest -> ¬ (48 <= b.val /\ b.val <= 57))
    (hdigits' : forall b, b ∈ digits' -> 48 <= b.val /\ b.val <= 57)
    (htail' : forall b rest, tail' = b :: rest -> ¬ (48 <= b.val /\ b.val <= 57)) :
    digits = digits' /\ tail = tail' := 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

Induct on D, allowing D' to vary. If both prefixes are empty, their tails are equal by the concatenation equality. If exactly one prefix is empty, the head of the nonempty digit prefix is also the head of the other tail. It is a digit by the prefix hypothesis and a nondigit by the tail hypothesis, a contradiction. If both prefixes are nonempty, equality of concatenations equates their heads and leaves equality of the tail concatenations. The remaining prefix members still satisfy the digit hypotheses, and the two final tails retain their nondigit-head hypotheses. Induction equates both remaining prefixes and both final tails; restoring the common head proves the claim.

Lean proof


  induction digits generalizing digits' with
  | nil =>
    cases digits' with
    | nil => exact ⟨rfl, by simpa using hsplit⟩
    | cons b bs =>
      have htailEq : tail = b :: (bs ++ tail') := by simpa using hsplit
      exact False.elim (htail b (bs ++ tail') htailEq (hdigits' b (by simp)))
  | cons b bs ih =>
    cases digits' with
    | nil =>
      have htailEq : tail' = b :: (bs ++ tail) := by simpa using hsplit.symm
      exact False.elim (htail' b (bs ++ tail) htailEq (hdigits b (by simp)))
    | cons c cs =>
      simp only [List.cons_append, List.cons.injEq] at hsplit
      have hbc := hsplit.1
      subst c
      obtain ⟨hp, ht⟩ := ih cs hsplit.2
        (fun c hc => hdigits c (by simp [hc]))
        (fun c hc => hdigits' c (by simp [hc]))
      exact ⟨congrArg (List.cons b) hp, ht⟩

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_DigitPrefixUnique]
theorem P435_T1_DigitPrefixUnique (digits tail digits' tail' : List Std.U8)
    (hsplit : digits ++ tail = digits' ++ tail')
    (hdigits : forall b, b ∈ digits -> 48 <= b.val /\ b.val <= 57)
    (htail : forall b rest, tail = b :: rest -> ¬ (48 <= b.val /\ b.val <= 57))
    (hdigits' : forall b, b ∈ digits' -> 48 <= b.val /\ b.val <= 57)
    (htail' : forall b rest, tail' = b :: rest -> ¬ (48 <= b.val /\ b.val <= 57)) :
    digits = digits' /\ tail = tail' := by
-- BODY
  induction digits generalizing digits' with
  | nil =>
    cases digits' with
    | nil => exact ⟨rfl, by simpa using hsplit⟩
    | cons b bs =>
      have htailEq : tail = b :: (bs ++ tail') := by simpa using hsplit
      exact False.elim (htail b (bs ++ tail') htailEq (hdigits' b (by simp)))
  | cons b bs ih =>
    cases digits' with
    | nil =>
      have htailEq : tail' = b :: (bs ++ tail) := by simpa using hsplit.symm
      exact False.elim (htail' b (bs ++ tail) htailEq (hdigits b (by simp)))
    | cons c cs =>
      simp only [List.cons_append, List.cons.injEq] at hsplit
      have hbc := hsplit.1
      subst c
      obtain ⟨hp, ht⟩ := ih cs hsplit.2
        (fun c hc => hdigits c (by simp [hc]))
        (fun c hc => hdigits' c (by simp [hc]))
      exact ⟨congrArg (List.cons b) hp, ht⟩

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_DigitPrefixUnique",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "bfe049a66f6b9fbd62de6381bcf14190a2ea87e3f77691cfc9412d7d07c0f80c",
  "active_statement_hash": "9d59140897e8d811436edf6c1cc0a204efa77be8b0259e63a90eae58d64fb0d1",
  "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:9152d66ce671d63038269b7b5a813686758a365514ef21870e063761a0c4860f",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}