Documentation

CslibFrontier.Algorithms.WordRAM.DPLL.Scan

The DPLL solver on the word RAM: what the scan computes #

The scan of the word-RAM DPLL solver (Cslib.Algorithms.WordRAM.DPLL.scan) makes one pass over the clauses. This file states what it computes as a fold over the clauses and their literals (Cslib.Algorithms.WordRAM.DPLL.clauseStep, Cslib.Algorithms.WordRAM.DPLL.litStep), proves that the fold gives the status of the trail (Cslib.Algorithms.Lean.DPLL.status): a falsified clause, satisfaction, the literal of the first unit clause, and the variable of the first literal occurrence that is open (Cslib.Algorithms.WordRAM.DPLL.foldl_clauseStep_init), and proves that the program computes the fold (Cslib.Algorithms.WordRAM.DPLL.scan_spec).

Main definitions #

Main results #

The fold of the scan #

The registers of the literal loop: the number of literals of the current clause not falsified so far, the code of the last of them, whether one of them is true, and the first open variable.

  • cnt : ℕ

    The number of literals not falsified so far.

  • uc : ℕ

    The code of the last such literal.

  • sat : Bool

    Whether a true literal was found.

  • opened : Option ℕ

    The first open variable.

Instances For

    One literal against the partial assignment π: a falsified literal changes nothing; a true one is counted and recorded; the variable of any other is open, and is recorded when it is the first.

    Whether some literal of π has the code u.

    The registers of the scan: a falsified clause, whether every clause has a true literal, the code of the literal of the first unit clause, and the first open variable.

    • conf : Bool

      A falsified clause was found.

    • alls : Bool

      Every clause so far has a true literal.

    • unit : Option ℕ

      The code of the literal of the first unit clause not on the trail.

    • opened : Option ℕ

      The first open variable.

    Instances For

      The registers at the start of the scan.

      The end of a clause whose literal loop ended with the registers r.

      The fold computes the status #

      @[reducible, inline]

      The literals of a clause not falsified by π.

      Assignment of a variable through the two literals on it.

      What the literal loop computes: the number of literals not falsified, whether one of them holds, the code of the last of them, and the first open variable.

      The code of the literal of a unit clause.

      theorem Cslib.Algorithms.WordRAM.DPLL.unitCode_eq (π : List (Logic.PL.Literal ℕ)) (c : Logic.PL.Clause ℕ) (o : Option ℕ) :
      (if ((List.foldl (litStep π) { cnt := 0, uc := 0, sat := false, opened := o } c).cnt == 1 && !codeOn π (List.foldl (litStep π) { cnt := 0, uc := 0, sat := false, opened := o } c).uc) = true then some (List.foldl (litStep π) { cnt := 0, uc := 0, sat := false, opened := o } c).uc else none) = unitCode π c
      theorem Cslib.Algorithms.WordRAM.DPLL.foldl_clauseStep (π : List (Logic.PL.Literal ℕ)) (φ : Logic.PL.CNF ℕ) (s : ScanRegs) :
      List.foldl (clauseStep π) s φ = { conf := s.conf || List.any φ (Lean.DPLL.Falsifies π), alls := s.alls && List.all φ fun (c : Logic.PL.Clause ℕ) => List.any c (Lean.DPLL.Holds π), unit := s.unit.or (List.findSome? (unitCode π) φ), opened := s.opened.or (List.find? (fun (x : ℕ) => !Lean.DPLL.Assigned π x) φ.vars) }

      What the scan computes, from any registers.

      The scan computes the status of the trail: whether a clause is falsified, whether every clause has a true literal, the code of the literal of the first unit clause, and the variable of the first literal occurrence that is open.

      theorem Cslib.Algorithms.WordRAM.DPLL.uc_foldl_litStep (π : List (Logic.PL.Literal ℕ)) (c : Logic.PL.Clause ℕ) (o : Option ℕ) :
      (List.foldl (litStep π) { cnt := 0, uc := 0, sat := false, opened := o } c).uc = 0 ∨ ∃ l ∈ notFalse π c, (List.foldl (litStep π) { cnt := 0, uc := 0, sat := false, opened := o } c).uc = ClauseCode.litCode l

      The code left by the literal loop is 0 or that of a literal not falsified.

      The program computes the fold #

      The literal array at T holds the partial assignment π on the variables below N: the cell T + 2 v + b is 1 when (v, b) is in π and 0 otherwise.

      The registers of the literal loop hold r.

      The scan registers hold s.

      theorem Cslib.Algorithms.WordRAM.DPLL.litBody_spec {w : ℕ} (π : List (Logic.PL.Literal ℕ)) (l : Logic.PL.Literal ℕ) (r : LitRegs) (x : WordRAM.Data 32) (N : ℕ) (hzero : x.regs Reg.zero = 0) (hone : x.regs Reg.one = 1) (hlit : x.mem (x.regs Reg.lptr) = ClauseCode.litCode l) (hlN : l.1 < N) (hπ : LitArr x.mem (x.regs Reg.tb) N π) (hr : LitAt x r) (hfit : WordRAM.Fits w (x.regs Reg.tb + 2 * N)) (hfitp : WordRAM.Fits w (x.regs Reg.lptr + 1)) (hfitc : WordRAM.Fits w (r.cnt + 1)) :

      One literal of the scan performs litStep.

      theorem Cslib.Algorithms.WordRAM.DPLL.litLoop_spec {w : ℕ} (π : List (Logic.PL.Literal ℕ)) (ls : Logic.PL.Clause ℕ) (r : LitRegs) (x : WordRAM.Data 32) (N : ℕ) (hzero : x.regs Reg.zero = 0) (hone : x.regs Reg.one = 1) (hl : WordRAM.Block.HoldsList (x.regs Reg.lptr) (List.map ClauseCode.litCode ls) x.mem) (hend : x.regs Reg.lend = x.regs Reg.lptr + List.length ls) (hN : ∀ l ∈ ls, l.1 < N) (hπ : LitArr x.mem (x.regs Reg.tb) N π) (hr : LitAt x r) (hfit : WordRAM.Fits w (x.regs Reg.tb + 2 * N)) (hfitp : WordRAM.Fits w (x.regs Reg.lend + 1)) (hfitc : WordRAM.Fits w (r.cnt + List.length ls + 1)) :

      The literal loop folds litStep over the literals at lptr, and leaves memory unchanged.

      theorem Cslib.Algorithms.WordRAM.DPLL.clauseEnd_spec {w : ℕ} (π : List (Logic.PL.Literal ℕ)) (r : LitRegs) (s : ScanRegs) (x : WordRAM.Data 32) (hzero : x.regs Reg.zero = 0) (hone : x.regs Reg.one = 1) (hr : LitAt x r) (hconf : x.regs Reg.conf = s.conf.toNat) (halls : x.regs Reg.alls = s.alls.toNat) (huf : x.regs Reg.uf = s.unit.isSome.toNat) (hunit : x.regs Reg.unit = s.unit.getD 0) (hu : r.cnt = 1 → x.mem (x.regs Reg.tb + r.uc) = (codeOn π r.uc).toNat) (hfit : WordRAM.Fits w (x.regs Reg.tb + r.uc)) :

      The end of a clause performs endClause.

      theorem Cslib.Algorithms.WordRAM.DPLL.clauseLoop_spec {w : ℕ} (π : List (Logic.PL.Literal ℕ)) (ψ : Logic.PL.CNF ℕ) (s : ScanRegs) (x : WordRAM.Data 32) (N : ℕ) (hzero : x.regs Reg.zero = 0) (hone : x.regs Reg.one = 1) (hcl : WordRAM.Block.HoldsList (x.regs Reg.ptr) (List.flatMap ClauseCode.encodeClause ψ) x.mem) (hend : x.regs Reg.ptr + (List.flatMap ClauseCode.encodeClause ψ).length = x.regs Reg.cend) (hN : ∀ c ∈ ψ, ∀ l ∈ c, l.1 < N) (hπ : LitArr x.mem (x.regs Reg.tb) N π) (hs : ScanAt x s) (hfit : WordRAM.Fits w (x.regs Reg.tb + 2 * N)) (hfitp : WordRAM.Fits w (x.regs Reg.cend + 1)) :

      The clause loop folds clauseStep over the clauses from ptr to cend, and leaves memory unchanged.

      theorem Cslib.Algorithms.WordRAM.DPLL.scan_spec {w : ℕ} (π : List (Logic.PL.Literal ℕ)) (φ : Logic.PL.CNF ℕ) (x : WordRAM.Data 32) (N : ℕ) (hzero : x.regs Reg.zero = 0) (hone : x.regs Reg.one = 1) (htwo : x.regs Reg.two = 2) (hcl : WordRAM.Block.HoldsList 2 (List.flatMap ClauseCode.encodeClause φ) x.mem) (hend : 2 + (List.flatMap ClauseCode.encodeClause φ).length = x.regs Reg.cend) (hN : ∀ c ∈ φ, ∀ l ∈ c, l.1 < N) (hπ : LitArr x.mem (x.regs Reg.tb) N π) (hfit : WordRAM.Fits w (x.regs Reg.tb + 2 * N)) (hfitp : WordRAM.Fits w (x.regs Reg.cend + 1)) :

      The scan of the clauses φ stored from address 2 to cend against the partial assignment π: the registers end with the status of π, and memory is unchanged.