Documentation

CslibFrontier.Algorithms.WordRAM.DPLL.Program

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):

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 #

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 #

@[reducible, inline]

Constant 0.

@[reducible, inline]

Constant 1.

@[reducible, inline]

Constant 2.

@[reducible, inline]

Base of the literal array, which is also the end of the clauses.

@[reducible, inline]

End of the refutation log, in the variant that writes the search tree (Cslib.Algorithms.WordRAM.DPLL.programLog).

@[reducible, inline]

Base of the trail.

@[reducible, inline]

Top of the trail: the address after its last entry.

@[reducible, inline]

Address of the output.

@[reducible, inline]

The bound N on the variables.

@[reducible, inline]

End of the clauses.

@[reducible, inline]

Address of the current clause.

@[reducible, inline]

Length of the current clause.

@[reducible, inline]

Address of the current literal.

@[reducible, inline]

End address of the current clause.

@[reducible, inline]

The current literal code.

@[reducible, inline]

The code of its negation.

@[reducible, inline]

Whether the current literal is on the trail.

@[reducible, inline]

Whether its negation is on the trail.

@[reducible, inline]

Scratch address.

@[reducible, inline]

The current variable.

@[reducible, inline]

The number of literals of the current clause not falsified so far.

@[reducible, inline]

The code of the last such literal.

@[reducible, inline]

Whether the current clause has a true literal so far.

@[reducible, inline]

Whether a falsified clause was found.

@[reducible, inline]

Whether every clause so far has a true literal.

@[reducible, inline]

Whether a unit clause was found.

@[reducible, inline]

The code of the literal of the first unit clause.

@[reducible, inline]

Whether an open variable was found.

@[reducible, inline]

The first open variable.

@[reducible, inline]

Whether the search goes on.

@[reducible, inline]

Output address.

@[reducible, inline]

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.

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.

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.

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)].

The solver #

Set up the registers: constants, the end of the clauses, and the three arrays.

The DPLL solver on the input encode N φ, leaving the address of its output in out.

The DPLL solver as a flat program returning its output list.