Documentation

CslibFrontier.Algorithms.WordRAM.PPZ.Round

One round of PPZ on the randomized word RAM #

Cslib.Algorithms.WordRAM.PPZ.roundProgram is one round of the PPZ algorithm Paturi, Pudlák, Zane as a program of the randomized word RAM (Cslib.WordRAM.runRand). On the input encode φ, the number n of variables followed by the clauses of φ : CNF (Fin n), it

  1. stores the empty partial assignment τ (the word 2 for every variable) and the array P = [0, 1, …, n - 1] just after the input;
  2. for i = 0, …, n - 1: draws j uniformly from [i, n), swaps P[i] and P[j], and sets the variable x = P[i] to its forced value (Cslib.Complexity.PPZ.forced, computed by Cslib.Algorithms.WordRAM.PPZ.forcedCode), or to a uniform bit if it has none;
  3. halts with output 1 if the assignment it built satisfies φ, and 0 otherwise.

Step 2 is the Fisher–Yates shuffle, run lazily: the variables still to be processed are P[i], …, P[n - 1], and the swap brings a uniformly chosen one of them to position i. This is exactly the recursion Cslib.Complexity.PPZ.roundOn_succ, so each iteration of the loop matches one step of Cslib.Complexity.PPZ.roundOn (Cslib.Algorithms.WordRAM.PPZ.roundLoop_law), and Cslib.Complexity.PPZ.roundWith_eq_roundOn identifies the whole loop with a round.

Cslib.Algorithms.WordRAM.PPZ.roundProgram_spec proves that the program halts on every path within roundTime n L = n (28 L + 40) + 12 L + 19 instructions, where L is the input length, makes at most 2 n rand calls, reports correctly whether the assignment it leaves satisfies φ, and that the law of that assignment is exactly Cslib.Complexity.PPZ.round φ. The PPZ success bound Cslib.Complexity.PPZ.round_success_of_satisfiable therefore applies to the program. Time is the instruction count of the word RAM with unit-cost rand (Cslib.WordRAM.stepRand); every instruction counts, including loop tests and jumps.

The loop takes its oracle as a parameter: Cslib.Algorithms.WordRAM.PPZ.roundCoreWith oc runs the round with any oracle code oc that meets the contract Cslib.Algorithms.WordRAM.PPZ.IsOracleCode for an oracle O, and has the law of Cslib.Complexity.PPZ.roundWith O (Cslib.Algorithms.WordRAM.PPZ.roundCoreWith_law). PPZ is the case oc = forcedCode (Cslib.Algorithms.WordRAM.PPZ.forcedCode_isOracleCode); PPSZ uses the w-implication search (Cslib.Algorithms.WordRAM.PPSZ.roundProgram).

The final check reuses Schöning's clause scan Cslib.Algorithms.WordRAM.Schoening.scan, renamed into the register file of this program along Cslib.Algorithms.WordRAM.PPZ.embed.

Main definitions #

Main results #

References #

Reading partial assignments #

The value of a partial assignment stored as the word v: 0 and 1 are set values, any other word is unset.

The partial assignment read from the n words at address base.

theorem Cslib.Algorithms.WordRAM.PPZ.partialAssignmentAt_eq {n : ℕ} {mem : ℕ → ℕ} {base : ℕ} {τ : Fin n → Option Bool} (h : PartialAt mem base τ) :
partialAssignmentAt mem base n = τ

Reading back a stored partial assignment.

Registers #

@[reducible, inline]

Address of the order array P.

@[reducible, inline]

The step i.

@[reducible, inline]

The drawn position j.

@[reducible, inline]

The address of P[i].

@[reducible, inline]

The address of P[j].

@[reducible, inline]

Output.

@[reducible, inline]

Where the renamed Schöning scan reports a falsified clause (embed Cslib.Algorithms.WordRAM.Schoening.Reg.found).

The frame of a round #

structure Cslib.Algorithms.WordRAM.PPZ.RoundFrame {n : ℕ} (φ : Logic.PL.CNF (Fin n)) (C Tb : ℕ) (M : ℕ → ℕ) (x : WordRAM.Data 32) :

The registers and memory a round relies on: the constants, the clauses of φ stored in [C, Tb), the partial assignment's address Tb, the order array's address Tb + n, and n. The memory from address Tb + 2 n on, just after the order array, agrees with M; a round never writes there.

theorem Cslib.Algorithms.WordRAM.PPZ.RoundFrame.congr {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {C Tb : ℕ} {M : ℕ → ℕ} {x y : WordRAM.Data 32} (h : RoundFrame φ C Tb M x) (hz : y.regs Reg.zero = x.regs Reg.zero) (ho : y.regs Reg.one = x.regs Reg.one) (ht : y.regs Reg.two = x.regs Reg.two) (hc : y.regs Reg.cBeg = x.regs Reg.cBeg) (he : y.regs Reg.cEnd = x.regs Reg.cEnd) (hb : y.regs Reg.tBase = x.regs Reg.tBase) (hn : y.regs Reg.nReg = x.regs Reg.nReg) (hp : y.regs Reg.pBase = x.regs Reg.pBase) (hmem : ∀ (a : ℕ), a < Tb ∨ Tb + 2 * n ≤ a → y.mem a = x.mem a) :
RoundFrame φ C Tb M y

The frame survives any change that keeps its registers and the memory outside [Tb, Tb + 2 n).

theorem Cslib.Algorithms.WordRAM.PPZ.RoundFrame.self {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {C Tb : ℕ} {M : ℕ → ℕ} {x : WordRAM.Data 32} (h : RoundFrame φ C Tb M x) :
RoundFrame φ C Tb x.mem x

The frame with the memory after the order array taken as it is.

Code that writes none of the frame registers.

Instances For
    theorem Cslib.Algorithms.WordRAM.PPZ.RoundFrame.of_execWithin {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {C Tb : ℕ} {M : ℕ → ℕ} {c : WordRAM.Code WordRAM.Basis.standard 32} {x y : WordRAM.Data 32} {w T : ℕ} (h : RoundFrame φ C Tb M x) (hc : PreservesRound c) (he : WordRAM.ExecWithin w c x y T) (hmem : ∀ (a : ℕ), a < Tb ∨ Tb + 2 * n ≤ a → y.mem a = x.mem a) :
    RoundFrame φ C Tb M y

    A deterministic run of frame-preserving code that keeps the memory outside [Tb, Tb + 2 n) keeps the frame.

    theorem Cslib.Algorithms.WordRAM.PPZ.RoundFrame.set {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {C Tb : ℕ} {M : ℕ → ℕ} {x : WordRAM.Data 32} (h : RoundFrame φ C Tb M x) {i : Fin 32} (hi : i ∉ {Reg.zero, Reg.one, Reg.two, Reg.cBeg, Reg.cEnd, Reg.tBase, Reg.nReg, Reg.pBase}) (v : ℕ) :
    RoundFrame φ C Tb M (x.set i v)

    The frame after setting a register outside it.

    The initial arrays #

    Store τ[i] = 2 (unset) and P[i] = i, and count.

    Initialize the entries iReg, …, n - 1 of both arrays.

    theorem Cslib.Algorithms.WordRAM.PPZ.initLoop_spec {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {C Tb w : ℕ} {M : ℕ → ℕ} (hw : WordRAM.Fits w (Tb + 2 * n)) (d : ℕ) (x : WordRAM.Data 32) :
    RoundFrame φ C Tb M x → x.regs Reg.iReg + d = n → (∀ v < x.regs Reg.iReg, x.mem (Tb + v) = 2 ∧ x.mem (Tb + n + v) = v) → ∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w initLoop x y (7 * d + 2) ∧ RoundFrame φ C Tb M y ∧ ∀ v < n, y.mem (Tb + v) = 2 ∧ y.mem (Tb + n + v) = v

    The initial arrays from entry i on: the first i entries of both arrays are stored, and the loop stores the others.

    One step of the round #

    Swap P[i] and P[j], where jReg holds the draw j - i, and load the new P[i] into xReg.

    Without a forced value, draw a uniform bit.

    One step of a round with the oracle code oc: draw j - i uniformly from [0, n - 1 - i], swap P[i] and P[j], and set x = P[i] to the oracle's value or to a uniform bit.

    One step of a round of PPZ: set x = P[i] to its forced value or to a uniform bit.

    The steps of a round with the oracle code oc: steps iReg, …, n - 1.

    The steps of a round of PPZ: steps iReg, …, n - 1.

    structure Cslib.Algorithms.WordRAM.PPZ.LoopState {n : ℕ} (φ : Logic.PL.CNF (Fin n)) (C Tb : ℕ) (M : ℕ → ℕ) (i : ℕ) (τ : Fin n → Option Bool) {d : ℕ} (g : Fin d → Fin n) (x : WordRAM.Data 32) :

    The state at the head of the round loop at step i: the frame, iReg = i, the partial assignment τ stored at Tb, and the unprocessed variables g 0, …, g (d - 1) stored at P[i], P[i + 1], …. Every variable that τ leaves unset is among them.

    theorem Cslib.Algorithms.WordRAM.PPZ.RoundFrame.scanFrame {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {C Tb w : ℕ} {M : ℕ → ℕ} {y : WordRAM.Data 32} (h : RoundFrame φ C Tb M y) {τ : Fin n → Option Bool} {v : Fin n} (hv : y.regs Reg.xReg = ↑v) (hs : PartialAt y.mem Tb τ) (hw : WordRAM.Fits w (Tb + 2 * n)) (hT : 1 ≤ Tb) :
    ScanFrame w τ v y

    The scan frame of a round frame, for the variable in xReg and the partial assignment stored at Tb.

    structure Cslib.Algorithms.WordRAM.PPZ.IsOracleCode {n : ℕ} (w : ℕ) (φ : Logic.PL.CNF (Fin n)) (C Tb : ℕ) (M : ℕ → ℕ) (O : (Fin n → Option Bool) → Fin n → Option Bool) (oc : WordRAM.Code WordRAM.Basis.standard 32) (T : ℕ) :

    The contract of an oracle code oc for the oracle O within T instructions, on rounds with the frame RoundFrame φ C Tb M: from the frame, with a variable v in xReg and a partial assignment τ stored at Tb, the code stores optCode (O τ v) in res and leaves memory unchanged. It writes none of the frame registers, xReg, iReg or jReg.

    theorem Cslib.Algorithms.WordRAM.PPZ.forcedCode_isOracleCode {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {C Tb w : ℕ} {M : ℕ → ℕ} (hw : WordRAM.Fits w (Tb + 2 * n)) (hT : 1 ≤ Tb) :

    The forced-value scan is an oracle code for Cslib.Complexity.PPZ.forced φ, within 28 E + 15 instructions (Cslib.Algorithms.WordRAM.PPZ.forcedCode_spec).

    def Cslib.Algorithms.WordRAM.PPZ.StepPost {n : ℕ} (φ : Logic.PL.CNF (Fin n)) (C Tb : ℕ) (M : ℕ → ℕ) (i : ℕ) (τ : Fin n → Option Bool) {m : ℕ} (g : Fin (m + 1) → Fin n) (y : WordRAM.Data 32) :

    The postcondition of the step from step i:for the drawn position p and the value b set, jReg = i + p, res = b, and the loop state at step i + 1 after processing g p.

    theorem Cslib.Algorithms.WordRAM.PPZ.roundBodyWith_law {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {C Tb w T : ℕ} {M : ℕ → ℕ} {O : (Fin n → Option Bool) → Fin n → Option Bool} {oc : WordRAM.Code WordRAM.Basis.standard 32} (hoc : IsOracleCode w φ C Tb M O oc T) (hw : WordRAM.Fits w (Tb + 2 * n)) {i m : ℕ} {τ : Fin n → Option Bool} {g : Fin (m + 1) → Fin n} {x : WordRAM.Data 32} (hx : LoopState φ C Tb M i τ g x) (hd : i + (m + 1) = n) :
    WordRAM.ExecRandLaw w (roundBodyWith oc) x (StepPost φ C Tb M i τ g) (T + 16) 2 (fun (y : WordRAM.Data 32) => (y.regs Reg.jReg - i, decide (y.regs Reg.res = 1))) ((Probability.PMF.uniformOfFintype (Fin (m + 1))).bind fun (p : Fin (m + 1)) => PMF.map (fun (b : Bool) => (↑p, b)) (Complexity.PPZ.stepWith O τ (g p)))

    One step of a round with an oracle code draws the position p uniformly from the m + 1 unprocessed positions and sets g p with the law of Cslib.Complexity.PPZ.stepWith O, within T + 16 instructions and two rand calls, where T bounds the oracle code.

    theorem Cslib.Algorithms.WordRAM.PPZ.roundBody_law {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {C Tb w : ℕ} {M : ℕ → ℕ} (hw : WordRAM.Fits w (Tb + 2 * n)) (hT : 1 ≤ Tb) {i m : ℕ} {τ : Fin n → Option Bool} {g : Fin (m + 1) → Fin n} {x : WordRAM.Data 32} (hx : LoopState φ C Tb M i τ g x) (hd : i + (m + 1) = n) :
    WordRAM.ExecRandLaw w roundBody x (StepPost φ C Tb M i τ g) (28 * (Schoening.encodeClauses φ).length + 31) 2 (fun (y : WordRAM.Data 32) => (y.regs Reg.jReg - i, decide (y.regs Reg.res = 1))) ((Probability.PMF.uniformOfFintype (Fin (m + 1))).bind fun (p : Fin (m + 1)) => PMF.map (fun (b : Bool) => (↑p, b)) (Complexity.PPZ.stepWith (Complexity.PPZ.forced φ) τ (g p)))

    One step of a round of PPZ draws the position p uniformly from the m + 1 unprocessed positions and sets g p with the law of Cslib.Complexity.PPZ.step, within 28 E + 31 instructions and two rand calls.

    theorem Cslib.Algorithms.WordRAM.PPZ.roundLoopWith_law {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {C Tb w T : ℕ} {M : ℕ → ℕ} {O : (Fin n → Option Bool) → Fin n → Option Bool} {oc : WordRAM.Code WordRAM.Basis.standard 32} (hoc : IsOracleCode w φ C Tb M O oc T) (hw : WordRAM.Fits w (Tb + 2 * n)) (d i : ℕ) (τ : Fin n → Option Bool) (g : Fin d → Fin n) (x : WordRAM.Data 32) :
    LoopState φ C Tb M i τ g x → i + d = n → WordRAM.ExecRandLaw w (roundLoopWith oc) x (fun (y : WordRAM.Data 32) => RoundFrame φ C Tb M y ∧ ∀ v < n, y.mem (Tb + v) ≤ 1) (d * (T + 18) + 2) (2 * d) (fun (y : WordRAM.Data 32) => partialAssignmentAt y.mem Tb n) (Complexity.PPZ.roundOn O g τ)

    The steps of a round with an oracle code from step i, with the unprocessed variables g 0, …, g (d - 1), have the law of roundOn O g τ, take d (T + 18) + 2 instructions and 2 d rand calls, and leave every variable set, where T bounds the oracle code.

    theorem Cslib.Algorithms.WordRAM.PPZ.roundLoop_law {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {C Tb w : ℕ} {M : ℕ → ℕ} (hw : WordRAM.Fits w (Tb + 2 * n)) (hT : 1 ≤ Tb) (d i : ℕ) (τ : Fin n → Option Bool) (g : Fin d → Fin n) (x : WordRAM.Data 32) (hx : LoopState φ C Tb M i τ g x) (hd : i + d = n) :
    WordRAM.ExecRandLaw w roundLoop x (fun (y : WordRAM.Data 32) => RoundFrame φ C Tb M y ∧ ∀ v < n, y.mem (Tb + v) ≤ 1) (d * (28 * (Schoening.encodeClauses φ).length + 33) + 2) (2 * d) (fun (y : WordRAM.Data 32) => partialAssignmentAt y.mem Tb n) (Complexity.PPZ.roundOn (Complexity.PPZ.forced φ) g τ)

    The steps of a round of PPZ from step i, with the unprocessed variables g 0, …, g (d - 1), have the law of roundOn (forced φ) g τ, take d (28 E + 33) + 2 instructions and 2 d rand calls, and leave every variable set.

    The round #

    The body of a round with the oracle code oc: store the empty partial assignment and the array P[i] = i, then process the variables in a lazily drawn uniform order. The clauses are read from [cBeg, cEnd), the partial assignment is stored from tBase and the order array from pBase, and n is read from nReg.

    The instruction bound of a round body on n variables and a clause encoding of length E.

    theorem Cslib.Algorithms.WordRAM.PPZ.roundCoreWith_law {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {C Tb w T : ℕ} {M : ℕ → ℕ} {O : (Fin n → Option Bool) → Fin n → Option Bool} {oc : WordRAM.Code WordRAM.Basis.standard 32} (hoc : IsOracleCode w φ C Tb M O oc T) (hw : WordRAM.Fits w (Tb + 2 * n)) {x : WordRAM.Data 32} (hx : RoundFrame φ C Tb M x) :
    WordRAM.ExecRandLaw w (roundCoreWith oc) x (fun (y : WordRAM.Data 32) => RoundFrame φ C Tb M y ∧ ∀ v < n, y.mem (Tb + v) ≤ 1) (n * (T + 25) + 6) (2 * n) (fun (y : WordRAM.Data 32) => partialAssignmentAt y.mem Tb n) (Complexity.PPZ.roundWith O)

    The body of a round with an oracle code has the law of Cslib.Complexity.PPZ.roundWith O, takes n (T + 25) + 6 instructions, where T bounds the oracle code, keeps the frame, and leaves every variable set.

    theorem Cslib.Algorithms.WordRAM.PPZ.roundCore_law {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {C Tb w : ℕ} {M : ℕ → ℕ} (hw : WordRAM.Fits w (Tb + 2 * n)) (hT : 1 ≤ Tb) {x : WordRAM.Data 32} (hx : RoundFrame φ C Tb M x) :
    WordRAM.ExecRandLaw w roundCore x (fun (y : WordRAM.Data 32) => RoundFrame φ C Tb M y ∧ ∀ v < n, y.mem (Tb + v) ≤ 1) (roundCoreTime n (Schoening.encodeClauses φ).length) (2 * n) (fun (y : WordRAM.Data 32) => partialAssignmentAt y.mem Tb n) (Complexity.PPZ.round φ)

    The body of a round of PPZ has the law of Cslib.Complexity.PPZ.round, keeps the frame, and leaves every variable set.

    The satisfaction check #

    The registers of Schöning's programs (Cslib.Algorithms.WordRAM.Schoening.Reg) inside the register file of PPZ: zero, one and cBeg are shared, Schöning's assignment address aBase and nReg are tBase and nReg, Schöning's scratch registers are PPZ's scan scratch, and the counter registers bBase, bLen and flag of the amplified algorithm are the last three registers.

    The satisfaction check: Schöning's scan of the clauses against the assignment stored at tBase, then out = 1 exactly when no clause is falsified.

    theorem Cslib.Algorithms.WordRAM.PPZ.roundCheck_exec {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {C Tb w : ℕ} {M : ℕ → ℕ} (hw : WordRAM.Fits w (Tb + 2 * n)) (hT : 1 ≤ Tb) {x : WordRAM.Data 32} (hx : RoundFrame φ C Tb M x) (hbits : ∀ v < n, x.mem (Tb + v) ≤ 1) :

    The satisfaction check on a total assignment stored at Tb sets out to whether it satisfies φ, within 12 E + 5 instructions, and keeps the memory and the frame.

    The program #

    Set up the registers of a round on the input encode φ: the clauses start at address 2, the partial assignment is stored just after the input, and the order array just after it.

    One round of PPZ on the input encode φ, as a structured program.

    One round of PPZ on the input encode φ, halting with out.

    The instruction bound of a round on n variables and an input of length L.

    The partial assignment left by a halting run: read from address base.

    The data after the setup of a round on the input encode φ.

    The setup establishes the frame of a round on the input encode φ.

    One round of PPZ on the randomized word RAM. On the input encode φ of length L, at any word size w with L + 2 n + 1 < 2 ^ w, the program

    • halts on every path within roundTime n L = n (28 L + 40) + 12 L + 19 instructions;
    • makes at most 2 n rand calls;
    • outputs 1 exactly when the assignment it leaves at address L + 1 satisfies φ, and that assignment is total: every word is 0 or 1;
    • leaves a partial assignment whose law is exactly Cslib.Complexity.PPZ.round φ.