Documentation

CslibFrontier.Algorithms.Lean.DPLL

A DPLL solver with LRAT certificates #

The procedure of Davis, Logemann and Loveland [DavisLogemannLoveland1962, pp. 394–395] decides satisfiability of a formula in conjunctive normal form by splitting on variables and propagating unit clauses. This is a variant: it keeps the splitting and the unit rule, but not the pure-literal rule, and it does not rewrite the formula as the search assigns variables. Here a partial assignment is a list π of literals assumed true, and the search (Cslib.Algorithms.Lean.DPLL.search) returns one of two outcomes (Cslib.Algorithms.Lean.DPLL.Outcome):

If π falsifies a clause of the formula, that clause is the derivation. If π satisfies every clause, it gives the model. Otherwise the search branches on a variable that π leaves open: the variable of a unit clause, one with a single literal not falsified by π, trying that literal first, or else the next open variable, trying true first. Trying the literal of a unit clause first is unit propagation, since the other branch falsifies the unit clause at once. The search keeps the open variables in a list without repetitions (Cslib.Algorithms.Lean.DPLL.OpenVars), so it never branches on a variable already assigned (Cslib.Algorithms.Lean.DPLL.OpenVars.fresh). When both branches return derivations and both clauses contain the branch variable, their resolvent on it is falsified by π; when one does not, that clause is already falsified by π. Recursion is structural on a bound on the number of open variables, which provably never runs out, so the search always ends with an outcome; there is no partial. The kernel can run it, so decide evaluates the solver on small formulas.

From the empty partial assignment, a derivation is a refutation, which compiles to a RUP-only LRAT (LRUP) certificate (Cslib.Logic.PL.CNF.Derivation.toLRAT). Cslib.Algorithms.Lean.DPLL.solve returns a model or a certificate. Models are models (Cslib.Algorithms.Lean.DPLL.solve_sat), certificates are accepted by Cslib.Logic.PL.CNF.checkLRUP (Cslib.Algorithms.Lean.DPLL.solve_unsat), and so the solver answers sat exactly on satisfiable formulas (Cslib.Algorithms.Lean.DPLL.isSat_solve_iff). As a corollary, every unsatisfiable formula has a RUP-only certificate that checkLRUP accepts (Cslib.Algorithms.Lean.DPLL.exists_checkLRUP_iff), and therefore one that full LRAT checkLRATRat accepts (Cslib.Algorithms.Lean.DPLL.exists_checkLRATRat_iff).

This solver learns no clauses: a certificate has one step per resolution of the search tree, which can be exponentially longer than what clause learning needs.

Main definitions #

Main results #

References #

Partial assignments #

A partial assignment, as a list of literals assumed true, falsifies a clause if it contains the negation of every literal of the clause.

A literal holds under a partial assignment if the assignment contains it and not its negation.

The total assignment of a partial assignment: a variable is true if it is assumed true.

A literal that holds under a partial assignment holds under its total assignment.

If every clause has a literal that holds, the total assignment is a model.

theorem Cslib.Algorithms.Lean.DPLL.all_any_holds {φ : Logic.PL.CNF ℕ} {π : List (Logic.PL.Literal ℕ)} (hnone : List.find? (Falsifies π) φ = none) (hassigned : ∀ x ∈ φ.vars, (x, true) ∈ π ∨ (x, false) ∈ π) :
(List.all φ fun (c : Logic.PL.Clause ℕ) => List.any c (Holds π)) = true

If a partial assignment falsifies no clause and assigns every variable, every clause has a literal that holds.

The outcome of the search from a partial assignment π: a model, or a tree-like derivation of a clause that π falsifies.

The literal of a clause that has exactly one literal not falsified by π, if that literal is not already assumed.

The literal to branch on: the literal of a unit clause if its variable is open, and otherwise the first open variable, true first.

def Cslib.Algorithms.Lean.DPLL.resolveBranches {φ : Logic.PL.CNF ℕ} {π : List (Logic.PL.Literal ℕ)} (v : ℕ) (b : Bool) {c₁ c₂ : Logic.PL.Clause ℕ} :
φ.Derivation c₁ → (v, !b) ∈ c₁ → (∀ l ∈ c₁, Std.Sat.Literal.negate l ∈ (v, b) :: π) → φ.Derivation c₂ → (v, b) ∈ c₂ → (∀ l ∈ c₂, Std.Sat.Literal.negate l ∈ (v, !b) :: π) → Outcome φ π

Combining the outcomes of the two branches on v, both derivations: the resolvent of their clauses on v, which π falsifies.

The open variables of a partial assignment: a list without repetitions of variables that π does not assign, containing every variable of the formula that π does not assign.

theorem Cslib.Algorithms.Lean.DPLL.OpenVars.erase {φ : Logic.PL.CNF ℕ} {π : List (Logic.PL.Literal ℕ)} {vs : List ℕ} (h : OpenVars φ π vs) (v : ℕ) (b : Bool) :
OpenVars φ ((v, b) :: π) (vs.erase v)

Assigning an open variable removes it from the open variables.

theorem Cslib.Algorithms.Lean.DPLL.OpenVars.fresh {φ : Logic.PL.CNF ℕ} {π : List (Logic.PL.Literal ℕ)} {x : ℕ} {xs : List ℕ} (h : OpenVars φ π (x :: xs)) {v : ℕ} {b : Bool} (hl : ↑(branchLiteral φ π x xs) = (v, b)) :
(v, true) ∉ π ∧ (v, false) ∉ π

The variable the search branches on is not yet assigned.

def Cslib.Algorithms.Lean.DPLL.search (φ : Logic.PL.CNF ℕ) (fuel : ℕ) (π : List (Logic.PL.Literal ℕ)) (vs : List ℕ) :
OpenVars φ π vs → vs.length ≤ fuel → Outcome φ π

The DPLL search from the partial assignment π, with the open variables vs and at most fuel of them.

The search from the empty partial assignment, with the variables of the formula open, in the order of their first occurrences.

The solver #

The answer of the solver: a model, or an LRAT certificate of unsatisfiability.

Whether the answer is a model.

theorem Cslib.Algorithms.Lean.DPLL.Result.isSat_iff {φ : Logic.PL.CNF ℕ} {r : Result} (hsat : ∀ (σ : ℕ → Bool), r = sat σ → Logic.PL.CNF.eval σ φ = true) (hunsat : ∀ (cert : Array Std.Tactic.BVDecide.LRAT.IntAction), r = unsat cert → φ.checkLRUP cert = true) :

A sound answer decides satisfiability: if a model in the answer satisfies φ and a certificate in it is accepted by CNF.checkLRUP on φ, the answer is a model exactly when φ is satisfiable.

A derivation of a clause falsified by the empty partial assignment derives the empty clause.

The DPLL solver: a model, or the RUP-only LRAT (LRUP) certificate of the refutation found by the search.

The models returned by the solver are models.

The certificates returned by the solver are accepted by the LRUP (RUP-only LRAT) checker.

The solver decides satisfiability.

The LRUP (RUP-only LRAT) checker is complete: a formula has a RUP-only certificate that CNF.checkLRUP accepts exactly when it is unsatisfiable.

The full LRAT checker with RAT steps is complete: a formula has a certificate that it accepts exactly when it is unsatisfiable.