Lean library · module TopologyByExample.Slices.SparseDecision

Classification from sparse witness and candidate families

Source file

The algorithm searches two finite families. A witness identifies a realised row; a refutation excludes a row from the candidate cover. An unresolved result only means that the supplied candidate has no witness in the supplied family, not that its realisability is an open question in the literature.

This file was written by Codex (OpenAI's AI model) working under the direction of David R. MacIver, who reviews it and is responsible for it.

Imports

inductive type Outcome

TopologyByExample.Slices.Sparse.Outcome

A verified witness, an unclassified candidate, or a refuted row.

inductive Outcome (m k : Nat) where
  /-- An index in the supplied witness family. -/
  | witness (i : Fin m)
  /-- An index in the candidate family, without a listed witness. -/
  | unresolved (i : Fin k)
  /-- A row outside the candidate cover. -/
  | refuted
  deriving DecidableEq

definition classify

TopologyByExample.Slices.Sparse.classify

Search only the witness and candidate families, not the full Boolean cube.

def classify {n m k : Nat} (w : Fin m → Row n) (c : Fin k → Row n) (r : Row n) : Outcome m k
Definition
:=
  match Fin.find? (fun i ↦ decide (w i = r)) with
  | some i => .witness i
  | none => match Fin.find? (fun i ↦ decide (c i = r)) with
    | some i => .unresolved i
    | none => .refuted

definition Correct

TopologyByExample.Slices.Sparse.Outcome.Correct

Meaning of the classification, relative to a set of realised rows.

def Outcome.Correct {n m k : Nat} (S : Set (Row n)) (w : Fin m → Row n)
    (c : Fin k → Row n) (r : Row n) : Outcome m k → Prop
  | .witness i => w i = r ∧ r ∈ S
  | .unresolved i => c i = r ∧ ¬ ∃ j, w j = r
  | .refuted => r ∉ S

theorem classify_correct

TopologyByExample.Slices.Sparse.classify_correct

Valid witnesses and a candidate cover make every classification sound.

theorem classify_correct {n m k : Nat} (S : Set (Row n)) (w : Fin m → Row n)
    (c : Fin k → Row n) (hw : ∀ i, w i ∈ S) (hc : ∀ r ∈ S, ∃ i, r = c i) (r : Row n) :
    Outcome.Correct S w c r (classify w c r)
Proof
:= by
  by_cases h : ∃ i, w i = r
  · simp only [classify, Fin.find?_eq_dite, decide_eq_true_eq, h, dite_true]
    exact ⟨Fin.find_spec h, (Fin.find_spec h) ▸ hw _⟩
  · by_cases h' : ∃ i, c i = r
    · simp only [classify, Fin.find?_eq_dite, decide_eq_true_eq, h, h', dite_false, dite_true]
      exact ⟨Fin.find_spec h', h⟩
    · simp only [classify, Fin.find?_eq_dite, decide_eq_true_eq, h, h', dite_false]
      intro hr
      obtain ⟨i, hi⟩ := hc r hr
      exact h' ⟨i, hi.symm⟩

check

example : classify (fun _ : Fin 1 ↦ fun _ : Fin 2 ↦ false)
    (fun _ : Fin 1 ↦ fun _ : Fin 2 ↦ false) (fun _ ↦ false) = .witness 0
Proof
:= by decide +kernel

check

example : classify (fun i : Fin 0 ↦ Fin.elim0 i)
    (fun _ : Fin 1 ↦ fun _ : Fin 2 ↦ false) (fun _ ↦ false) = .unresolved 0
Proof
:= by decide +kernel

check

example : classify (fun i : Fin 0 ↦ Fin.elim0 i)
    (fun i : Fin 0 ↦ Fin.elim0 i) (fun _ : Fin 2 ↦ false) = .refuted
Proof
:= by decide +kernel