The DPLL search with an explicit trail #
The solver Cslib.Algorithms.Lean.DPLL.solve searches recursively and builds a resolution
derivation as it returns. A machine without recursion runs the same search with an explicit
trail: the literals assumed so far, each marked as a first or a second branch
(Cslib.Algorithms.Lean.DPLL.Trail). One step (Cslib.Algorithms.Lean.DPLL.Trail.step) looks
at the partial assignment of the trail (Cslib.Algorithms.Lean.DPLL.status):
- if it satisfies every clause, the search ends with it;
- if it falsifies a clause, the search backtracks: it drops the second branches on top of the
trail and turns the first branch below them into its second branch, or ends with
UNSATwhen there is none (Cslib.Algorithms.Lean.DPLL.Trail.backtrack); - otherwise it pushes the literal the solver branches on
(
Cslib.Algorithms.Lean.DPLL.nextLiteral) as a first branch.
The run of the steps (Cslib.Algorithms.Lean.DPLL.Trail.run) explores the same tree as the
recursive search, except that it always tries the second branch of a variable, where the solver
skips it when the derivation of the first branch does not mention the variable. In that case the
second branch has no model either, since the derived clause is falsified by the partial assignment
(Cslib.Algorithms.Lean.DPLL.dfs_eq_none_of_derivation); so both find the same first model
(Cslib.Algorithms.Lean.DPLL.solve_eq_sat_iff_dfs). The run takes at most 2 ^ (N + 1) steps,
where N is the number of distinct variables (Cslib.Algorithms.Lean.DPLL.Trail.run_answer):
one per node of the search tree.
Main definitions #
Cslib.Algorithms.Lean.DPLL.status,Cslib.Algorithms.Lean.DPLL.nextLiteral: what the search does at a partial assignment.Cslib.Algorithms.Lean.DPLL.dfs: the search without skipping second branches.Cslib.Algorithms.Lean.DPLL.Trail.step,Cslib.Algorithms.Lean.DPLL.Trail.run: the search with an explicit trail.
Main results #
Cslib.Algorithms.Lean.DPLL.solve_eq_sat_iff_dfs,Cslib.Algorithms.Lean.DPLL.isSat_solve_eq_isSome_dfs: the search without skipping finds the solver's answer and model.Cslib.Algorithms.Lean.DPLL.Trail.run_answer: the trail run reaches that answer within2 ^ (N + 1)steps.
The status of a partial assignment #
Whether a partial assignment assigns the variable x.
The literal the solver branches on at π: the literal of a unit clause, or else the variable
of the first literal occurrence that π leaves open, true first.
What the search does at a partial assignment.
- conflict : Status
A clause is falsified.
- sat : Status
Every clause has a literal that holds.
- branch (l : Logic.PL.Literal ℕ) : Status
Branch on this literal, first assuming it true.
Instances For
The status of the partial assignment π, tested in the order of the solver: a falsified
clause, then satisfaction, then branching.
No variable is assumed both true and false.
Assuming a literal on an unassigned variable keeps a partial assignment consistent.
Every variable of the formula is assigned when no variable of φ.vars is open.
The branch variable is open.
The search without skipping #
The search without skipping from π with fuel levels left: the first partial assignment
satisfying every clause, trying both branches of every variable in order.
A partial assignment falsifying a clause has the status conflict.
A partial assignment of status conflict falsifies a clause.
A partial assignment falsifying no clause, with a true literal in every clause, has the status
sat.
Otherwise the status branches on nextLiteral.
A model found by the search extends the partial assignment, stays consistent, and satisfies every clause.
No model below a falsified derived clause: if π falsifies a clause derived from φ, the
search from π finds no model.
The search without skipping finds the solver's answer #
The open variables of π in the order of their first occurrences in φ.vars.
At a branching on l, a bound fuel on the open variables is positive, and the partial
assignments with a literal on the variable of l added have fewer.
The literal of the solver's branch is nextLiteral when the open variables are listed in the
order of their first occurrences.
The model of an outcome, if it is one.
The solver's search and the search without skipping agree: from the same partial assignment, the solver's search returns a model exactly when the search without skipping finds one, and then it is the model of the partial assignment found.
The number of distinct variables of φ: the depth of the search tree.
The search without skipping finds the solver's model.
The search with an explicit trail #
An entry of a trail: a literal assumed, and whether it is the second branch of its variable.
- lit : Logic.PL.Literal ℕ
The literal assumed.
- isSecond : Bool
Whether this is the second branch of its variable, after the first was refuted.
Instances For
A trail: its entries, last first.
The partial assignment of a trail.
Backtracking: drop the second branches on top, and turn the first branch below them into
its second branch; none when every branch is a second branch.
The end of a run: a partial assignment satisfying every clause, or none.
- sat (π : List (Logic.PL.Literal ℕ)) : Answer
The partial assignment of the trail satisfies every clause.
- unsat : Answer
No partial assignment satisfies every clause.
Instances For
One step of the search: end at a satisfying partial assignment, backtrack at a falsified clause, and otherwise push the branch literal.
The run of at most k steps from the trail t: its answer, or none if the steps run
out.
The number of nodes of the search tree from π with fuel levels.
What a run does after the subtree at the top of the trail: the model found in it, or else
the backtracked trail continuing with k steps.
The run explores the subtree at the top of the trail in nodes steps: it ends with the
model of the subtree if there is one, and otherwise continues by backtracking.
The answer of the search without skipping.