Documentation

CslibFrontier.Algorithms.Lean.CDCL.Minimize

Minimizing learned clauses #

MiniSat's minimization of learned clauses. In its recursive mode (ccmin_mode = 2, Sörensson and Biere), a literal y of a learned clause, false below the backjump point, is redundant when the literal ¬y of the trail is implied and every other literal of its reason is either in the learned clause or, recursively, redundant (Cslib.Algorithms.Lean.CDCL.derived). In its basic mode (ccmin_mode = 1, MiniSat 1.13), the recursion goes only into the literals implied without any decision, which MiniSat's test of level 0 admits. Removing every redundant literal gives a clause that follows from the rest by unit propagation: assuming its negation, the reasons of the derived literals, oldest first, propagate the negations of the removed literals, and then the learned clause is false.

So the minimized clause is learned with the hints of the learned clause after those reasons (Cslib.Algorithms.Lean.CDCL.Learned.minimize), still one RUP step, and the hints are proved to refute it (Cslib.Algorithms.Lean.CDCL.Learned.propagateHints_redundant), with no check at run time. The proof rests on the soundness of the memo of the search: a variable recorded as derived has a reason on the trail whose other literals are on variables of the learned clause or recorded as derived. The search records a variable as not derived while it searches its reason, so a recorded result is never changed. Reasons point down the trail, so propagating the derived literals oldest first reaches each reason with its other literals false. The minimized clause is a subset of the learned one containing its asserting literal once, at its head, so it is again a learned clause.

On the solver's array trail (Cslib.Algorithms.Lean.CDCL.ATrail), reasons are looked up in constant time through self-certifying position hints (Cslib.Algorithms.Lean.CDCL.ATrail.reasonAt), and the clause-variable and memo arrays are cleared along the variables touched and reused in place across conflicts when unshared and within bounds.

Main definitions #

Main results #

References #

State of the memoized search for derived literals: ok holds the answer of the current step (or whether any literal was removed in redundant), memo caches answers (some true for derived, some false for not derived or active), and visited lists every variable written in memo so the caller can clear memo in time proportional to the search.

  • ok : Bool

    Answer of the current search step, or whether any literal was found redundant.

  • memo : Assign

    Memoized outcomes indexed by variable.

  • visited : List ℕ

    Variables given a value in memo during this search.

def Cslib.Algorithms.Lean.CDCL.derived {φ : Logic.PL.CNF ℕ} (log : φ.LRATLog) (reasonCode : ℕ → ℕ) (inC deep : ℕ → Bool) (fuel : ℕ) (memo : Assign) (visited : List ℕ) (v : ℕ) :

Whether the literal of the trail on v is derived from the literals of the learned clause, whose variables satisfy inC: its reason, looked up in log through reasonCode (0 for none or a decision, r + 1 for reason r), has every other literal either on a variable of the learned clause or, on a variable where deep allows the recursion, derived. The results are memoized in memo, where v counts as not derived while its reason is searched; visited records every variable written in memo; fuel bounds the depth of the search, and running out of it counts as not derived.

def Cslib.Algorithms.Lean.CDCL.redundant {φ : Logic.PL.CNF ℕ} (log : φ.LRATLog) (reasonCode : ℕ → ℕ) (inC deep : ℕ → Bool) (fuel : ℕ) (lit : Logic.PL.Literal ℕ) (C : Logic.PL.Clause ℕ) (memo : Assign) :

Whether any literal of the clause C other than lit has its negation derived, together with the memoized search and the list of variables written in memo.

The reasons of the derived literals of the trail T, oldest first: the hints that propagate them.

The minimized clause is a RUP clause #

theorem Cslib.Algorithms.Lean.CDCL.Learned.propagateHints_redundant {φ : Logic.PL.CNF ℕ} {log₀ : φ.LRATLog} {A : Trail} {T : XTrail} (L : Learned log₀ A T.trail) (hreasons : Reasons log₀ T) (hnd : T.trail.vars.Nodup) {reasonCode : ℕ → ℕ} (hrc : ∀ (v r : ℕ), reasonCode v = r + 1 → ∃ (b : Bool), XEntry.implied (v, b) r ∈ T) {inC : ℕ → Bool} (hinC : ∀ (w : ℕ), inC w = true → ∃ y ∈ L.clause, y.1 = w) (deep : ℕ → Bool) (fuel : ℕ) {memo₀ : Assign} (hmemo₀ : ∀ (w : ℕ), memo₀.value w = none) :
have C := L.clause; have r := redundant log₀ reasonCode inC deep fuel L.lit C memo₀; Logic.PL.CNF.propagateHints log₀.db (List.map Std.Sat.Literal.negate (L.lit :: List.filter (fun (y : Logic.PL.Literal ℕ) => !y == L.lit && !r.memo.holds (y.1, true)) C)) (derivedHints T r.memo ++ L.hints) = true

Removing derived literals yields a RUP clause, for any sound reason lookup reasonCode, clause-variable predicate inC, depth filter deep, fuel, and empty initial memo₀.

derivedHints of the entries below position p, read in one pass from the arrays of the trail.

def Cslib.Algorithms.Lean.CDCL.Learned.minimize {φ : Logic.PL.CNF ℕ} {log₀ : φ.LRATLog} {A : Trail} (T : ATrail) (vpos : Array ℕ) (p : ℕ) (L : Learned log₀ A (T.seg 0 p).trail) (memoClean : { A : Assign // ∀ (v : ℕ), A.value v = none }) (hreasons : Reasons log₀ (T.seg 0 p)) (hnd : (T.seg 0 p).trail.vars.Nodup) (recursive : Bool := true) :
Learned log₀ A (T.seg 0 p).trail × { A : Assign // ∀ (v : ℕ), A.value v = none }

Minimizing a learned clause, whose false literals are on the entries of the trail T below position p, recursively if recursive (MiniSat's ccmin_mode = 2) and otherwise in the basic way (ccmin_mode = 1): the learned clause without its redundant literals, together with the restored scratch memo array. Reasons are looked up in constant time through ATrail.reasonAt vpos p, L.seenMarks is detached first so the clause variables are marked and cleared in place when unshared and within bounds, and the memo is cleared along res.visited.