One trial of Schöning's algorithm on the randomized word RAM #
Cslib.Algorithms.WordRAM.Schoening.trialProgram is one trial of Schöning's k-SAT algorithm
Schöning 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
- draws a uniformly random assignment, one
randcall per variable; - performs
3 nsteps of local search: each step scans for the first falsified clause and, if there is one, flips the variable of a uniformly chosen literal occurrence of it; - halts with output
1if the final assignment satisfiesφand0otherwise, leaving the final assignment in memory just after the input.
Cslib.Algorithms.WordRAM.Schoening.trialProgram_spec proves that the program halts on every path
within trialTime n L = 36 n L + 66 n + 12 L + 19 instructions, where L is the input length,
makes at most 4 n rand calls, reports correctly whether the assignment it leaves satisfies φ,
and that the law of that assignment is exactly the mathematical trial
Cslib.Complexity.Schoening.trial φ. Schöning's success bound for that trial
(Cslib.Complexity.Schoening.trial_success_of_length_le) 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 trial body Cslib.Algorithms.WordRAM.Schoening.trialCore reads the clause region and the
number of variables from registers, so the amplified algorithm reuses it with a different input
layout. It writes memory only in the assignment: Cslib.Algorithms.WordRAM.Schoening.Frame records
that the memory after the assignment is unchanged, which is where the amplified algorithm keeps its
trial counter.
Main definitions #
Cslib.Algorithms.WordRAM.Schoening.Frame: the registers and memory a trial relies on.Cslib.Algorithms.WordRAM.Schoening.initAssign,Cslib.Algorithms.WordRAM.Schoening.flip,Cslib.Algorithms.WordRAM.Schoening.stepBody,Cslib.Algorithms.WordRAM.Schoening.walkLoop,Cslib.Algorithms.WordRAM.Schoening.trialCore: the parts of a trial.Cslib.Algorithms.WordRAM.Schoening.trialCode,Cslib.Algorithms.WordRAM.Schoening.trialProgram: a trial on the inputencode φ, structured and compiled.Cslib.Algorithms.WordRAM.Schoening.trialTime: its instruction bound.Cslib.Algorithms.WordRAM.Schoening.cfgAssignment: the assignment left by a halting run.
Main results #
Cslib.Algorithms.WordRAM.Schoening.trialCore_law: the trial body has the law ofCslib.Complexity.Schoening.trial.Cslib.Algorithms.WordRAM.Schoening.trialProgram_spec: halting, time andrandbounds, a correct output, and the exact law of the trial for the compiled program.
References #
Reading assignments #
The assignment left by a halting run: read from address base.
AssignAt for the assignment read back from bits.
The found word reported by a clause scan is 0 when σ satisfies φ and 1 otherwise.
On the initial machine data for encode φ, the encoded clauses start at address 2.
The frame of a trial #
The registers and memory a trial relies on: the constants, the clauses of φ stored in
[C, A), the assignment's address A, and n. The memory from address A + n on, just after
the assignment, agrees with M; a trial never writes there, so callers can keep data such as a
trial counter in it.
The frame survives any change that keeps its registers and the memory outside the assignment
[A, A + n).
The frame with the memory after the assignment taken as it is.
The frame survives any change that keeps its registers and the memory below A, with the
memory after the assignment taken as it is.
Code that writes none of the frame registers keeps the frame registers.
Instances For
A deterministic run of frame-preserving code that keeps the memory outside the assignment keeps the frame.
The random initial assignment #
The random initial assignment: draw all n variables via Cslib.WordRAM.sampleBits.
The random initial assignment is uniform, takes 6 n + 3 instructions and n rand
calls, and keeps the frame.
Flipping a literal of a falsified clause #
Read the literal at offset var of the clause at cPtr and flip its variable.
One flip: choose a literal occurrence of the clause at cPtr uniformly and flip its
variable; an empty clause changes nothing.
One flip has the law of Cslib.Complexity.Schoening.flipStep.
One step of local search #
One step: scan for the first falsified clause and flip a literal of it, then count the step.
The law of one step of Cslib.Complexity.Schoening.walk.
A satisfying assignment is never moved.
One more step of the walk is a step followed by the walk.
One step has the law stepLaw φ σ, within 12 E + 18 instructions and one rand
call.
The local search #
The local search: steps cnt, …, steps - 1.
The local search from t remaining steps has the law of walk φ t.
One trial #
The body of a trial: a uniform assignment, 3 n steps of local search, and the final
check, which sets out to 1 exactly when the assignment satisfies the formula. The clauses are
read from [cBeg, aBase), the assignment is stored from aBase, and n is read from nReg.
The instruction bound of a trial body on n variables and a clause encoding of length
E.
The body of a trial has the law of Cslib.Complexity.Schoening.trial, keeps the frame,
and sets out to whether the assignment it leaves satisfies the formula.
The program #
Set up the registers of a trial on the input encode φ: the clauses start at address 2,
and the assignment is stored just after the input.
One trial of Schöning's algorithm on the input encode φ, as a structured program.
One trial of Schöning's algorithm on the input encode φ, halting with out.
The instruction bound of a trial on n variables and an input of length L.
The data after the setup of a trial on the input encode φ.
The setup establishes the frame of a trial on the input encode φ.
One trial of Schöning's algorithm on the randomized word RAM. On the input encode φ of
length L, at any word size w with L + 3 n + 1 < 2 ^ w, the program
- halts on every path within
trialTime n L = 36 n L + 66 n + 12 L + 19instructions; - makes at most
4 nrandcalls; - outputs
1exactly when the assignment it leaves at addressL + 1satisfiesφ; - leaves an assignment whose law is exactly
Cslib.Complexity.Schoening.trial φ.