Documentation

CslibFrontier.Algorithms.WordRAM.PPSZ.Implied

w-implication on the word RAM #

Cslib.Algorithms.WordRAM.PPSZ.impliedCode computes the value w-implied on a variable (Cslib.Complexity.PPSZ.implied), the oracle of PPSZ. The formula is stored as in Cslib.Algorithms.WordRAM.Schoening.encodeClauses, the partial assignment as in Cslib.Algorithms.WordRAM.PPZ.PartialAt, and the bound s on the number of clauses is stored in the word after a scratch base address. The program runs the search Cslib.Algorithms.WordRAM.PPSZ.addrTest for the polarity true, then, if needed, for false:

Both odometers step with Cslib.Algorithms.WordRAM.PPSZ.nextSection, so they visit every section (Cslib.Algorithms.WordRAM.PPSZ.nextSection_sections). The arrays D and E take 2 s words of scratch memory, which the program sets back to zero at the end. On scratch memory that starts out zero, Cslib.Algorithms.WordRAM.PPSZ.impliedCode_spec therefore leaves memory unchanged and stores the word of implied φ s τ x.

Main definitions #

Main results #

References #

Registers #

@[reducible, inline]

The bound s on the number of clauses.

@[reducible, inline]

Address of the array D of chosen clause addresses.

@[reducible, inline]

Address of the array E of chosen literal addresses, dBase + s.

@[reducible, inline]

Index into D and E.

@[reducible, inline]

Second index into E.

@[reducible, inline]

Scratch address.

@[reducible, inline]

A clause address.

@[reducible, inline]

A literal address.

@[reducible, inline]

A clause length, or a word of the partial assignment.

@[reducible, inline]

An end address, or a comparison value.

@[reducible, inline]

A literal code.

@[reducible, inline]

A variable, or the code of the complementary literal.

@[reducible, inline]

The result of a test or search.

@[reducible, inline]

Whether the clause odometer continues.

@[reducible, inline]

Whether the literal odometer continues.

@[reducible, inline]

A sign.

structure Cslib.Algorithms.WordRAM.PPSZ.ImpFrame {n : ℕ} (w : ℕ) (φ : Logic.PL.CNF (Fin n)) (τ : Fin n → Option Bool) (x : Fin n) (b : Bool) (C Tb s Db : ℕ) (y : WordRAM.Data 32) :

The registers and memory the search relies on: the constants, the variable x, the polarity b, the clauses of φ stored from C, the partial assignment τ stored from Tb, the bound s, and the arrays D at Db and E at Db + s, above the clauses, the partial assignment and the literal codes.

theorem Cslib.Algorithms.WordRAM.PPSZ.ImpFrame.congr {n w : ℕ} {φ : Logic.PL.CNF (Fin n)} {τ : Fin n → Option Bool} {x : Fin n} {b : Bool} {C Tb s Db : ℕ} {y z : WordRAM.Data 32} (h : ImpFrame w φ τ x b C Tb s Db y) (hr : ∀ i ∈ {PPZ.Reg.zero, PPZ.Reg.one, PPZ.Reg.xReg, PPZ.Reg.bReg, PPZ.Reg.cBeg, PPZ.Reg.cEnd, PPZ.Reg.tBase, Reg.sReg, Reg.dBase, Reg.eBase}, z.regs i = y.regs i) (hm : ∀ a < Db, z.mem a = y.mem a) :
ImpFrame w φ τ x b C Tb s Db z

The frame survives a change that keeps its registers and the memory below Db.

theorem Cslib.Algorithms.WordRAM.PPSZ.ImpFrame.set {n w : ℕ} {φ : Logic.PL.CNF (Fin n)} {τ : Fin n → Option Bool} {x : Fin n} {b : Bool} {C Tb s Db : ℕ} {y : WordRAM.Data 32} (h : ImpFrame w φ τ x b C Tb s Db y) {i : Fin 32} (hi : i ∉ {PPZ.Reg.zero, PPZ.Reg.one, PPZ.Reg.xReg, PPZ.Reg.bReg, PPZ.Reg.cBeg, PPZ.Reg.cEnd, PPZ.Reg.tBase, Reg.sReg, Reg.dBase, Reg.eBase}) (v : ℕ) :
ImpFrame w φ τ x b C Tb s Db (y.set i v)

The frame after setting a register outside it.

The clause odometer #

Set D[j], …, D[s - 1] to the first clause address.

Start the clause odometer: every entry of D is the first clause address.

Advance D[j] to the next clause address, or, after the last clause, return it to the first one and carry into D[j + 1]. Without a carry, jR becomes s + 1 and the loop stops.

The carries of the clause odometer from D[j] on.

Step the clause odometer: contO becomes 0 after the last choice of clauses, and 1 otherwise.

theorem Cslib.Algorithms.WordRAM.PPSZ.initD_spec {n w : ℕ} {φ : Logic.PL.CNF (Fin n)} {τ : Fin n → Option Bool} {x : Fin n} {b : Bool} {C Tb s Db : ℕ} (y : WordRAM.Data 32) (hf : ImpFrame w φ τ x b C Tb s Db y) :
∃ (z : WordRAM.Data 32), WordRAM.ExecWithin w initD y z (5 * s + 3) ∧ ImpFrame w φ τ x b C Tb s Db z ∧ WordRAM.Block.HoldsList Db (List.replicate s C) z.mem ∧ ∀ (a : ℕ), a < Db ∨ Db + s ≤ a → z.mem a = y.mem a

Start the clause odometer: D holds s copies of the first clause address, and the memory outside D is unchanged, within 5 s + 3 instructions.

theorem Cslib.Algorithms.WordRAM.PPSZ.incD_spec {n w : ℕ} {φ : Logic.PL.CNF (Fin n)} {τ : Fin n → Option Bool} {x : Fin n} {b : Bool} {C Tb s Db : ℕ} (t : List ℕ) (y : WordRAM.Data 32) (hf : ImpFrame w φ τ x b C Tb s Db y) (ht : t ∈ (List.replicate s (clauseAddrs C φ)).sections) (hl : WordRAM.Block.HoldsList Db t y.mem) :
∃ (z : WordRAM.Data 32), WordRAM.ExecWithin w incD y z (12 * s + 4) ∧ ImpFrame w φ τ x b C Tb s Db z ∧ (∀ (a : ℕ), a < Db ∨ Db + s ≤ a → z.mem a = y.mem a) ∧ (∀ (t' : List ℕ), nextSection (List.replicate s (clauseAddrs C φ)) t = some t' → z.regs Reg.contO = 1 ∧ WordRAM.Block.HoldsList Db t' z.mem) ∧ (nextSection (List.replicate s (clauseAddrs C φ)) t = none → z.regs Reg.contO = 0)

Step the clause odometer on a choice t of s clause addresses in D: if the odometer step on t has a result, D holds it and contO = 1; if not, contO = 0. The memory outside D is unchanged, within 12 s + 4 instructions.

The literal odometer #

The addresses of the literal codes of the clause stored at address p.

Set E[j] to the first literal address of the clause D[j], and clear sat if that clause is empty.

Start the literal odometer: every entry of E is the first literal address of its clause, and sat = 1 exactly when no chosen clause is empty.

Advance E[j] to the next literal address of the clause D[j], or, after its last literal, return it to the first one and carry into E[j + 1]. Without a carry, jR becomes s + 1 and the loop stops.

The carries of the literal odometer from E[j] on.

Step the literal odometer: contI becomes 0 after the last choice of literals, and 1 otherwise.

theorem Cslib.Algorithms.WordRAM.PPSZ.initE_spec {n w : ℕ} {φ : Logic.PL.CNF (Fin n)} {τ : Fin n → Option Bool} {x : Fin n} {b : Bool} {C Tb s Db : ℕ} (t : List ℕ) (y : WordRAM.Data 32) (hf : ImpFrame w φ τ x b C Tb s Db y) (ht : t ∈ (List.replicate s (clauseAddrs C φ)).sections) (hl : WordRAM.Block.HoldsList Db t y.mem) :
∃ (z : WordRAM.Data 32), WordRAM.ExecWithin w initE y z (12 * s + 4) ∧ ImpFrame w φ τ x b C Tb s Db z ∧ (∀ (a : ℕ), a < Db + s ∨ Db + 2 * s ≤ a → z.mem a = y.mem a) ∧ WordRAM.Block.HoldsList (Db + s) (List.map (fun (x : ℕ) => x + 1) t) z.mem ∧ z.regs Reg.sat = (t.all fun (a : ℕ) => List.length (clauseOf C φ a) != 0).toNat

Start the literal odometer on a choice t of s clause addresses in D: E holds their first literal addresses, sat = 1 exactly when none of the clauses is empty, D is kept, and the memory outside E is unchanged, within 12 s + 4 instructions.

theorem Cslib.Algorithms.WordRAM.PPSZ.incE_spec {n w : ℕ} {φ : Logic.PL.CNF (Fin n)} {τ : Fin n → Option Bool} {x : Fin n} {b : Bool} {C Tb s Db : ℕ} (t e : List ℕ) (y : WordRAM.Data 32) (hf : ImpFrame w φ τ x b C Tb s Db y) (ht : t ∈ (List.replicate s (clauseAddrs C φ)).sections) (hl : WordRAM.Block.HoldsList Db t y.mem) (hle : WordRAM.Block.HoldsList (Db + s) e y.mem) (he : e ∈ (List.map (litAddrs C φ) t).sections) :
∃ (z : WordRAM.Data 32), WordRAM.ExecWithin w incE y z (14 * s + 4) ∧ ImpFrame w φ τ x b C Tb s Db z ∧ (∀ (a : ℕ), a < Db + s ∨ Db + 2 * s ≤ a → z.mem a = y.mem a) ∧ (∀ (e' : List ℕ), nextSection (List.map (litAddrs C φ) t) e = some e' → z.regs Reg.contI = 1 ∧ WordRAM.Block.HoldsList (Db + s) e' z.mem) ∧ (nextSection (List.map (litAddrs C φ) t) e = none → z.regs Reg.contI = 0)

Step the literal odometer on clause addresses t in D and a choice e of one literal address of each in E: if the odometer step on e has a result, E holds it and contI = 1; if not, contI = 0. The memory outside E is unchanged, within 14 s + 4 instructions.

The compatibility test #

Compare the literal code at E[k] with auxR, the code of the complementary literal, and clear sat if they are equal.

Compare the literal codes at E[k], …, E[s - 1] with auxR.

Read the literal code at E[j] and clear sat if the literal is falsified: on x when its sign is b, and elsewhere when the partial assignment sets its variable to the other sign.

Test the literal at E[j]: it is not falsified, and no literal of E is its complement.

The compatibility test: sat = 1 exactly when the literals at the addresses in E are compatible with the partial assignment with x set to !b.

theorem Cslib.Algorithms.WordRAM.PPSZ.xor_one_lt {c m : ℕ} (h : c < 2 * m) :
c ^^^ 1 < 2 * m

The code of the complementary literal stays below 2 n.

The time of the compatibility test on s literals.

theorem Cslib.Algorithms.WordRAM.PPSZ.goodTest_spec {n w : ℕ} {φ : Logic.PL.CNF (Fin n)} {τ : Fin n → Option Bool} {x : Fin n} {b : Bool} {C Tb s Db : ℕ} (El : List ℕ) (hlen : El.length = s) (y : WordRAM.Data 32) (hf : ImpFrame w φ τ x b C Tb s Db y) (hEl : WordRAM.Block.HoldsList (Db + s) El y.mem) (hcodes : ∀ p ∈ El, y.mem p < 2 * n) :
∃ (z : WordRAM.Data 32), WordRAM.ExecWithin w goodTest y z (goodTime s) ∧ z.mem = y.mem ∧ z.regs Reg.sat = (compatCodes (fun (v : ℕ) => y.mem (Tb + v)) (↑x) b.toNat (List.map y.mem El)).toNat

The compatibility test: sat = 1 exactly when the literal codes at the addresses El in E are compatible (compatCodes), within goodTime s instructions. The memory is unchanged.

Sections: shape and size #

With an empty list among L, there is no section.

theorem Cslib.Algorithms.WordRAM.PPSZ.sections_eq_cons_headD {α : Type u_1} (d : α) {L : List (List α)} :
(∀ l ∈ L, l ≠ []) → ∃ (xs : List (List α)), L.sections = List.map (fun (x : List α) => x.headD d) L :: xs

Without an empty list among L, the first section picks the first entry of every list.

theorem Cslib.Algorithms.WordRAM.PPSZ.length_sections_le {α : Type u_1} {m : ℕ} {L : List (List α)} :
(∀ l ∈ L, l.length ≤ m) → L.sections.length ≤ m ^ L.length

The number of sections of lists of length at most m.

theorem Cslib.Algorithms.WordRAM.PPSZ.all_congr_of_mem {α : Type u_1} {l : List α} {f g : α → Bool} (h : ∀ a ∈ l, f a = g a) :
l.all f = l.all g

List.all depends only on the values of the test on the list.

theorem Cslib.Algorithms.WordRAM.PPSZ.lt_of_mem_litAddrs {n C : ℕ} {φ : Logic.PL.CNF (Fin n)} {a : ℕ} (ha : a ∈ clauseAddrs C φ) {p : ℕ} (hp : p ∈ litAddrs C φ a) :

The literal addresses of a clause address lie in the encoding of the clauses.

A clause has at most as many literals as the encoding has words.

There are at most as many clauses as the encoding has words.

The search over choices of literals #

One step of the literal search: test the current choice, and stop if it is compatible; otherwise step the odometer.

The literal search from the current choice on.

The literal search: sat = 1 exactly when some choice of one literal address from each clause in D is compatible.

The time of one step of the literal search.

The time of the literal search, with at most E ^ s choices of literals.

def Cslib.Algorithms.WordRAM.PPSZ.litOk {n : ℕ} (m : ℕ → ℕ) (Tb : ℕ) (x : Fin n) (b : Bool) (e : List ℕ) :

The test of the literal search, on the memory m.

theorem Cslib.Algorithms.WordRAM.PPSZ.litOk_congr {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {x : Fin n} {b : Bool} {C Tb s Db : ℕ} {t : List ℕ} (ht : t ∈ (List.replicate s (clauseAddrs C φ)).sections) {m₁ m₂ : ℕ → ℕ} (hcl : WordRAM.Block.HoldsList C (Schoening.encodeClauses φ) m₁) (hle : C + (Schoening.encodeClauses φ).length ≤ Db) (hTb : Tb + n ≤ Db) (hm : ∀ a < Db, m₂ a = m₁ a) {e : List ℕ} (he : e ∈ (List.map (litAddrs C φ) t).sections) :
litOk m₂ Tb x b e = litOk m₁ Tb x b e

The test of the literal search reads only memory below Db.

theorem Cslib.Algorithms.WordRAM.PPSZ.innerSearch_spec {n w : ℕ} {φ : Logic.PL.CNF (Fin n)} {τ : Fin n → Option Bool} {x : Fin n} {b : Bool} {C Tb s Db : ℕ} (t : List ℕ) (ht : t ∈ (List.replicate s (clauseAddrs C φ)).sections) (y : WordRAM.Data 32) (hf : ImpFrame w φ τ x b C Tb s Db y) (hl : WordRAM.Block.HoldsList Db t y.mem) :
∃ (z : WordRAM.Data 32), WordRAM.ExecWithin w innerSearch y z (innerTime s (Schoening.encodeClauses φ).length) ∧ ImpFrame w φ τ x b C Tb s Db z ∧ (∀ (a : ℕ), a < Db + s ∨ Db + 2 * s ≤ a → z.mem a = y.mem a) ∧ z.regs Reg.sat = ((List.map (litAddrs C φ) t).sections.any (litOk y.mem Tb x b)).toNat

The literal search on a choice t of s clause addresses in D: sat = 1 exactly when some choice of one literal address from each clause is compatible, within innerTime s E instructions, where E is the length of the encoding of the clauses. The memory outside E is unchanged.

The search over choices of clauses #

One step of the clause search: search the choices of literals, and stop if none is compatible; otherwise step the odometer.

The clause search from the current choice on.

The clause search: sat = 0 exactly when some choice of s clause addresses has no compatible choice of literals.

The time of one step of the clause search.

The time of the clause search, with at most E ^ s choices of clauses.

def Cslib.Algorithms.WordRAM.PPSZ.clauseOk {n : ℕ} (m : ℕ → ℕ) (C Tb : ℕ) (φ : Logic.PL.CNF (Fin n)) (x : Fin n) (b : Bool) (t : List ℕ) :

The test of the clause search: the clauses at the addresses t have a compatible choice of literals, on the memory m.

theorem Cslib.Algorithms.WordRAM.PPSZ.outerSearch_spec {n w : ℕ} {φ : Logic.PL.CNF (Fin n)} {τ : Fin n → Option Bool} {x : Fin n} {b : Bool} {C Tb s Db : ℕ} (hφ : φ ≠ []) (y : WordRAM.Data 32) (hf : ImpFrame w φ τ x b C Tb s Db y) :
∃ (z : WordRAM.Data 32), WordRAM.ExecWithin w outerSearch y z (outerTime s (Schoening.encodeClauses φ).length) ∧ ImpFrame w φ τ x b C Tb s Db z ∧ (∀ (a : ℕ), a < Db ∨ Db + 2 * s ≤ a → z.mem a = y.mem a) ∧ z.regs Reg.sat = ((List.replicate s (clauseAddrs C φ)).sections.all (clauseOk y.mem C Tb φ x b)).toNat

The clause search, on a nonempty formula: sat = 1 exactly when every choice of s clause addresses has a compatible choice of literals, within outerTime s E instructions. The memory outside D and E is unchanged.

Deciding w-implication #

Load the word of x in the partial assignment.

The w-implication search for x = b: sat = 0 exactly when the partial assignment sets x to b, or some choice of s clauses has no compatible choice of literals with x set to !b.

The time of the w-implication search.

theorem Cslib.Algorithms.WordRAM.PPSZ.impScan_spec {n w : ℕ} {φ : Logic.PL.CNF (Fin n)} {τ : Fin n → Option Bool} {x : Fin n} {b : Bool} {C Tb s Db : ℕ} (y : WordRAM.Data 32) (hf : ImpFrame w φ τ x b C Tb s Db y) :
∃ (z : WordRAM.Data 32), WordRAM.ExecWithin w impScan y z (impScanTime s (Schoening.encodeClauses φ).length) ∧ ImpFrame w φ τ x b C Tb s Db z ∧ (∀ (a : ℕ), a < Db ∨ Db + 2 * s ≤ a → z.mem a = y.mem a) ∧ z.regs Reg.sat = (!Complexity.PPSZ.impliedTest φ s τ x b).toNat

The w-implication search decides w-implication: sat = 0 exactly when x = b is s-implied under τ (through Cslib.Complexity.PPSZ.impliedTest), within impScanTime s E instructions. The memory outside D and E is unchanged.

The implied value #

Set the words jR, …, 2 s - 1 after dBase to zero.

Read the bound s from the word at tBase + 2 n, set the addresses of D and E just after it, and start with the polarity true.

The value w-implied on xReg, stored in res as optCode (implied φ s τ x). The bound s is read from the word at tBase + 2 n, and the arrays D and E take the 2 s words after it, which are cleared at the end.

The instruction bound of impliedCode for the bound s and a clause encoding of length E: two searches over at most E ^ s choices of clauses, each with at most E ^ s choices of literals.

theorem Cslib.Algorithms.WordRAM.PPSZ.impliedTime_le (s E : ℕ) :
impliedTime s E ≤ 140 * (s + 1) ^ 2 * (E + 1) ^ (2 * s)

The instruction bound in closed form: impliedTime s E ≤ 140 (s + 1)² (E + 1)^(2 s).

theorem Cslib.Algorithms.WordRAM.PPSZ.ImpFrame.setB {n w : ℕ} {φ : Logic.PL.CNF (Fin n)} {τ : Fin n → Option Bool} {x : Fin n} {b : Bool} {C Tb s Db : ℕ} {y : WordRAM.Data 32} (h : ImpFrame w φ τ x b C Tb s Db y) (b' : Bool) :
ImpFrame w φ τ x b' C Tb s Db (y.set PPZ.Reg.bReg b'.toNat)

The frame with another polarity.

theorem Cslib.Algorithms.WordRAM.PPSZ.impliedCode_spec {n w : ℕ} (φ : Logic.PL.CNF (Fin n)) (τ : Fin n → Option Bool) (x : Fin n) (s : ℕ) {C Tb : ℕ} (y : WordRAM.Data 32) (hz : y.regs PPZ.Reg.zero = 0) (ho : y.regs PPZ.Reg.one = 1) (htwo : y.regs PPZ.Reg.two = 2) (hx : y.regs PPZ.Reg.xReg = ↑x) (hC : y.regs PPZ.Reg.cBeg = C) (hCe : y.regs PPZ.Reg.cEnd = C + (Schoening.encodeClauses φ).length) (hTb : y.regs PPZ.Reg.tBase = Tb) (hn : y.regs PPZ.Reg.nReg = n) (hcl : WordRAM.Block.HoldsList C (Schoening.encodeClauses φ) y.mem) (hτ : PPZ.PartialAt y.mem Tb τ) (hle : C + (Schoening.encodeClauses φ).length ≤ Tb) (hs : y.mem (Tb + 2 * n) = s) (hzero : ∀ i < 2 * s, y.mem (Tb + 2 * n + 1 + i) = 0) (hw : WordRAM.Fits w (Tb + 2 * n + 2 * s + 2)) :

The value w-implied on x. From the clauses of φ stored in [cBeg, cEnd) below the partial assignment τ stored at tBase = Tb, the bound s stored at Tb + 2 n and 2 s zero words after it, impliedCode stores optCode (implied φ s τ x) in res within impliedTime s E instructions, where E is the length of the encoding of the clauses, and leaves memory unchanged.