Documentation

CslibFrontier.Algorithms.WordRAM.PPZ.Amplify

The PPZ algorithm on the randomized word RAM #

Cslib.Algorithms.WordRAM.PPZ.ampProgram is the PPZ k-SAT algorithm Paturi, Pudlák, Zane with confidence c, as a program of the randomized word RAM. On the input k :: c :: encode φ it computes the number of rounds R = ppzRounds k n c = 2 ^ ⌈(k - 1) n / k⌉ c in a multiword counter (Cslib.Algorithms.WordRAM.Schoening.mulAdd), then runs up to R independent rounds (Cslib.Algorithms.WordRAM.PPZ.roundCore), stopping at the first round whose assignment satisfies the formula. It halts with output 1, leaving a satisfying assignment in memory, or with output 0 when every round failed.

Cslib.Algorithms.WordRAM.PPZ.ampProgram_spec proves, at every word size w with L + 2 n + k n + k + 2 c + ppzCounterLen k n c + 2 < 2 ^ w, where L is the input length and ppzCounterLen k n c, which is ⌈(k - 1) n / k⌉ + 1 plus the number of binary digits of c, bounds the number of digits of R:

With the PPZ bound p ≥ 2 ^ (-(1 - 1 / k) n) for one round (Cslib.Complexity.PPZ.round_success_of_satisfiable), the program fails on a satisfiable formula with clauses of at most k ≥ 1 literals with probability at most e ^ (-c) (Cslib.Algorithms.WordRAM.PPZ.ampProgram_failure_le_exp), and it runs in time O((n + L) ^ 2 2 ^ ((1 - 1 / k) n) (c + 1)) (Cslib.Algorithms.WordRAM.PPZ.ampTime_le). Rounding the exponent (1 - 1 / k) n up to an integer costs at most a factor 2 in the number of rounds, and makes the counter's setup a run of zero digits, a single one digit, and one multiply-add by c.

The loop of rounds and the counter's setup take their round body and exponent as parameters: Cslib.Algorithms.WordRAM.PPZ.ampLoopWith core runs rounds with any round body core for an oracle O (Cslib.Algorithms.WordRAM.PPZ.IsRoundCore), with the law of Cslib.Algorithms.WordRAM.PPZ.repeatRoundWith O (Cslib.Algorithms.WordRAM.PPZ.ampLoopWith_law), and Cslib.Algorithms.WordRAM.PPZ.countSetup_spec computes the digits of any 2 ^ e c. The PPSZ algorithm (Cslib.Algorithms.WordRAM.PPSZ.ampProgram) uses both.

Main definitions #

Main results #

References #

Repeated rounds #

Whether the partial assignment τ satisfies φ, reading unset variables as false. A round leaves a total assignment, on which this is satisfaction.

noncomputable def Cslib.Algorithms.WordRAM.PPZ.roundSuccessProbWith {n : ℕ} (O : (Fin n → Option Bool) → Fin n → Option Bool) (φ : Logic.PL.CNF (Fin n)) :

The probability that one round with the oracle O finds a satisfying assignment of φ.

The probability that one round of PPZ finds a satisfying assignment.

noncomputable def Cslib.Algorithms.WordRAM.PPZ.repeatRoundWith {n : ℕ} (O : (Fin n → Option Bool) → Fin n → Option Bool) (φ : Logic.PL.CNF (Fin n)) :

The output of up to R independent rounds with the oracle O, stopping at the first that finds a satisfying assignment of φ: true if some round found one.

noncomputable def Cslib.Algorithms.WordRAM.PPZ.repeatRound {n : ℕ} (φ : Logic.PL.CNF (Fin n)) :

The output of up to R independent rounds of PPZ, stopping at the first success: true if some round found a satisfying assignment.

All R rounds with the oracle O fail with probability (1 - p) ^ R, where p is the success probability of one round.

All R rounds fail with probability (1 - p) ^ R, where p is the success probability of one round.

The success probability of a round is at most 1.

theorem Cslib.Algorithms.WordRAM.PPZ.succeeds_some {n : ℕ} (φ : Logic.PL.CNF (Fin n)) (σ : Fin n → Bool) :
(succeeds φ fun (x : Fin n) => some (σ x)) = Logic.PL.CNF.eval σ φ

A round's success test on a total assignment is satisfaction.

theorem Cslib.Algorithms.WordRAM.PPZ.sum_le_roundSuccessProbWith {n : ℕ} (O : (Fin n → Option Bool) → Fin n → Option Bool) (φ : Logic.PL.CNF (Fin n)) :
∑ σ : Fin n → Bool with Logic.PL.CNF.eval σ φ = true, ((Complexity.PPZ.roundWith O) fun (x : Fin n) => some (σ x)).toReal ≤ roundSuccessProbWith O φ

The success probability of a round is at least the probability that it outputs a satisfying assignment, summed over the satisfying assignments.

theorem Cslib.Algorithms.WordRAM.PPZ.repeatRoundWith_false_le_exp {n : ℕ} {O : (Fin n → Option Bool) → Fin n → Option Bool} {φ : Logic.PL.CNF (Fin n)} {q c : ℝ} {R : ℕ} (hq : q ≤ roundSuccessProbWith O φ) (hR : c ≤ ↑R * q) :

Amplification: if one round succeeds with probability at least q > 0 and c ≤ R q, then R rounds all fail with probability at most e ^ (-c).

theorem Cslib.Algorithms.WordRAM.PPZ.roundSuccessProb_ge {n k : ℕ} (hk : 1 ≤ k) {φ : Logic.PL.CNF (Fin n)} (hsat : φ.Satisfiable) (hlen : ∀ c ∈ φ, List.length c ≤ k) :
2 ^ (-((1 - 1 / ↑k) * ↑n)) ≤ roundSuccessProb φ

The PPZ bound for one round Paturi, Pudlák, Zane: on a satisfiable formula with clauses of at most k ≥ 1 literals, one round succeeds with probability at least 2 ^ (-(1 - 1 / k) n) (Cslib.Complexity.PPZ.round_success_of_satisfiable).

The success test of a stored assignment is the satisfaction test of the stored words.

Registers #

@[reducible, inline]

Base address of the counter digits (embed Cslib.Algorithms.WordRAM.Schoening.Reg.bBase).

@[reducible, inline]

Number of counter digits (embed Cslib.Algorithms.WordRAM.Schoening.Reg.bLen).

@[reducible, inline]

Whether the amplified algorithm runs another round.

@[reducible, inline]

Multiplier of a multiply-add (embed Cslib.Algorithms.WordRAM.Schoening.Reg.mulr); shares register 9 with lend.

@[reducible, inline]

Carry of a multiply-add (embed Cslib.Algorithms.WordRAM.Schoening.Reg.carry); shares register 10 with lit.

@[reducible, inline]

k, during the setup; shares register 6 with ptr.

@[reducible, inline]

c, during the setup; shares register 7 with len.

@[reducible, inline]

The exponent ⌈(k - 1) n / k⌉, during the setup; shares register 8 with lptr.

The counter routines in the register file of PPZ #

theorem Cslib.Algorithms.WordRAM.PPZ.mulAdd_rename_spec {w a cy Bd : ℕ} {ds : List ℕ} {x : WordRAM.Data 32} (hz : x.regs Reg.zero = 0) (hone : x.regs Reg.one = 1) (ha : x.regs Reg.mulr = a) (hc : x.regs Reg.carry = cy) (hl : x.regs Reg.bLen = ds.length) (hh : WordRAM.Block.HoldsList (x.regs Reg.bBase) ds x.mem) (hds : ∀ d ∈ ds, d ≤ 1) (haB : a ≤ Bd) (hcB : cy ≤ Bd) (hf : WordRAM.Fits w (2 * Bd)) (hfit : WordRAM.Fits w (x.regs Reg.bBase + (Schoening.mulAddDigits a cy ds).length)) :

Multiply-add, renamed: Schöning's Cslib.Algorithms.WordRAM.Schoening.mulAdd_spec.

theorem Cslib.Algorithms.WordRAM.PPZ.RoundFrame.of_exec_mem_lt {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 < Tb, y.mem a = x.mem a) :
RoundFrame φ C Tb y.mem y

A deterministic run of frame-preserving code keeps the frame if it keeps the memory below Tb, with the memory after the arrays taken as it is.

The rounds #

structure Cslib.Algorithms.WordRAM.PPZ.IsRoundCore {n : ℕ} (w : ℕ) (φ : Logic.PL.CNF (Fin n)) (C Tb : ℕ) (S : List ℕ) (O : (Fin n → Option Bool) → Fin n → Option Bool) (core : WordRAM.Code WordRAM.Basis.standard 32) (Tc : ℕ) :

A round body for the oracle O within Tc instructions, on rounds whose memory holds the words S just after the order array: from any frame of a round whose memory M holds S at Tb + 2 n, core has the law of Cslib.Complexity.PPZ.roundWith O within Tc instructions and 2 n rand calls, keeps the frame and leaves every variable set. It writes none of the counter registers.

The body of a round of PPZ is a round body for Cslib.Complexity.PPZ.forced φ, with no words after the order array.

Decrement the counter; stop if it was zero, and otherwise run one round with the round body core and stop after a success.

Decrement the counter; stop if it was zero, and otherwise run one round of PPZ and stop after a success.

The instruction bound of one round of the amplified algorithm, amortizing the decrements.

structure Cslib.Algorithms.WordRAM.PPZ.AmpState {n : ℕ} (φ : Logic.PL.CNF (Fin n)) (C Tb : ℕ) (S ds : List ℕ) (x : WordRAM.Data 32) :

The state at the head of the round loop: the frame of the rounds, the words S the rounds read at Tb + 2 n, the counter digits ds just after them, flag = 1 and out = 0.

The postcondition of the round loop: the frame, and an output 0, or 1 with a satisfying assignment at Tb.

theorem Cslib.Algorithms.WordRAM.PPZ.ampLoopWith_law {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {C Tb w Tc : ℕ} {S : List ℕ} {O : (Fin n → Option Bool) → Fin n → Option Bool} {core : WordRAM.Code WordRAM.Basis.standard 32} (hcore : IsRoundCore w φ C Tb S O core Tc) (hw : WordRAM.Fits w (Tb + 2 * n)) (hT : 1 ≤ Tb) (j : ℕ) (ds : List ℕ) (x : WordRAM.Data 32) :
AmpState φ C Tb S ds x → Nat.ofDigits 2 ds = j → WordRAM.Fits w (Tb + 2 * n + S.length + ds.length) → WordRAM.ExecRandLaw w (ampLoopWith core) x (AmpPost φ C Tb) (j * (Tc + 12 * (Schoening.encodeClauses φ).length + 35) + 9 * List.count 0 ds + 30) (j * (2 * n)) (fun (y : WordRAM.Data 32) => decide (y.regs Reg.out = 1)) (repeatRoundWith O φ j)

The round loop with a round body for the oracle O, from a counter of value j, has the law repeatRoundWith O φ j. Each round costs Tc + 12 E + 35 instructions, amortized: the decrements are paid for by the zero digits of the counter.

theorem Cslib.Algorithms.WordRAM.PPZ.ampLoop_law {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {C Tb w : ℕ} (hw : WordRAM.Fits w (Tb + 2 * n)) (hT : 1 ≤ Tb) (j : ℕ) (ds : List ℕ) (x : WordRAM.Data 32) (hx : AmpState φ C Tb [] ds x) (hv : Nat.ofDigits 2 ds = j) (hfit : WordRAM.Fits w (Tb + 2 * n + ds.length)) :
WordRAM.ExecRandLaw w ampLoop x (AmpPost φ C Tb) (j * ampRoundTime n (Schoening.encodeClauses φ).length + 9 * List.count 0 ds + 30) (j * (2 * n)) (fun (y : WordRAM.Data 32) => decide (y.regs Reg.out = 1)) (repeatRound φ j)

The round loop of PPZ from a counter of value j has the law repeatRound φ j. Each round costs ampRoundTime n E instructions, amortized: the decrements are paid for by the zero digits of the counter.

The number of rounds #

The exponent ⌈(k - 1) n / k⌉ of the number of rounds.

The number of rounds of PPZ with confidence c on n variables and clauses of at most k literals: 2 ^ ⌈(k - 1) n / k⌉ c.

The binary digits of 2 ^ e c, low digit first, as the counter's setup computes them: the digits of 2 ^ e, multiplied by c.

The binary digits of the number of rounds, as the setup computes them: the digits of 2 ^ ⌈(k - 1) n / k⌉, multiplied by c.

A bound on the number of digits of the number of rounds.

theorem Cslib.Algorithms.WordRAM.PPZ.le_two_pow_mul_mul_rpow_neg {e c : ℕ} {x : ℝ} (hx : x ≤ ↑e) :
↑c ≤ ↑(2 ^ e * c) * 2 ^ (-x)

The number of rounds suffices: with 2 ^ e · c rounds and x ≤ e, the product 2 ^ e · c · 2 ^ (-x) is at least c. With q = 2 ^ (-x) this is the hypothesis c ≤ R · q of repeatRoundWith_false_le_exp, for PPZ here and for PPSZ.

theorem Cslib.Algorithms.WordRAM.PPZ.two_pow_le_two_mul_rpow {e : ℕ} {x : ℝ} (he : ↑e ≤ x + 1) :
2 ^ e ≤ 2 * 2 ^ x

Rounding an exponent x up to e ≤ x + 1 costs at most a factor of 2 in 2 ^ e.

theorem Cslib.Algorithms.WordRAM.PPZ.div_mul_le_add_pred_div {a b : ℕ} (hb : 0 < b) (n : ℕ) :
↑a / ↑b * ↑n ≤ ↑((a * n + b - 1) / b)

Ceiling division (a * n + b - 1) / b is at least (a / b) · n.

theorem Cslib.Algorithms.WordRAM.PPZ.add_pred_div_le_div_mul_add_one {a b : ℕ} (hb : 0 < b) (n : ℕ) :
↑((a * n + b - 1) / b) ≤ ↑a / ↑b * ↑n + 1

Ceiling division (a * n + b - 1) / b is at most (a / b) · n + 1.

theorem Cslib.Algorithms.WordRAM.PPZ.le_ppzExp {k : ℕ} (hk : 1 ≤ k) (n : ℕ) :
(1 - 1 / ↑k) * ↑n ≤ ↑(ppzExp k n)

The exponent is at least (1 - 1 / k) n.

The exponent is at most n.

The setup #

Set up the registers on the input k :: c :: encode φ: the clauses start at address 4, the partial assignment is stored just after the input, then the order array, then the counter; and eReg = ⌈(k - 1) n / k⌉.

Write the top digit 1, and prepare the multiplication by c.

The number of rounds: write the digits of 2 ^ eReg, then multiply by c.

theorem Cslib.Algorithms.WordRAM.PPZ.fillLoop_spec {w B e : ℕ} (hfit : WordRAM.Fits w (B + e)) (d : ℕ) (x : WordRAM.Data 32) :
x.regs Reg.bBase = B → x.regs Reg.eReg = e → x.regs Reg.zero = 0 → x.regs Reg.one = 1 → x.regs Reg.iReg + d = e → ∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w fillLoop x y (5 * d + 2) ∧ y.mem = fun (a : ℕ) => if B + x.regs Reg.iReg ≤ a ∧ a < B + e then 0 else x.mem a

The zero digits from iReg on.

The data after the setup on the input k :: c :: encode φ.

The setup establishes the frame of the rounds on the input k :: c :: encode φ.

The instruction bound of the counter's setup for 2 ^ e c.

theorem Cslib.Algorithms.WordRAM.PPZ.countSetup_spec {w B e c : ℕ} (x : WordRAM.Data 32) (hz : x.regs Reg.zero = 0) (ho : x.regs Reg.one = 1) (hB : x.regs Reg.bBase = B) (he : x.regs Reg.eReg = e) (hc : x.regs Reg.cReg = c) (hw : WordRAM.Fits w (B + e + 1 + (Nat.digits 2 c).length + 2 * c)) :

Computing the number of rounds 2 ^ e c. From bBase = B, eReg = e and cReg = c, the setup stores the digits countDigits e c from B, sets bLen to their number and leaves the memory below B unchanged.

The instruction bound of the counter's setup.

theorem Cslib.Algorithms.WordRAM.PPZ.countSetup_exec {n : ℕ} (k c : ℕ) (φ : Logic.PL.CNF (Fin n)) {w : ℕ} (hw : WordRAM.Fits w ((k :: c :: Schoening.encode φ).length + 2 * n + k * n + k + 2 * c + ppzCounterLen k n c + 2)) :

Computing the number of rounds. After the setup, the counter holds the digits ppzDigits k n c of ppzRounds k n c, and the frame of the rounds holds.

The algorithm #

The PPZ algorithm on the input k :: c :: encode φ.

The PPZ algorithm on the input k :: c :: encode φ, halting with out.

The instruction bound of the PPZ algorithm with confidence c, on n variables, clauses of at most k literals and an input of length L.

The PPZ algorithm on the randomized word RAM. On the input k :: c :: encode φ of length L, with 1 ≤ k and at any word size w with L + 2 n + k n + k + 2 c + ppzCounterLen k n c + 2 < 2 ^ w, the program

  • halts on every path within ampTime k n c L instructions;
  • makes at most R (2 n) rand calls, where R = ppzRounds k n c;
  • outputs 0 or 1, and outputs 1 only with a satisfying assignment of φ stored at address L + 1;
  • outputs 1 with exactly the law repeatRound φ R of up to R independent rounds.

Failure probability. The program outputs something other than 1 with probability exactly (1 - p) ^ R, where R = ppzRounds k n c and p = roundSuccessProb φ is the probability that one round finds a satisfying assignment.

theorem Cslib.Algorithms.WordRAM.PPZ.ampProgram_failure_le_exp {n k c : ℕ} (hk : 1 ≤ k) {φ : Logic.PL.CNF (Fin n)} (hφ : φ.Satisfiable) (hlen : ∀ cl ∈ φ, List.length cl ≤ k) {w : ℕ} (hw : WordRAM.Fits w ((k :: c :: Schoening.encode φ).length + 2 * n + k * n + k + 2 * c + ppzCounterLen k n c + 2)) :

The PPZ algorithm succeeds with high probability Paturi, Pudlák, Zane. On a satisfiable formula whose clauses have at most k ≥ 1 literals, the program outputs 1 except with probability at most e ^ (-c).

theorem Cslib.Algorithms.WordRAM.PPZ.ppzExp_le_add_one {k : ℕ} (hk : 1 ≤ k) (n : ℕ) :
↑(ppzExp k n) ≤ (1 - 1 / ↑k) * ↑n + 1

The exponent is at most (1 - 1 / k) n + 1.

theorem Cslib.Algorithms.WordRAM.PPZ.ampTime_le {k : ℕ} (hk : 1 ≤ k) (n c L : ℕ) :
↑(ampTime k n c L) ≤ 200 * ↑(n + L + 1) ^ 2 * 2 ^ ((1 - 1 / ↑k) * ↑n) * (↑c + 1)

The running time of the PPZ algorithm is O((n + L) ^ 2 2 ^ ((1 - 1 / k) n) (c + 1)): explicitly, at most 200 (n + L + 1) ^ 2 2 ^ ((1 - 1 / k) n) (c + 1) instructions. For k = 3 this is O((n + L) ^ 2 2 ^ (2 n / 3) (c + 1)), about 1.588 ^ n.