Finding the first falsified clause on the word RAM #
A CNF formula on the variables Fin n is stored in word-RAM memory clause by clause: a clause
c occupies c.length + 1 words, its length followed by the codes 2 v + b of its literals
(v, b) (Cslib.Algorithms.WordRAM.Schoening.encodeClause). An assignment σ : Fin n → Bool is
stored as n words 0 or 1 (Cslib.Algorithms.WordRAM.Schoening.AssignAt).
Cslib.Algorithms.WordRAM.Schoening.scan scans the clauses in order, evaluating each one against
the stored assignment, and stops at the first falsified clause. It reports whether one was found
and, if so, the address of its encoding: exactly the clause chosen by
Cslib.Complexity.Schoening.firstUnsat (Cslib.Algorithms.WordRAM.Schoening.scan_spec). It runs
within 12 E + 4 instructions, where E is the number of words of the formula's encoding, and
leaves memory unchanged. The scan is the deterministic part of one step of Schöning's local search
and of the final satisfaction check.
The registers of the scan belong to a register file of 24 registers shared with the trial and
amplification programs of Schöning's algorithm (Cslib.Algorithms.WordRAM.Schoening.Reg).
Main definitions #
Cslib.Algorithms.WordRAM.Schoening.litCode,Cslib.Algorithms.WordRAM.Schoening.encodeClause,Cslib.Algorithms.WordRAM.Schoening.encodeClauses,Cslib.Algorithms.WordRAM.Schoening.encode: the word encoding of literals, clauses and formulas; the input of a trial isnfollowed by the clauses.Cslib.Algorithms.WordRAM.Schoening.AssignAt,Cslib.Algorithms.WordRAM.Schoening.assignmentAt: storing and reading an assignment.Cslib.Algorithms.WordRAM.Schoening.ScanResult: the result registers of the scan, matched againstfirstUnsat.Cslib.Algorithms.WordRAM.Schoening.scan: the scan as a structured program.
Main results #
Cslib.Algorithms.WordRAM.Schoening.scan_spec: the scan findsfirstUnsatwithin12 E + 4instructions without changing memory.Cslib.Algorithms.WordRAM.Schoening.assignmentAt_eq: reading back a stored assignment.
References #
Encoding #
The word code 2 v + b of the literal (v, b)
(Cslib.Algorithms.WordRAM.ClauseCode.litCodeBy through the value of the variable).
A clause is stored as its length followed by the codes of its literals
(Cslib.Algorithms.WordRAM.ClauseCode.encodeClauseBy).
The words of a clause: its length, then the codes of its literals.
The clauses of a formula, stored one after another.
The input of a trial of Schöning's algorithm: the number of variables, then the clauses.
Literal codes are below 2 n.
Shifting a literal code right recovers its variable.
The low bit of a literal code is its sign.
Registers #
The 24 registers shared by the programs of Schöning's algorithm.
Address of the first clause.
Address of the stored assignment, which is also the end of the clauses.
The number n of variables.
Address of the current clause.
Length of the current clause.
Address of the current literal.
End address of the current clause.
Whether the current clause has a true literal so far.
The current literal code.
The current variable.
The sign of the current literal.
Scratch address.
Whether a falsified clause was found.
Address of the falsified clause found.
Number of steps of the local search.
The scan #
One literal: read its code, look up its variable, and record whether it is true.
Evaluate the literals in [lptr, lend).
Read the length of the clause at ptr and set up its literal loop.
After a clause: on a falsified clause record it and jump to the end, otherwise move on.
One clause: evaluate it, and on a falsified clause record it and jump to the end.
Evaluate the clauses in [ptr, aBase) until a falsified one.
The scan: find the first clause falsified by the stored assignment.
The cons equation of firstUnsat: List.find?_cons with the match on !c.eval σ stated as an
if, the form the scan proofs rewrite with.
firstUnsat finds nothing exactly on satisfying assignments.
A satisfied first clause does not change the scan result.
The literal loop. From sat = 0, the loop over the literals ls ends with sat the value
of the clause ls under σ, lptr = lend, and unchanged memory.
The clause loop. From ptr at the encoding of the clauses ψ, which end at aBase, and
found = 0, the loop ends with the scan result for ψ and unchanged memory.
The scan. From the clauses of φ stored in [cBeg, aBase) and the assignment σ stored at
aBase, the scan reports firstUnsat φ σ within 12 E + 4 instructions, where E is the length
of the encoding, and leaves memory unchanged.