Documentation

CslibFrontier.Logics.FirstOrder.Problems.CNF

Satisfiability of CNF structures #

A formula in conjunctive normal form is given as a finite structure for the vocabulary cnf of two binary relation symbols cnf.pos and cnf.neg. Every element c names a clause and a variable: the clause named by c has the positive literal x when pos(c, x) holds and the negative literal ¬x when neg(c, x) holds. An element related to nothing names the empty clause. A structure is satisfiable (cnf.Satisfiable) when some assignment of truth values to the elements satisfies every clause, that is, when it satisfies the existential second-order sentence ∃ S, ∀ c, ∃ x, (pos(c, x) ∧ S x) ∨ (neg(c, x) ∧ ¬ S x). It is a 3-CNF structure (cnf.IsThreeCNF) when every clause has at most three literals.

Descriptive complexity presents satisfiability as a class of finite structures in this way Immerman, Chapter 7; the conventions above are fixed here. A formula with m clauses over n variables is presented by a structure with max m n elements: the clauses and the variables are numbered from the same elements, and the elements naming no clause of the formula name the tautology x ∨ ¬x of their own variable. The empty structure presents the empty formula, which is satisfiable. The machine-level problem, on formulas of Cslib.Logic.PL.CNF ℕ encoded as lists, is Cslib.Complexity.SAT.

The classes cnf.SAT and cnf.ThreeSAT of satisfiable structures and of satisfiable 3-CNF structures are existential second-order definable, hence closed under isomorphism, and they are invariant under disjoint copies, so that tagged interpretations reduce to them. The vocabulary cnf.vocabulary lists the table of pos before that of neg in encoded structures.

Main definitions #

Main results #

References #

The vocabulary #

The relation symbols of CNF structures.

  • pos : CNFRel 2

    The positive occurrence of a variable in a clause.

  • neg : CNFRel 2

    The negative occurrence of a variable in a clause.

def Cslib.Logic.FO.instDecidableEqCNFRel.decEq {a✝ : ℕ} (x✝ x✝¹ : CNFRel a✝) :
Decidable (x✝ = x✝¹)
@[instance_reducible]

The vocabulary of CNF structures, with two binary relation symbols.

@[reducible, inline]

pos(c, x): the variable x occurs positively in the clause c.

@[reducible, inline]

neg(c, x): the variable x occurs negatively in the clause c.

The relation symbol of the literals of a polarity: pos for true, neg for false.

@[simp]

The positive literal relation symbol is cnf.pos.

@[simp]

The negative literal relation symbol is cnf.neg.

Satisfiability #

def Cslib.Logic.FO.cnf.literals {M : Type u_1} [cnf.Structure M] (c : M) :
Set (Bool × M)

The literals of the clause named by c: a polarity and a variable.

A pair (b, x) belongs to literals c iff lit b relates c and x.

def Cslib.Logic.FO.cnf.ClauseSatisfied {M : Type u_1} [cnf.Structure M] (A : M → Prop) (c : M) :

An assignment satisfies the clause named by c when the clause has a positive literal whose variable is true or a negative literal whose variable is false.

def Cslib.Logic.FO.cnf.Satisfies {M : Type u_1} [cnf.Structure M] (A : M → Prop) :

An assignment satisfies a CNF structure when it satisfies every clause.

A CNF structure is satisfiable when some assignment satisfies it.

theorem Cslib.Logic.FO.cnf.clauseSatisfied_iff {M : Type u_1} [cnf.Structure M] (A : M → Prop) (c : M) :
ClauseSatisfied A c ↔ ∃ l ∈ literals c, A l.2 ↔ l.1 = true

A clause is satisfied when it has a literal with the truth value of its polarity.

theorem Cslib.Logic.FO.cnf.satisfies_iff {M : Type u_1} [cnf.Structure M] (A : M → Prop) :
Satisfies A ↔ ∀ (c : M), ∃ l ∈ literals c, A l.2 ↔ l.1 = true

An assignment satisfies a CNF structure iff every clause has a literal matching its truth value.

Satisfiability is invariant under isomorphism.

Isomorphic CNF structures are equisatisfiable.

Every clause of a satisfiable CNF structure is nonempty.

3-CNF structures #

A CNF structure is a 3-CNF structure when every clause has at most three literals.

theorem Cslib.Logic.FO.cnf.encard_literals_le_three_iff {M : Type u_1} [cnf.Structure M] (c : M) :
(literals c).encard ≤ 3 ↔ ¬∃ (l : Fin 4 → Bool × M), (∀ (i : Fin 4), l i ∈ literals c) ∧ Function.Injective l

A clause has at most three literals exactly when it has no four distinct ones.

Being a 3-CNF structure is invariant under isomorphism.

The classes SAT and 3SAT #

SAT: the class of satisfiable CNF structures.

3SAT: the class of satisfiable 3-CNF structures.

SAT is closed under isomorphism.

3SAT is closed under isomorphism.

The empty structure is satisfiable.

The empty structure is a 3-CNF structure.

Every structure with at most one element is a 3-CNF structure.

Copies #

A positive number of disjoint copies of a CNF structure is satisfiable exactly when the structure is.

A positive number of disjoint copies of a CNF structure is a 3-CNF structure exactly when the structure is.

SAT is invariant under copies.

CNF structures interpreted by templates #

theorem Cslib.Logic.FO.cnf.relMap_lit_of_templates {L : FirstOrder.Language} {T : Type u_3} {ι : T → Type u_4} [∀ (t : T), Finite (ι t)] {I : TaggedInterpretation L cnf T ι} {temps : (t : T) → Bool → List (TaggedInterpretation.Template L ι t)} {M : Type w} [L.Structure M] (hI : ∀ (b : Bool) (ts : Fin 2 → T), I.rel (lit b) ts = TaggedInterpretation.binaryRel (fun (t w : T) => TaggedInterpretation.Template.listFormula (temps t b) w) ts) (b : Bool) (c y : I.Model M) :

In a CNF structure interpreted by templates, the literals of a polarity of a clause are the elements related to it by the templates of that polarity.

theorem Cslib.Logic.FO.cnf.clauseSatisfied_iff_of_templates {L : FirstOrder.Language} {T : Type u_3} {ι : T → Type u_4} [∀ (t : T), Finite (ι t)] {I : TaggedInterpretation L cnf T ι} {temps : (t : T) → Bool → List (TaggedInterpretation.Template L ι t)} {M : Type w} [L.Structure M] (hI : ∀ (b : Bool) (ts : Fin 2 → T), I.rel (lit b) ts = TaggedInterpretation.binaryRel (fun (t w : T) => TaggedInterpretation.Template.listFormula (temps t b) w) ts) (A : I.Model M → Prop) (c : I.Model M) :
ClauseSatisfied A c ↔ (∃ τ ∈ temps c.fst true, τ.guard.Realize c.coords ∧ ∃ (y : ι τ.target → M) (hy : (I.domain τ.target).Realize y), τ.Compat c.coords y ∧ A ⟨τ.target, ⟨y, hy⟩⟩) ∨ ∃ τ ∈ temps c.fst false, τ.guard.Realize c.coords ∧ ∃ (y : ι τ.target → M) (hy : (I.domain τ.target).Realize y), τ.Compat c.coords y ∧ ¬A ⟨τ.target, ⟨y, hy⟩⟩

In a CNF structure interpreted by templates, an assignment satisfies a clause when a template of a polarity applies to its coordinates and relates it to a variable with that truth value.

Defining sentences #

@[reducible, inline]

The symbol pos among those of the satisfiability sentence.

@[reducible, inline]

The symbol neg among those of the satisfiability sentence.

@[reducible, inline]

The relation variable S of the satisfiability sentence, the set of true variables.

The first-order part of the satisfiability sentence: ∀ c, ∃ x, (pos(c, x) ∧ S x) ∨ (neg(c, x) ∧ ¬ S x).

The satisfiability sentence ∃ S, ∀ c, ∃ x, (pos(c, x) ∧ S x) ∨ (neg(c, x) ∧ ¬ S x).

The satisfiability sentence holds exactly in the satisfiable CNF structures.

SAT is existential second-order definable.

The formula in the variables c (Sum.inl ()) and x₀, …, x₃ (Sum.inr i) saying that the literals (bs i, x i) of the clause c are distinct.

The 3-CNF sentence: no clause has four distinct literals.

The 3-CNF sentence holds exactly in the 3-CNF structures.

The sentence saying that no clause is empty: ∀ c, ∃ x, pos(c, x) ∨ neg(c, x).

The sentence nonemptyClausesSentence holds exactly when no clause is empty.

3-CNF structures form a first-order definable class.

3SAT is existential second-order definable.

Encoded CNF structures #

The vocabulary of encoded CNF structures: the table of pos, then that of neg.