The DPLL solver on the word RAM: encoding and program #
This file states the input encoding, the output and the program of a word-RAM version of the DPLL
solver Cslib.Algorithms.Lean.DPLL.solve. The program runs the search with an explicit trail
(Cslib.Algorithms.Lean.DPLL.Trail.run), one step of it per iteration of its main loop.
Encoding #
A literal (v, b) is the word 2 v + b (Cslib.Algorithms.WordRAM.ClauseCode.litCode), and a
clause is its length followed by the codes of its literals
(Cslib.Algorithms.WordRAM.ClauseCode.encodeClause), the encoding of the word-RAM Schöning scan.
The input is a bound N on the variables, then the clauses
(Cslib.Algorithms.WordRAM.DPLL.encode); every variable of the formula must be below N.
Output #
The program returns a length-prefixed list (Cslib.WordRAM.outputList): [0] when the formula
is unsatisfiable, and [1, σ 0, …, σ (N - 1)] (as bits) for the model σ of the solver otherwise
(Cslib.Algorithms.WordRAM.DPLL.answerWords).
Memory #
With the input of length L at addresses 1, …, L, the clauses occupy [2, T) for T = L + 1.
After them come three arrays, all initially zero since word-RAM memory starts at zero
(Cslib.WordRAM.Data.init):
- the literal array at
T: the cellT + 2 v + bholds1when the literal(v, b)is on the trail, and0otherwise; - the trail at
T + 2 N: two words per entry, the code of its literal and1for a second branch,0for a first; - the output at
T + 4 N.
One step of the search #
One pass over the clauses (Cslib.Algorithms.WordRAM.DPLL.scan) finds whether a clause is
falsified, whether every clause has a true literal, the first unit clause whose literal is not
on the trail, and the variable of the first literal occurrence that the trail leaves open. Then
the step backtracks on a falsified clause, writes the model when every clause is satisfied, and
otherwise pushes the literal of the unit clause or the open variable, true first.
Main definitions #
Cslib.Algorithms.WordRAM.DPLL.encode,Cslib.Algorithms.WordRAM.DPLL.answerWords: the input and the output.Cslib.Algorithms.WordRAM.DPLL.solver,Cslib.Algorithms.WordRAM.DPLL.program: the solver, as a structured program and as a flat program returning its output list.
Encoding #
The input of the solver: the bound N on the variables, then the clauses of φ.
The output of the solver: [0] for an unsatisfiable formula, and 1 followed by the bits
of the solver's model on the variables below N otherwise.
Registers #
Base of the literal array, which is also the end of the clauses.
End of the refutation log, in the variant that writes the search tree
(Cslib.Algorithms.WordRAM.DPLL.programLog).
Top of the trail: the address after its last entry.
The bound N on the variables.
Address of the current clause.
Length of the current clause.
Address of the current literal.
End address of the current clause.
The current literal code.
The code of its negation.
Whether the current literal is on the trail.
Whether its negation is on the trail.
The number of literals of the current clause not falsified so far.
The code of the last such literal.
Whether the current clause has a true literal so far.
Whether a falsified clause was found.
Whether every clause so far has a true literal.
Whether a unit clause was found.
The code of the literal of the first unit clause.
Whether an open variable was found.
The first open variable.
Whether the search goes on.
Whether backtracking keeps popping.
The scan of the clauses #
One literal: count it when it is not falsified, recording its code. Such a literal is true, which is recorded, or its variable is open, which is recorded as the first open one when none was found before.
The literals in [lptr, lend).
After a clause: record a falsified clause, a clause without a true literal, and the first unit clause whose literal is not on the trail; move to the next clause.
One clause.
The clauses in [ptr, cend).
The scan of the clauses against the trail.
Steps #
Pop a second branch from the top of the trail, clearing its literal; stop at a first branch or an empty trail.
Pop the second branches on top of the trail.
Stop with the output [0].
Backtracking: pop the second branches, then turn the first branch on top into its second
branch, or stop with [0] when the trail is empty.
Branching: push the literal of the unit clause, or the first open variable, true, as a first branch.
One bit of the model: the literal array cell of the variable, true.
Stop with the output [1, σ 0, …, σ (N - 1)].
One step of the search.
The search: steps while go = 1.
The solver #
Set up the registers: constants, the end of the clauses, and the three arrays.
The DPLL solver as a flat program returning its output list.