Documentation

CslibFrontier.Algorithms.Lean.CDCL.System

Abstract DPLL with learning #

Nieuwenhuis, Oliveras and Tinelli [NieuwenhuisOliverasTinelli2006, §2] describe DPLL and conflict driven clause learning as transition systems. A state (Cslib.Algorithms.Lean.CDCL.State) is either the distinguished fail state or a trail M with a clause database F. The trail (Cslib.Algorithms.Lean.CDCL.Trail) is the sequence of assigned literals, kept here newest first, each marked as a decision or not (Cslib.Algorithms.Lean.CDCL.Entry). The rules are:

Entailment. The source (§2.1) works with partial assignments: a set of literals is a model of a clause set if it contains a literal of every clause, and F entails C if every such model of F contains a literal of C (Cslib.Algorithms.Lean.CDCL.PEntails). Forget uses this entailment, which the partial-model conclusion of Theorem 2.12 needs: entailment by total assignments would let Forget remove the tautology b ∨ ¬b from a, b ∨ ¬b, ending at the trail a, which has no literal of b ∨ ¬b. Backjump and Learn use entailment by total assignments. The §2.1 entailment implies it (Cslib.Algorithms.Lean.CDCL.PEntails.eval), so every step of the source is a step here, and the results below hold for at least the source's runs.

DPLL with learning (Cslib.Algorithms.Lean.CDCL.Step) is the union of the three. The invariant Cslib.Algorithms.Lean.CDCL.Inv is their Lemma 2.7, over a list V of variables containing those of the input formula φ: the database has the models of φ, its partial models are partial models of φ, and it uses variables of V, the trail assigns each variable of V at most once, and every implied literal holds in every model of φ satisfying the older literals; in fail, φ is unsatisfiable. Every step keeps it (Cslib.Algorithms.Lean.CDCL.Step.inv). Their results then hold, from the initial state with the empty trail and F = φ, taking V to be the variables of φ:

Representations. Clause sets are lists, so Learn prepends a clause and Forget removes one occurrence. The trail is kept newest first. Locators refer to the authors' manuscript, printed pp. 5–16.

Main definitions #

Main results #

References #

An entry of a trail: a literal and whether it is a decision.

@[reducible, inline]

The variable of an entry.

@[reducible, inline]

A trail: the assigned literals, newest first.

A partial assignment satisfies a clause if it makes one of its literals true [NieuwenhuisOliverasTinelli2006, §2.1]: the variable of the literal is assigned, with its polarity.

A partial assignment is a model of a clause set if it satisfies every clause.

Entailment [NieuwenhuisOliverasTinelli2006, §2.1]: every partial model of F satisfies C. It implies entailment by total assignments (Cslib.Algorithms.Lean.CDCL.PEntails.eval), but not conversely: the tautology b ∨ ¬b holds under every total assignment, while the partial model {a} of the clause a does not satisfy it.

Entailment by partial assignments implies entailment by total ones.

The variables of a trail.

@[reducible, inline]

A trail falsifies a clause if it contains the negation of every literal of the clause.

The level of a trail: its number of decisions.

An assignment satisfies a trail if it makes every literal of the trail true.

Every implied literal of the trail holds in every model of φ satisfying the older literals.

The total assignment of a trail: a variable is true if the trail makes it true.

The partial assignment of a trail: a variable is true or false if the trail makes it so, and unassigned otherwise.

The negation of the decisions of a trail.

A state: the distinguished failure state, or a trail and a clause database.

The Basic DPLL rules [NieuwenhuisOliverasTinelli2006, Definition 2.4].

Learn [NieuwenhuisOliverasTinelli2006, Definition 2.5]: adding a clause entailed by the database, whose variables occur in the database or the trail.

Forget [NieuwenhuisOliverasTinelli2006, Definition 2.5]: removing a clause entailed by the rest of the database, in the sense of §2.1 (Cslib.Algorithms.Lean.CDCL.PEntails).

DPLL with learning [NieuwenhuisOliverasTinelli2006, Definition 2.5]: a Basic DPLL step, a Learn step or a Forget step.

The invariant of a running state [NieuwenhuisOliverasTinelli2006, Lemma 2.7].

The invariant for the formula φ over the variables V: in a running state Cslib.Algorithms.Lean.CDCL.RunInv, and in fail, φ is unsatisfiable.

A trail assigning each variable once does not contain a literal and its negation.

theorem Cslib.Algorithms.Lean.CDCL.Trail.sat_of_entailed {φ : Logic.PL.CNF ℕ} {M : Trail} (h : Entailed φ M) {σ : ℕ → Bool} (hσ : Logic.PL.CNF.eval σ φ = true) (hdec : ∀ (l : Logic.PL.Literal ℕ), { lit := l, decision := true } ∈ M → Logic.PL.Literal.eval σ l = true) :
Sat σ M

A model of φ that satisfies the decisions of an entailed trail satisfies the trail.

theorem Cslib.Algorithms.Lean.CDCL.Trail.eval_of_forall_ne {σ : ℕ → Bool} {c : Logic.PL.Clause ℕ} {l : Logic.PL.Literal ℕ} {M : Trail} (hc : Logic.PL.Clause.eval σ c = true) (hM : Sat σ M) (hfalse : ∀ l' ∈ c, l' ≠ l → Std.Sat.Literal.negate l' ∈ M.lits) :

A clause that holds, with every literal but l false, forces l.

theorem Cslib.Algorithms.Lean.CDCL.Inv.init {φ : Logic.PL.CNF ℕ} {V : List ℕ} (hV : ∀ c ∈ φ, ∀ l ∈ c, l.1 ∈ V) :
Inv φ V (State.run [] φ)

The initial state, with the empty trail and the clauses of φ, satisfies the invariant.

Steps keep the invariant #

theorem Cslib.Algorithms.Lean.CDCL.RunInv.push {φ : Logic.PL.CNF ℕ} {V : List ℕ} {M : Trail} {F : Logic.PL.CNF ℕ} (h : RunInv φ V M F) {l : Logic.PL.Literal ℕ} (b : Bool) (hundef : l.1 ∉ M.vars) (hv : l.1 ∈ V) :
(Trail.vars ({ lit := l, decision := b } :: M)).Nodup ∧ ∀ x ∈ Trail.vars ({ lit := l, decision := b } :: M), x ∈ V

Adding a literal over an unassigned variable of V keeps the trail's variables distinct and in V.

theorem Cslib.Algorithms.Lean.CDCL.Step.inv {φ : Logic.PL.CNF ℕ} {V : List ℕ} {S S' : State} (hstep : Step S S') (h : Inv φ V S) :
Inv φ V S'

Steps keep the invariant [NieuwenhuisOliverasTinelli2006, Lemma 2.7].

Final states #

With each variable assigned once, the partial assignment of a trail makes a literal true exactly when the literal is on the trail.

theorem Cslib.Algorithms.Lean.CDCL.Trail.exists_mem_lits {M : Trail} {F : Logic.PL.CNF ℕ} (hnoconf : ∀ c ∈ F, ¬M.Falsifies c) (htotal : ∀ x ∈ F.vars, x ∈ M.vars) (c : Logic.PL.Clause ℕ) :
c ∈ F → ∃ l ∈ c, l ∈ M.lits

A trail that falsifies no clause of F and assigns every variable of F has a literal of every clause of F.

theorem Cslib.Algorithms.Lean.CDCL.RunInv.trail_model {φ : Logic.PL.CNF ℕ} {V : List ℕ} {M : Trail} {F : Logic.PL.CNF ℕ} (h : RunInv φ V M F) (hnoconf : ∀ c ∈ F, ¬M.Falsifies c) (htotal : ∀ x ∈ F.vars, x ∈ M.vars) (c : Logic.PL.Clause ℕ) :
c ∈ φ → ∃ l ∈ c, l ∈ M.lits

The trail is a model [NieuwenhuisOliverasTinelli2006, §2.1]: in a running state with no false clause that assigns every variable, every clause of φ has a literal on the trail.

theorem Cslib.Algorithms.Lean.CDCL.RunInv.eval_model {φ : Logic.PL.CNF ℕ} {V : List ℕ} {M : Trail} {F : Logic.PL.CNF ℕ} (h : RunInv φ V M F) (hnoconf : ∀ c ∈ F, ¬M.Falsifies c) (htotal : ∀ x ∈ F.vars, x ∈ M.vars) :

A running state with no false clause that assigns every variable gives a total model: the assignment making the trail's literals true.

theorem Cslib.Algorithms.Lean.CDCL.Trail.exists_split {M : Trail} (h : ∃ e ∈ M, e.decision = true) :
∃ (N : List Entry) (d : Logic.PL.Literal ℕ) (M₀ : List Entry), M = N ++ { lit := d, decision := true } :: M₀ ∧ ∀ e ∈ N, e.decision = false

A trail with a decision splits at its newest decision.

theorem Cslib.Algorithms.Lean.CDCL.RunInv.backjump_decisions {φ : Logic.PL.CNF ℕ} {V : List ℕ} {N M₀ : Trail} {F : Logic.PL.CNF ℕ} {d : Logic.PL.Literal ℕ} (h : RunInv φ V (N ++ { lit := d, decision := true } :: M₀) F) (hN : ∀ e ∈ N, e.decision = false) {c : Logic.PL.Clause ℕ} (hc : c ∈ F) (hcM : (N ++ { lit := d, decision := true } :: M₀).Falsifies c) :
BasicStep (State.run (N ++ { lit := d, decision := true } :: M₀) F) (State.run ({ lit := Std.Sat.Literal.negate d, decision := false } :: M₀) F)

Backjump with the negation of the decisions: below the newest decision d, a false clause lets Backjump add the negation of d.

theorem Cslib.Algorithms.Lean.CDCL.RunInv.fail_or_backjump {φ : Logic.PL.CNF ℕ} {V : List ℕ} {M : Trail} {F : Logic.PL.CNF ℕ} (h : RunInv φ V M F) {c : Logic.PL.Clause ℕ} (hc : c ∈ F) (hcM : M.Falsifies c) :
BasicStep (State.run M F) State.fail ∨ ∃ (N : List Entry) (d : Logic.PL.Literal ℕ) (M₀ : List Entry), M = N ++ { lit := d, decision := true } :: M₀ ∧ BasicStep (State.run M F) (State.run ({ lit := Std.Sat.Literal.negate d, decision := false } :: M₀) F)

Fail or Backjump applies [NieuwenhuisOliverasTinelli2006, Lemma 2.8]: in a running state with a false clause, Fail applies if the trail has no decision, and otherwise Backjump applies, going below the newest decision d and adding its negation.

theorem Cslib.Algorithms.Lean.CDCL.RunInv.exists_basicStep {φ : Logic.PL.CNF ℕ} {V : List ℕ} {M : Trail} {F : Logic.PL.CNF ℕ} (h : RunInv φ V M F) (hfinal : ¬((∀ c ∈ F, ¬M.Falsifies c) ∧ ∀ x ∈ F.vars, x ∈ M.vars)) :
∃ (S' : State), BasicStep (State.run M F) S'

Progress: a running state from which no Basic DPLL step applies has no false clause and assigns every variable occurring in the database (the first two parts of [NieuwenhuisOliverasTinelli2006, Lemma 2.9]): otherwise Fail or Backjump applies by Cslib.Algorithms.Lean.CDCL.RunInv.fail_or_backjump, or Decide applies.

theorem Cslib.Algorithms.Lean.CDCL.Inv.final {φ : Logic.PL.CNF ℕ} {V : List ℕ} {S : State} (h : Inv φ V S) (hfinal : ∀ (S' : State), ¬BasicStep S S') :
(S = State.fail ↔ ¬φ.Satisfiable) ∧ ∀ (M : Trail) (F : Logic.PL.CNF ℕ), S = State.run M F → (∀ c ∈ φ, ∃ l ∈ c, l ∈ M.lits) ∧ Logic.PL.CNF.eval M.assignment φ = true

A state that satisfies the invariant and is final for Basic DPLL is fail exactly when φ is unsatisfiable, and otherwise its trail is a model of φ: every clause of φ has a literal on the trail, so the total assignment making the trail's literals true is a model too.

The states reachable from the initial state satisfy the invariant.

theorem Cslib.Algorithms.Lean.CDCL.final_of_reachable {φ : Logic.PL.CNF ℕ} {S : State} (h : Relation.ReflTransGen Step (State.run [] φ) S) (hfinal : ∀ (S' : State), ¬BasicStep S S') :
(S = State.fail ↔ ¬φ.Satisfiable) ∧ ∀ (M : Trail) (F : Logic.PL.CNF ℕ), S = State.run M F → (∀ c ∈ φ, ∃ l ∈ c, l ∈ M.lits) ∧ Logic.PL.CNF.eval M.assignment φ = true

Final states decide satisfiability [NieuwenhuisOliverasTinelli2006, Theorem 2.12]: a state reachable from the initial state by DPLL with learning and final for Basic DPLL is fail exactly when φ is unsatisfiable, and otherwise its trail is a model of φ in the sense of §2.1: every clause of φ has a literal on the trail. The total assignment making the trail's literals true is then a model as well.

Termination #

The measure of a trail over N variables: a literal at level k weighs (N + 1) ^ (N - k).

The literals above a trail weigh at most (N + 1) ^ (N - level) each.

The length of a trail is at most the number of variables it may use.

The measure of a trail satisfying the invariant is at most N * (N + 1) ^ N.

The rank of a state over the variables V: 0 for fail, and otherwise one more than the room left below the bound on the measure. Every Basic DPLL step lowers it.

theorem Cslib.Algorithms.Lean.CDCL.BasicStep.rank_lt {φ : Logic.PL.CNF ℕ} {V : List ℕ} {S S' : State} (hstep : BasicStep S S') (h : Inv φ V S) :
rank V S' < rank V S

Every Basic DPLL step lowers the rank.

Termination of Basic DPLL [NieuwenhuisOliverasTinelli2006, Theorem 2.10]: there is no infinite run of Basic DPLL steps from the initial state.

A Learn or Forget step.

Learn and Forget steps keep the trail, hence the rank.

Learn and Forget steps from a reachable state reach states of the same rank.

Termination of DPLL with learning [NieuwenhuisOliverasTinelli2006, Theorem 2.11]: a run from the initial state in which no stretch of Learn and Forget steps is infinite is finite. It is stated as: there is no infinite sequence of moves from the initial state, each a finite run of Learn and Forget steps followed by a Basic DPLL step.