AFTD Auto-Formalizing Theoretical Domains

SATtoColor.SATtoColorCompleteness

theoremverifiedimported Lean

Completeness of the 3-SAT to 3-coloring reduction. Let $f$ be a 3-SAT instance over a variable type $V$, that is, a list of clauses, each a disjunction of three literals. If $f$ is satisfiable — there exists a Boolean assignment $\mathrm{assign} : V \to \mathrm{Bool}$ under which every clause of $f$ has at least one true literal — then the reduction graph $\mathrm{ReductionGraph}(f)$ is 3-colorable, i.e.\ it admits a proper coloring by the three colors $\mathrm{Fin}\,3$.

Statement

set_option relaxedAutoImplicit false in
set_option autoImplicit false in
lemma SATtoColor.SATtoColorCompleteness {V : Type} (f : Sat3 V) :
  IsSatisfiable f → Is3Colorable (ReductionGraph f)
Source
TCSlib, `SATtoColor.SATtoColorCompleteness`
Lean proof
By CS 294-268 course staff (UC Berkeley, Spring 2026), from github.com/Shilun-Allan-Li/tcslib at c8a02591b1e5 (Copyright (c) 2026 UC Berkeley CS 294. All rights reserved, Apache-2.0). Compiled here against leanprover/lean4:v4.33.1, Mathlib v4.33.1; written for leanprover/lean4:v4.25.0.
Verified
07 Oct 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 14
  • SATtoColor.EdgeRelation$\mathrm{EdgeRelation}(f, u, v)$ defines the (undirected) adjacency structure of the reduction graph. The edges are: all pairs of distinct…
  • SATtoColor.sat3Coloring_litNodeColor of a literal node. Fix a variable type $V$ and a Boolean assignment $\alpha : V \to \{\text{true}, \text{false}\}$, and consider the…
  • SATtoColor.OutputVertexThe vertex set of the reduction graph is the inductive type $\mathrm{OutputVertex}(V)$ with three constructors:
    •…
  • SATtoColor.IsSatisfiableA 3-SAT instance $f$ is satisfiable if there exists a Boolean assignment that satisfies it:…
  • SATtoColor.LiteralA literal for switching-lemma formulas: a variable $\mathtt{var} : \mathrm{Fin}\,n$ with a negation flag $\mathtt{neg} : \mathrm{Bool}$…
  • SATtoColor.Is3ColorableA simple graph $G$ on vertex type $V'$ is 3-colorable if there exists a proper graph coloring with colors $\mathrm{Fin}\,3$, i.e.\…
  • SATtoColor.SatisfiesClauseUnder assignment $\mathrm{assign}$, a clause $c$ is satisfied if at least one of its three literals evaluates to true:…
  • SATtoColor.SatisfiesLiteralGiven a Boolean assignment $\mathrm{assign} : V \to \mathrm{Bool}$, the function $\texttt{SATtoColor.SatisfiesLiteral}$ evaluates a…
  • SATtoColor.ClauseA clause over a variable type $V$ is a structure bundling exactly three literals $\ell_1, \ell_2, \ell_3 : \mathrm{Literal}\,V$.…
  • SATtoColor.ReductionGraphGiven a 3-SAT instance $f$ over variables $V$, the reduction graph $\mathrm{ReductionGraph}(f)$ is the SimpleGraph on…
  • SATtoColor.Sat3A 3-SAT instance over variable type $V$ is defined as a list of clauses, i.e.\ $\mathrm{Sat3}(V) := \mathrm{List}(\mathrm{Clause}\,V)$.
  • SATtoColor.clauseGadgetColorGiven the Boolean truth values $a, b, c_3$ of the three literals of a clause, $\mathrm{clauseGadgetColor}(a, b, c_3, k)$ assigns a color…
  • SATtoColor.sat3ColoringGiven a satisfying assignment $\mathrm{assign} : V \to \mathrm{Bool}$, the function $\mathrm{sat3Coloring}(\mathrm{assign})$ maps every…
  • SATtoColor.SatisfiesSat3An assignment $\mathrm{assign}$ satisfies a 3-SAT instance $f$ if every clause in the list $f$ is satisfied by $\mathrm{assign}$,…
Used by 2
  • SATtoColor.SATtoColorReductionCorrectness of the 3-SAT to 3-coloring reduction. Let $f$ be a 3-SAT instance over a variable type $V$: a list of clauses, each clause an…
  • SATtoColor.SATtoColorSoundnessSoundness of the 3-SAT to 3-colouring reduction. Let $f$ be a 3-SAT instance over a variable type $V$, that is, a list of clauses, each…

Lean source view module on GitHub

Lean’s trace was cut to the first 400 of 424 tactics.

set_option relaxedAutoImplicit false inset_option autoImplicit false in/-- Completeness of reduction from 3-SAT to 3-Coloring. -/lemma SATtoColor.SATtoColorCompleteness {V : Type} (f : Sat3 V) :  IsSatisfiable f → Is3Colorable (ReductionGraph f) := by  intro ⟨assign, hsat⟩  refine ⟨⟨sat3Coloring assign, ?_⟩⟩  intro u v hadj  simp only [SimpleGraph.top_adj]  obtain ⟨hne, hedge⟩ := hadj  suffices key : ∀ {a b : OutputVertex V}, EdgeRelation f a b →                   sat3Coloring assign a ≠ sat3Coloring assign b by    rcases hedge with h | h    · exact key h    · exact fun heq => key h heq.symm  intro a b h  cases a with  | palette i =>    cases b with    | palette j =>      simp only [sat3Coloring]      simp only [EdgeRelation] at h      exact h    | literalNode l =>      fin_cases i      · rw [sat3Coloring_litNode]; simp only [sat3Coloring]        cases SatisfiesLiteral assign l <;> simp      · exact absurd h (by simp [EdgeRelation])      · exact absurd h (by simp [EdgeRelation])    | clauseGadget c k =>      fin_cases i <;> fin_cases k <;>        simp_all [EdgeRelation, sat3Coloring, clauseGadgetColor]  | literalNode l =>    cases b with    | palette j =>      fin_cases j      · rw [sat3Coloring_litNode]; simp only [sat3Coloring]        cases SatisfiesLiteral assign l <;> simp      · exact absurd h (by simp [EdgeRelation])      · exact absurd h (by simp [EdgeRelation])    | literalNode l2 =>      cases l with      | pos x =>        cases l2 with        | pos y => exact absurd h (by simp [EdgeRelation])        | neg y =>          simp only [EdgeRelation] at h          simp only [sat3Coloring]; subst h          cases assign x <;> simp      | neg x =>        cases l2 with        | neg y => exact absurd h (by simp [EdgeRelation])        | pos y =>          simp only [EdgeRelation] at h          simp only [sat3Coloring]; subst h          cases assign x <;> simp    | clauseGadget c k =>      simp only [EdgeRelation] at h      rcases h with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩      all_goals (        rw [sat3Coloring_litNode]; simp only [sat3Coloring]        cases hA : SatisfiesLiteral assign c.l1 <;>        cases hB : SatisfiesLiteral assign c.l2 <;>        cases hC : SatisfiesLiteral assign c.l3 <;>        simp [clauseGadgetColor])  | clauseGadget c k =>    cases b with    | palette j =>      fin_cases j <;> fin_cases k <;>        simp_all [EdgeRelation, sat3Coloring, clauseGadgetColor]    | literalNode l =>      simp only [EdgeRelation] at h      rcases h with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩      all_goals (        rw [sat3Coloring_litNode]; simp only [sat3Coloring]        cases hA : SatisfiesLiteral assign c.l1 <;>        cases hB : SatisfiesLiteral assign c.l2 <;>        cases hC : SatisfiesLiteral assign c.l3 <;>        simp [clauseGadgetColor])    | clauseGadget c2 j =>      simp only [EdgeRelation] at h      obtain ⟨rfl, hcIn, hidx⟩ := h      simp only [sat3Coloring]      have hClauseTrue : SatisfiesClause assign c = true :=        List.all_eq_true.mp hsat c hcIn      rcases hidx with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ |                       ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ |                       ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ |                       ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩      all_goals (        cases hA : SatisfiesLiteral assign c.l1 <;>        cases hB : SatisfiesLiteral assign c.l2 <;>        cases hC : SatisfiesLiteral assign c.l3 <;>        simp_all [clauseGadgetColor, SatisfiesClause])
See it in the graphDiscuss this resultChallenge it