The Implication Graph of a 2-CNF Formula
Lax117284.TwoSatImplicationGraph · concepts/Lax117284/TwoSatImplicationGraph.lean · lax-117284
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
The implication graph of a 2-CNF formula is the directed graph on the literals in which a clause contributes the two edges and , and a unit clause the edge . An edge says that any assignment making true must make true, and so does a path. A variable is contradictory when reaches and reaches .
Concept map
Lean source view on GitHub
| 1 | import Lax117284.TwoSatCNF |
| 2 | import Mathlib.Logic.Relation |
| 3 | |
| 4 | /-! |
| 5 | --- |
| 6 | title: The Implication Graph of a 2-CNF Formula |
| 7 | type: definition |
| 8 | --- |
| 9 | The implication graph of a 2-CNF formula is the directed graph on the literals in which a |
| 10 | clause contributes the two edges and , and a unit |
| 11 | clause the edge . An edge says that any assignment making true |
| 12 | must make true, and so does a path. A variable is *contradictory* when reaches |
| 13 | and reaches . |
| 14 | |
| 15 | # Formalization Notes |
| 16 | |
| 17 | The graph is a relation on all literals, with no vertex set: a literal that no clause mentions |
| 18 | has no edges, and reachability is the reflexive-transitive closure of the edge relation. The |
| 19 | algorithm restricts its attention to the literals whose index is below a bound; that is its |
| 20 | business, and the criterion is stated for the graph as a whole. |
| 21 | |
| 22 | The edge relation is written by the shape of the clause. A clause of one literal gives |
| 23 | ; a clause gives and, read from the other end, |
| 24 | . A clause with two copies of the same literal gives one edge twice, and a |
| 25 | clause with more than two literals gives no edge at all, since the graph is only meant for |
| 26 | formulas in 2-CNF. |
| 27 | -/ |
| 28 | |
| 29 | namespace Lax117284.TwoSatImplicationGraph |
| 30 | |
| 31 | open Lax429075.CNF |
| 32 | |
| 33 | /-- The negation of a literal: the same variable, the opposite sign. -/ |
| 34 | def negate (l : Literal) : Literal := ⟨l.index, !l.positive⟩ |
| 35 | |
| 36 | /-- The positive literal of the variable `x`. -/ |
| 37 | def pos (x : ℕ) : Literal := ⟨x, true⟩ |
| 38 | |
| 39 | /-- The negative literal of the variable `x`. -/ |
| 40 | def neg (x : ℕ) : Literal := ⟨x, false⟩ |
| 41 | |
| 42 | /-- **The edges of the implication graph**: `a → b` when some clause is `[b]` with `a = ¬b`, or |
| 43 | some clause is `[¬a, b]` or `[b, ¬a]`. -/ |
| 44 | def Implies (F : Formula) (a b : Literal) : Prop := |
| 45 | ∃ C ∈ F, (C = [b] ∧ a = negate b) ∨ C = [negate a, b] ∨ C = [b, negate a] |
| 46 | |
| 47 | /-- **Reachability** in the implication graph, by a path of any length including zero. -/ |
| 48 | def Reaches (F : Formula) : Literal → Literal → Prop := Relation.ReflTransGen (Implies F) |
| 49 | |
| 50 | /-- **A contradictory variable**: it reaches its negation, and its negation reaches it. -/ |
| 51 | def Contradictory (F : Formula) (x : ℕ) : Prop := |
| 52 | Reaches F (pos x) (neg x) ∧ Reaches F (neg x) (pos x) |
| 53 | |
| 54 | end Lax117284.TwoSatImplicationGraph |
| 55 |
Formalization Notes
The graph is a relation on all literals, with no vertex set: a literal that no clause mentions has no edges, and reachability is the reflexive-transitive closure of the edge relation. The algorithm restricts its attention to the literals whose index is below a bound; that is its business, and the criterion is stated for the graph as a whole.
The edge relation is written by the shape of the clause. A clause of one literal gives ; a clause gives and, read from the other end, . A clause with two copies of the same literal gives one edge twice, and a clause with more than two literals gives no edge at all, since the graph is only meant for formulas in 2-CNF.
Builds on
From Mathlib
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments