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):
- a model of the formula, with a proof that it is one; or
- a tree-like resolution derivation (
Cslib.Logic.PL.CNF.Derivation) of a clause thatπfalsifies.
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 #
Cslib.Algorithms.Lean.DPLL.search: the search from a partial assignment.Cslib.Algorithms.Lean.DPLL.solve: a model or an LRUP (RUP-only LRAT) certificate.
Main results #
Cslib.Algorithms.Lean.DPLL.solve_sat,Cslib.Algorithms.Lean.DPLL.solve_unsat: both answers are correct.Cslib.Algorithms.Lean.DPLL.Result.isSat_iff: an answer whose model satisfies the formula and whose certificateCNF.checkLRUPaccepts decides satisfiability.Cslib.Algorithms.Lean.DPLL.isSat_solve_iff: the solver decides satisfiability.Cslib.Algorithms.Lean.DPLL.OpenVars.fresh: the search branches only on unassigned variables.Cslib.Algorithms.Lean.DPLL.exists_checkLRUP_iff: the LRUP (RUP-only LRAT) checker is complete.Cslib.Algorithms.Lean.DPLL.exists_checkLRATRat_iff: so is the full LRAT checker with RAT steps.
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.
If a partial assignment falsifies no clause and assigns every variable, every clause has a literal that holds.
The search #
The outcome of the search from a partial assignment π: a model, or a tree-like derivation
of a clause that π falsifies.
- sat {φ : Logic.PL.CNF ℕ} {π : List (Logic.PL.Literal ℕ)} (σ : ℕ → Bool) (h : Logic.PL.CNF.eval σ φ = true) : Outcome φ π
A model of the formula.
- unsat {φ : Logic.PL.CNF ℕ} {π : List (Logic.PL.Literal ℕ)} (c : Logic.PL.Clause ℕ) (d : φ.Derivation c) (h : ∀ l ∈ c, Std.Sat.Literal.negate l ∈ π) : Outcome φ π
A 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.
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.
Every variable of the formula is open or assigned.
No open variable is assigned.
- nodup : vs.Nodup
No open variable is listed twice.
The variable the search branches on is not yet assigned.
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.
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.