Documentation

CslibFrontier.Algorithms.Lean.CDCL.Phase

Phase saving for the CDCL solver #

MiniSat's choice of polarity for a decision (with phase_saving = 2). Every variable has a saved phase, initially false, so a fresh variable is decided negative, as MiniSat's default polarity does. When a backjump unassigns variables, each one's phase becomes the value it had on the trail (Phases.save), and a later decision on it takes that value again (Phases.get). The solver thus returns to the part of the search space it left, keeping the assignments of the subproblems it had solved.

The polarity of a decision does not affect correctness.

Main definitions #

Main results #

Storage. The phases are an array indexed by variable; setting a variable past its end grows it. WExec.init gives it varSlots φ slots, one more than the largest variable of the formula and none for a formula without variables, so solveCompact, which renames the variables to 0, …, k - 1 first, keeps it at k slots.

Saved phases: a polarity for each variable, by index; variables past the end have the phase false.

  • saved : Array Bool

    The saved polarity of each variable.

The initial phases of the variables below n: all false.

The phase of the variable v: the polarity of its next decision.

Setting the phase of v to b, growing the array with false if v is past its end.

Saving the phases of the literals of M, which a backjump undoes: each variable takes the value it had.

theorem Cslib.Algorithms.Lean.CDCL.Phases.get_set (P : Phases) (v : ℕ) (b : Bool) (w : ℕ) :
(P.set v b).get w = if v = w then b else P.get w

Setting a phase changes that variable only.

theorem Cslib.Algorithms.Lean.CDCL.Phases.get_save_of_mem (P : Phases) {M : Trail} (hM : M.vars.Nodup) {l : Logic.PL.Literal ℕ} (hl : l ∈ M.lits) :
(P.save M).get l.1 = l.2

Saved phases are the undone values: on a trail assigning each variable once, saving its literals gives each of their variables the value it had.

theorem Cslib.Algorithms.Lean.CDCL.Phases.get_save_of_not_mem (P : Phases) {M : Trail} {v : ℕ} (hv : v ∉ M.vars) :
(P.save M).get v = P.get v

Other phases are kept: saving the literals of a trail leaves the phase of every other variable unchanged.