Documentation

CslibFrontier.Algorithms.WordRAM.PPZ.Forced

Forced values of PPZ on the word RAM #

A partial assignment τ : Fin n → Option Bool is stored as n words, 0 or 1 for a set variable and 2 for an unset one (Cslib.Algorithms.WordRAM.PPZ.PartialAt). The formula is stored as in Cslib.Algorithms.WordRAM.Schoening.encodeClauses: each clause is its length followed by the codes 2 v + b of its literals.

Cslib.Algorithms.WordRAM.PPZ.unitScan scans the clauses once and reports whether one of them is a unit clause on the variable x with polarity b under τ (Cslib.Complexity.PPZ.IsUnitOn): a clause that contains (x, b), whose literals on x all have polarity b, and whose other literals τ falsifies. Cslib.Algorithms.WordRAM.PPZ.forcedCode runs it for the polarity true and then, if needed, for false, and stores the word of Cslib.Complexity.PPZ.forced φ τ x (Cslib.Algorithms.WordRAM.PPZ.forcedCode_spec). Both leave memory unchanged and take O(E) instructions, where E is the length of the encoding of the clauses.

Main definitions #

Main results #

References #

Partial assignments #

The word of a value of a partial assignment: 0 or 1 when set, 2 when unset.

def Cslib.Algorithms.WordRAM.PPZ.PartialAt {n : ℕ} (mem : ℕ → ℕ) (base : ℕ) (τ : Fin n → Option Bool) :

The partial assignment τ is stored as the words optCode (τ i) from address base.

Unit clauses through literal tests #

Whether the literal l is (x, b).

def Cslib.Algorithms.WordRAM.PPZ.litOk {n : ℕ} (τ : Fin n → Option Bool) (x : Fin n) (b : Bool) (l : Logic.PL.Literal (Fin n)) :

Whether the literal l may occur in a unit clause on x with polarity b under τ: a literal on x must have polarity b, and τ must falsify any other literal.

theorem Cslib.Algorithms.WordRAM.PPZ.isUnitOn_iff {n : ℕ} (τ : Fin n → Option Bool) (x : Fin n) (b : Bool) (c : Logic.PL.Clause (Fin n)) :

A unit clause through its literal tests.

def Cslib.Algorithms.WordRAM.PPZ.unitTest {n : ℕ} (τ : Fin n → Option Bool) (x : Fin n) (b : Bool) (c : Logic.PL.Clause (Fin n)) :

Whether the clause c is a unit clause on x with polarity b under τ, through the literal tests.

The value forced by unit clauses, through the literal tests.

The partial-assignment test of litOk: τ v is some (!s) exactly when its word is 1 - s.

Registers #

@[reducible, inline]

Constant 0.

@[reducible, inline]

Constant 1.

@[reducible, inline]

Address of the first clause.

@[reducible, inline]

End address of the clauses.

@[reducible, inline]

Address of the stored partial assignment.

@[reducible, inline]

The number n of variables.

@[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 current variable.

@[reducible, inline]

The sign of the current literal.

@[reducible, inline]

Scratch address.

@[reducible, inline]

Scratch value.

@[reducible, inline]

Scratch comparison.

@[reducible, inline]

Whether the current clause contains (x, b).

@[reducible, inline]

Whether every literal of the current clause passes litOk.

@[reducible, inline]

Whether a unit clause was found.

@[reducible, inline]

The variable x.

@[reducible, inline]

The polarity b.

@[reducible, inline]

The word of the forced value.

@[reducible, inline]

Constant 2.

The scan #

Read the length of the clause at ptr and set up its literal loop.

After a clause: record whether it is a unit clause and move on.

The unit-clause scan: whether some clause is a unit clause on xReg with polarity bReg.

The forced value of xReg, stored in res as optCode (forced φ τ x).

structure Cslib.Algorithms.WordRAM.PPZ.ScanFrame {n : ℕ} (w : ℕ) (τ : Fin n → Option Bool) (x : Fin n) (y : WordRAM.Data 32) :

The registers the scan relies on. The scan writes none of them and leaves memory unchanged, so a call of one of its parts proves the frame from the caller's (scanFrame_iff).

theorem Cslib.Algorithms.WordRAM.PPZ.litBody_spec {n w : ℕ} (τ : Fin n → Option Bool) (x : Fin n) (b : Bool) (l : Logic.PL.Literal (Fin n)) (h o : Bool) (y : WordRAM.Data 32) (hf : ScanFrame w τ x y) (hb : y.regs Reg.bReg = b.toNat) (hl : y.mem (y.regs Reg.lptr) = Schoening.litCode l) (hh : y.regs Reg.hasLit = h.toNat) (ho : y.regs Reg.ok = o.toNat) (hlp : WordRAM.Fits w (y.regs Reg.lptr + 1)) :

One literal.

theorem Cslib.Algorithms.WordRAM.PPZ.litLoop_spec {n w : ℕ} (τ : Fin n → Option Bool) (x : Fin n) (b : Bool) (ls : Logic.PL.Clause (Fin n)) (h o : Bool) (y : WordRAM.Data 32) (hf : ScanFrame w τ x y) (hb : y.regs Reg.bReg = b.toNat) (hl : WordRAM.Block.HoldsList (y.regs Reg.lptr) (List.map Schoening.litCode ls) y.mem) (hend : y.regs Reg.lend = y.regs Reg.lptr + List.length ls) (hh : y.regs Reg.hasLit = h.toNat) (ho : y.regs Reg.ok = o.toNat) (hle : WordRAM.Fits w (y.regs Reg.lend)) :

The literal loop. From hasLit = h and ok = o, the loop over the literals ls ends with hasLit = h || ls.any (litHas x b) and ok = o && ls.all (litOk τ x b), and unchanged memory.

theorem Cslib.Algorithms.WordRAM.PPZ.clauseLoop_spec {n w : ℕ} (τ : Fin n → Option Bool) (x : Fin n) (b : Bool) (ψ : Logic.PL.CNF (Fin n)) (f : Bool) (y : WordRAM.Data 32) (hf : ScanFrame w τ x y) (hb : y.regs Reg.bReg = b.toNat) (hp : WordRAM.Block.HoldsList (y.regs Reg.ptr) (Schoening.encodeClauses ψ) y.mem) (hend : y.regs Reg.ptr + (Schoening.encodeClauses ψ).length = y.regs Reg.cEnd) (hfnd : y.regs Reg.fnd = f.toNat) (hce : WordRAM.Fits w (y.regs Reg.cEnd)) :

The clause loop. From ptr at the encoding of the clauses ψ, which end at cEnd, and fnd = f, the loop ends with fnd = f || ψ.any (unitTest τ x b) and unchanged memory.

The unit-clause scan. From the clauses of φ stored in [cBeg, cEnd), the scan reports whether φ has a unit clause on x with polarity b under τ, within 14 E + 4 instructions, where E is the length of the encoding, and leaves memory unchanged.

The forced value. From the clauses of φ stored in [cBeg, cEnd) and the partial assignment τ stored at tBase, forcedCode stores optCode (forced φ τ x) in res within 28 E + 15 instructions, where E is the length of the encoding, and leaves memory unchanged.