Documentation

Complexity.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.

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

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

      Instances For
        @[reducible, inline]

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

        Instances For
          @[reducible, inline]

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

          Instances For

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

            Instances For

              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.

              Instances For
                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.

                Instances For
                  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.

                  Instances For

                    A CNF structure is satisfiable when some assignment satisfies it.

                    Instances For
                      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

                      Satisfiability is invariant under isomorphism.

                      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.

                      Instances For
                        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.

                        The classes SAT and 3SAT #

                        SAT: the class of satisfiable CNF structures.

                        Instances For

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

                          Instances For

                            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 #

                            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) :
                            FirstOrder.Language.Structure.RelMap (lit b) ![c, y] ↔ ∃ τ ∈ temps c.fst b, τ.Holds (↑c.snd) y.toSigma

                            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.snd ∧ ∃ (y : ι τ.target → M) (hy : (I.domain τ.target).Realize y), τ.Compat (↑c.snd) y ∧ A ⟨τ.target, ⟨y, hy⟩⟩) ∨ ∃ τ ∈ temps c.fst false, τ.guard.Realize ↑c.snd ∧ ∃ (y : ι τ.target → M) (hy : (I.domain τ.target).Realize y), τ.Compat (↑c.snd) 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.

                            Instances For
                              @[reducible, inline]

                              The symbol neg among those of the satisfiability sentence.

                              Instances For
                                @[reducible, inline]

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

                                Instances For

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

                                  Instances For

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

                                    Instances For

                                      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.

                                      Instances For

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

                                        Instances For

                                          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).

                                          Instances For

                                            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.

                                            Instances For