Documentation

CslibFrontier.Algorithms.WordRAM.DPLL.Solver

The DPLL solver on the word RAM: correctness and running time #

This file proves the main theorem about the word-RAM DPLL solver (Cslib.Algorithms.WordRAM.DPLL.program). On the input encode N φ of length E, where every variable of φ is below N, it returns the output of Cslib.Algorithms.Lean.DPLL.solve (Cslib.Algorithms.WordRAM.DPLL.answerWords): [0] when φ is unsatisfiable, and 1 followed by the bits of the solver's model otherwise. It halts within 2 ^ (d + 1) (37 E + 62) + 10 N + 14 instructions, where d is the number of distinct variables of φ (Cslib.Algorithms.WordRAM.DPLL.program_spec), and so within 222 · 2 ^ N · E (Cslib.Algorithms.WordRAM.DPLL.program_spec_pow).

Each iteration of the main loop runs one step of the search with an explicit trail (Cslib.Algorithms.Lean.DPLL.Trail.step) in O(E) instructions, and the search ends within 2 ^ (d + 1) steps (Cslib.Algorithms.Lean.DPLL.Trail.run_answer). The term 10 N is charged once, on the exit that writes a model: it writes one word for each of the N variables. It is not covered by the O(E) cost of a step, because the header N is only an upper bound on the variables and can exceed the input length E.

Main results #

theorem Cslib.Algorithms.WordRAM.DPLL.mainLoop_spec {w : ℕ} (φ : Logic.PL.CNF ℕ) (N T : ℕ) (hfit : WordRAM.Fits w (T + 5 * N + 2)) (k : ℕ) (t : Lean.DPLL.Trail) (x : WordRAM.Data 32) (a : Lean.DPLL.Trail.Answer) :
StateAt φ N T x t → Lean.DPLL.Trail.run φ k t = some a → ∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w mainLoop x y (k * (37 * (List.flatMap ClauseCode.encodeClause φ).length + 62) + 10 * N + 2) ∧ y.regs Reg.out = T + 4 * N ∧ WordRAM.outputList y.mem (T + 4 * N) = answerList N a

The main loop runs the search: from the state of the trail t, if the run of k steps from t ends with the answer a, the loop writes the output of a at T + 4 N.

theorem Cslib.Algorithms.WordRAM.DPLL.memAt_init (N : ℕ) (φ : Logic.PL.CNF ℕ) (hN : ∀ c ∈ φ, ∀ l ∈ c, l.1 < N) :
MemAt φ N ((encode N φ).length + 1) (WordRAM.Data.init (encode N φ)).mem []

The memory of the input encode N φ of length E is that of the empty trail, with the end of the clauses at T = E + 1.

theorem Cslib.Algorithms.WordRAM.DPLL.solver_spec {w : ℕ} (N : ℕ) (φ : Logic.PL.CNF ℕ) (hN : ∀ c ∈ φ, ∀ l ∈ c, l.1 < N) (hfit : WordRAM.Fits w ((encode N φ).length + 5 * N + 3)) :
∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w solver (WordRAM.Data.init (encode N φ)) y (2 ^ (Lean.DPLL.depth φ + 1) * (37 * (encode N φ).length + 62) + 10 * N + 13) ∧ y.regs Reg.out = (encode N φ).length + 1 + 4 * N ∧ WordRAM.outputList y.mem (y.regs Reg.out) = answerWords N φ

The solver on the word RAM ends with the output answerWords N φ at the address in out.

theorem Cslib.Algorithms.WordRAM.DPLL.program_spec (N : ℕ) (φ : Logic.PL.CNF ℕ) (hN : ∀ c ∈ φ, ∀ l ∈ c, l.1 < N) {w : ℕ} (hfit : WordRAM.Fits w ((encode N φ).length + 5 * N + 3)) :
∃ n ≤ 2 ^ (Lean.DPLL.depth φ + 1) * (37 * (encode N φ).length + 62) + 10 * N + 14, WordRAM.ExecutesList w program (WordRAM.State.init (encode N φ)) (answerWords N φ) n

The DPLL solver on the word RAM. At any word size w that fits E + 5 N + 3, the program run on the input encode N φ of length E, where every variable of φ is below N, returns the output of Cslib.Algorithms.Lean.DPLL.solve: [0] when φ is unsatisfiable, and 1 followed by the bits of the solver's model on the variables below N otherwise. It halts within 2 ^ (d + 1) (37 E + 62) + 10 N + 14 instructions, the final halt included, where d = Cslib.Algorithms.Lean.DPLL.depth φ is the number of distinct variables of φ.

theorem Cslib.Algorithms.WordRAM.DPLL.depth_le {N : ℕ} {φ : Logic.PL.CNF ℕ} (hN : ∀ c ∈ φ, ∀ l ∈ c, l.1 < N) :
theorem Cslib.Algorithms.WordRAM.DPLL.program_spec_pow (N : ℕ) (φ : Logic.PL.CNF ℕ) (hN : ∀ c ∈ φ, ∀ l ∈ c, l.1 < N) {w : ℕ} (hfit : WordRAM.Fits w ((encode N φ).length + 5 * N + 3)) :
∃ n ≤ 222 * 2 ^ N * (encode N φ).length, WordRAM.ExecutesList w program (WordRAM.State.init (encode N φ)) (answerWords N φ) n

The running time in the form c · 2 ^ N · E: the program halts within 222 · 2 ^ N · E instructions on the input encode N φ of length E.