Port graphs, independent sets and the formula (three-occurrence Horn class)
DefinitionPalomaMax2SAT_DegreeFormulapaloma-max2sat
Formal model of the three-occurrence Horn formula of a simple -regular graph with a port labelling (PortGraph), its independent sets and independence number, and the number of clauses of satisfied by an assignment (satCount), together with the assignment obtained from an independent set. Definitions and the port-structure bijection used by them, as in Sections 2 and 3 of the paper.
Definition code
-- Generated by skeleton subtraction from the paloma repository: Definitions bundle
import Mathlib
section Bundle_DegreeFormula
/-!
# The degree-`d` formula `T_H` as an explicit MAX-HORN-2SAT instance
For a simple `d`-regular graph `H` with a port labelling, the formula `T_H` has
`d + 1` Boolean clones `(v, 0), …, (v, d)` per vertex `v`: the clone `(v, 0)` occurs in
the unit clause `(¬ (v,0))`, the clones `(v, p+1)` occur in the edge clauses of the
`d` edges at `v`, and the `d + 1` cyclic implications `(¬ (v,i) ∨ (v,i+1))` enforce
consistency. Every clone occurs exactly three times.
This module proves, for every `d`:
* the number of satisfied clauses equals `U(z) + (m - F(z)) + ((d+1) n - T(z))`;
* the optimum equals `(d+1) n + m + α`;
* every clause is Horn, the formula has `(d+2) n + m` clauses, and every variable
occurs exactly three times;
* `2 m = d n` and `2 α ≤ n` follow from the port structure (for `d > 0`);
* the lift of an independent set has value `(d+1) n + m + |I|`, and the arithmetic of
`DegreeTransfer` applies to it.
Lean does not prove that an algorithm attains any independent-set guarantee; those
guarantees are hypotheses of the transfer statements.
-/
namespace PalomaMax2SAT.DegreeFormula
/-- A `d`-regular graph on `n` vertices with `m` edges and a port labelling: every
vertex has exactly one incident edge at each of its `d` ports. -/
structure PortGraph (d n m : ℕ) where
left : Fin m → Fin n
right : Fin m → Fin n
left_ne_right : ∀ e, left e ≠ right e
leftPort : Fin m → Fin d
rightPort : Fin m → Fin d
left_unique : ∀ e f, left e = left f → leftPort e = leftPort f → e = f
right_unique : ∀ e f, right e = right f → rightPort e = rightPort f → e = f
cross_unique : ∀ e f, left e = right f → leftPort e = rightPort f → False
port_occupied : ∀ v : Fin n, ∀ p : Fin d,
(∃ e, left e = v ∧ leftPort e = p) ∨ (∃ e, right e = v ∧ rightPort e = p)
def Independent {d n m : ℕ} (G : PortGraph d n m) (I : Finset (Fin n)) : Prop :=
∀ e, ¬ (G.left e ∈ I ∧ G.right e ∈ I)
def IsIndependenceNumber {d n m : ℕ} (G : PortGraph d n m) (alpha : ℕ) : Prop :=
(∀ I, Independent G I → I.card ≤ alpha) ∧
∃ I, Independent G I ∧ I.card = alpha
/-- The clone of a port: ports `0, …, d-1` use the clones `1, …, d`. -/
def edgeClone {d : ℕ} (p : Fin d) : Fin (d + 1) := p.succ
abbrev transition {n d : ℕ} (z : Fin n → Fin (d + 1) → Bool)
(v : Fin n) (i : Fin (d + 1)) : Prop :=
z v i = true ∧ z v (i + 1) = false
def selectedVertices {n d : ℕ} (z : Fin n → Fin (d + 1) → Bool) : Finset (Fin n) :=
Finset.univ.filter fun v => z v 0 = false
noncomputable def transitionPairs {n d : ℕ} (z : Fin n → Fin (d + 1) → Bool) :
Finset (Fin n × Fin (d + 1)) :=
Finset.univ.filter fun pair => transition z pair.1 pair.2
def falseEdges {d n m : ℕ} (G : PortGraph d n m)
(z : Fin n → Fin (d + 1) → Bool) : Finset (Fin m) :=
Finset.univ.filter fun e =>
z (G.left e) (edgeClone (G.leftPort e)) = false ∧
z (G.right e) (edgeClone (G.rightPort e)) = false
/-- Satisfied unit, edge, and cyclic-consistency clauses. -/
noncomputable def score {d n m : ℕ} (G : PortGraph d n m)
(z : Fin n → Fin (d + 1) → Bool) : ℕ :=
(selectedVertices z).card + (m - (falseEdges G z).card) +
((d + 1) * n - (transitionPairs z).card)
def assignmentOfIndependent {n d : ℕ} (I : Finset (Fin n)) :
Fin n → Fin (d + 1) → Bool :=
fun v _ => if v ∈ I then false else true
/-! ### Port structure: `2 m = d n` and `2 α ≤ n` -/
/-- The port at the given side of an edge. -/
def portOf {d n m : ℕ} (G : PortGraph d n m) : Fin m ⊕ Fin m → Fin n × Fin d
| Sum.inl e => (G.left e, G.leftPort e)
| Sum.inr e => (G.right e, G.rightPort e)
theorem portOf_bijective {d n m : ℕ} (G : PortGraph d n m) :
Function.Bijective (portOf G) := by
constructor
· intro a b hab
rcases a with e | e <;> rcases b with f | f <;>
simp only [portOf, Prod.mk.injEq] at hab
· exact congrArg Sum.inl (G.left_unique e f hab.1 hab.2)
· exact (G.cross_unique e f hab.1 hab.2).elim
· exact (G.cross_unique f e hab.1.symm hab.2.symm).elim
· exact congrArg Sum.inr (G.right_unique e f hab.1 hab.2)
· rintro ⟨v, p⟩
rcases G.port_occupied v p with ⟨e, h1, h2⟩ | ⟨e, h1, h2⟩
· exact ⟨Sum.inl e, by simp [portOf, h1, h2]⟩
· exact ⟨Sum.inr e, by simp [portOf, h1, h2]⟩
noncomputable def portEquiv {d n m : ℕ} (G : PortGraph d n m) :
Fin m ⊕ Fin m ≃ Fin n × Fin d :=
Equiv.ofBijective (portOf G) (portOf_bijective G)
noncomputable def edgeOfPort {d n m : ℕ} (G : PortGraph d n m) (q : Fin n × Fin d) : Fin m :=
Sum.elim id id ((portEquiv G).symm q)
/-! ### The formula as an explicit list of Horn clauses -/
/-- A literal over the clone variables `(v, i)`; `positive = false` is a negated
literal. -/
structure Lit (n d : ℕ) where
var : Fin n × Fin (d + 1)
positive : Bool
/-- A clause is a list of literals. -/
abbrev Clause (n d : ℕ) := List (Lit n d)
def Lit.eval {n d : ℕ} (z : Fin n → Fin (d + 1) → Bool) (l : Lit n d) : Bool :=
if l.positive then z l.var.1 l.var.2 else !z l.var.1 l.var.2
/-- A clause is satisfied when some literal evaluates to true. -/
def Clause.satisfied {n d : ℕ} (z : Fin n → Fin (d + 1) → Bool) (c : Clause n d) : Bool :=
c.any (Lit.eval z)
/-- Indices of the clauses of `T_H`: one unit clause per vertex, one edge clause per
edge, and `d + 1` cyclic implications per vertex. -/
abbrev ClauseIdx (d n m : ℕ) := Fin n ⊕ Fin m ⊕ (Fin n × Fin (d + 1))
/-- The unit clause `(¬ z v 0)`. -/
def unitClause {n d : ℕ} (v : Fin n) : Clause n d :=
[Lit.mk (v, 0) false]
/-- The edge clause `(z u p ∨ z w q)` of the edge `e`. -/
def edgeClause {d n m : ℕ} (G : PortGraph d n m) (e : Fin m) : Clause n d :=
[Lit.mk (G.left e, edgeClone (G.leftPort e)) true,
Lit.mk (G.right e, edgeClone (G.rightPort e)) true]
/-- The consistency implication `(¬ z v i ∨ z v (i+1))`. -/
def consClause {n d : ℕ} (p : Fin n × Fin (d + 1)) : Clause n d :=
[Lit.mk p false, Lit.mk (p.1, p.2 + 1) true]
def clauseOf {d n m : ℕ} (G : PortGraph d n m) : ClauseIdx d n m → Clause n d :=
Sum.elim unitClause (Sum.elim (edgeClause G) consClause)
/-- The number of clauses of `T_H` satisfied by `z`. -/
noncomputable def satCount {d n m : ℕ} (G : PortGraph d n m)
(z : Fin n → Fin (d + 1) → Bool) : ℕ :=
(Finset.univ.filter fun c : ClauseIdx d n m =>
Clause.satisfied z (clauseOf G c) = true).card
/-! ### Values of lifted assignments and the transfer to `T_H` -/
end PalomaMax2SAT.DegreeFormula
end Bundle_DegreeFormula
Source