Documentation

CslibFrontier.Algorithms.WordRAM.Schoening.Amplify

Schöning's algorithm on the randomized word RAM #

Cslib.Algorithms.WordRAM.Schoening.ampProgram is Schöning's k-SAT algorithm Schöning with confidence c, as a program of the randomized word RAM. On the input k :: c :: encode φ it computes the trial count R = schoeningTrials k n c = ⌈(3 n + 1) (2 (k - 1) / k) ^ n (k / (k - 1)) ^ (k - 3)⌉ c in a multiword counter (Cslib.Algorithms.WordRAM.Schoening.counterDigits), then runs up to R independent trials, stopping at the first trial that finds a satisfying assignment. It halts with output 1, leaving a satisfying assignment in memory, or with output 0 when every trial failed.

Cslib.Algorithms.WordRAM.Schoening.ampProgram_spec proves, at every word size w with L + 6 n + 4 k + 2 c + counterLen k n c + 2 < 2 ^ w, where L is the input length and counterLen k n c = O((n + k) log (n + k) + log c) bounds the number of digits of R:

Combined with Schöning's bound for one trial (Cslib.Complexity.Schoening.trial_success_of_length_le), the program fails on a satisfiable formula with clauses of at most k ≥ 3 literals with probability at most e ^ (-c) (Cslib.Algorithms.WordRAM.Schoening.ampProgram_failure_le_exp). For k = 3 there are ⌈(3 n + 1) (4 / 3) ^ n⌉ c trials, so the time is O(n ^ 2 L (4 / 3) ^ n c) plus the polynomial setup: Schöning's O*((2 - 2 / k) ^ n) running time, with the polynomial factor explicit. The word size needs only O(log (n + k + L + c)) bits, which is O(log (L + c)) when k is fixed and n = O(L); n and k count separately because the input length L does not bound them (a formula without clauses has L = 3 for every n). The trial count, of about 0.415 n bits for k = 3, is kept in memory, one binary digit per word. A decrement reads the digits up to the lowest nonzero one, which costs a constant amortized number of instructions per trial.

Main definitions #

Main results #

References #

Repeated trials #

The output of up to R independent trials of Schöning's algorithm, stopping at the first success: true if some trial found a satisfying assignment.

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

The program #

@[reducible, inline]

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

@[reducible, inline]

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

@[reducible, inline]

k - 3, during the setup; shares register 7 with lptr.

@[reducible, inline]

Loop counter of the setup; shares register 18 with steps.

Set up the registers on the input k :: c :: encode φ: the clauses start at address 4, the assignment is stored just after the input, the counter just after the assignment, and it is empty.

The trial count: compute schoeningTrials k n c in the counter.

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

Schöning's algorithm on the input k :: c :: encode φ.

Schöning's algorithm on the input k :: c :: encode φ, halting with out.

The instruction bound of the setup.

noncomputable def Cslib.Algorithms.WordRAM.Schoening.ampTime (k n c L : ℕ) :

The instruction bound of Schöning's algorithm with confidence c, on n variables, clauses of at most k literals and an input of length L.

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

The running time of Schöning's algorithm is O((n + k + L) ^ 3 (2 - 2 / k) ^ n (c + 1)): explicitly, at most 900 (n + k + L + 1) ^ 3 (2 (k - 1) / k) ^ n (c + 1) instructions. For k = 3 this is O((n + L) ^ 3 (4 / 3) ^ n (c + 1)).

The setup #

structure Cslib.Algorithms.WordRAM.Schoening.SetupState {n : ℕ} (φ : Logic.PL.CNF (Fin n)) (k c A : ℕ) (ds : List ℕ) (x : WordRAM.Data 24) :

The state during the setup: the frame of the trials, the setup registers, and the counter digits ds at A + n.

theorem Cslib.Algorithms.WordRAM.Schoening.countSetup_exec {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {k c A w : ℕ} {x : WordRAM.Data 24} (hk : 3 ≤ k) (h : SetupState φ k c A [] x) (hfm : WordRAM.Fits w (6 * n + 4 * k + 2 * c + 2)) (hfa : WordRAM.Fits w (A + n + counterLen k n c)) :
∃ (y : WordRAM.Data 24), WordRAM.ExecWithin w countSetup x y (setupTime k n c) ∧ SetupState φ k c A (counterDigits k n c) y

Computing the trial count. From an empty counter, the setup leaves the digits counterDigits k n c of schoeningTrials k n c within setupTime k n c instructions.

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

theorem Cslib.Algorithms.WordRAM.Schoening.ampSetup_exec {n : ℕ} (k c : ℕ) (φ : Logic.PL.CNF (Fin n)) {w : ℕ} (hw : WordRAM.Fits w ((k :: c :: encode φ).length + n + k + 4)) :

The setup establishes the setup state with an empty counter on the input k :: c :: encode φ.

The trials #

The algorithm #

Schöning's algorithm on the randomized word RAM. On the input k :: c :: encode φ of length L, with 3 ≤ k and at any word size w with L + 6 n + 4 k + 2 c + counterLen k n c + 2 < 2 ^ w, the program

  • halts on every path within ampTime k n c L instructions;
  • makes at most R (4 n) rand calls, where R = schoeningTrials 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 repeatTrial φ R of up to R independent trials.

Failure probability. The program outputs something other than 1 with probability exactly (1 - p) ^ R, where R = schoeningTrials k n c and p = succeedProb φ (trial φ) is the success probability of one trial.

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

Schöning's algorithm succeeds with high probability. On a satisfiable formula whose clauses have at most k ≥ 3 literals, the program outputs 1 except with probability at most e ^ (-c).