A CDCL solver with watched literals and LRAT certificates #
An executable instance of abstract DPLL with learning, which returns a model or an LRAT certificate
(Cslib.Algorithms.Lean.CDCL.solve). Its moves are those of Cslib.Algorithms.Lean.CDCL.Exec;
this module finds conflicts and unit clauses among the clauses of at least two literals with two
watched literals per clause, as MiniSat does, instead of scanning them. Each trail literal is
queued when it is assigned; processing it visits the watchers of its negation: a watcher whose
blocker is true is skipped without reading its clause, and otherwise the clause finds another
watch, is satisfied by its other watch, becomes unit, or is false.
The state WExec extends Exec with the value of each variable on the trail in an array indexed by
variable (Assign, MiniSat's assigns), read by the visits of watchers, the checks of the short
clauses and the choice of decision variable instead of scanning the trail, the watch store, the
queue, and the clauses with fewer than two different literals, which cannot be watched and are
scanned when the queue is empty. Conflict analysis reads the literals of the current level from an
array of its own. Its
invariant WExec.Inv adds to Exec.Inv:
- the watch store's invariant
WatchStore.Inv: every clause with two different literals is stored, and a stored clause with both watches falsified by processed literals (literals of the trail not on the queue) has a literal that is true and stays true after any backjump keeping both watches false; - the queue is on the trail, without repetitions, and above the newest decision;
- the array of values agrees with the trail (
Assign.Agrees): both Backjump and Restart unassign the variables undone in place; - the variables occurring in the database are marked (
WExec.occurs), so that the variable order skips those that left it.
The condition on the queue makes the invariant survive Backjump without decision levels: the
literals removed include all those above the newest decision, so every processed literal kept was
processed before. It also makes skipping a watcher on a true blocker safe: the literal being
processed is above the newest decision, so any backjump that keeps it false keeps the blocker
true. With the queue empty, no clause of the database is false unless a short one is
(WExec.Inv.noConflict), so the loop finds conflicts and units among long clauses without
scanning them. Without VSIDS, choosing the next decision variable searches the variables of the
database (CNF.vars).
The loop (Cslib.Algorithms.Lean.CDCL.loop). While the queue is not empty, it processes its
oldest literal. As in MiniSat, the queue is the part of the trail from a head position on
(Cslib.Algorithms.Lean.CDCL.WExec.qhead, Cslib.Algorithms.Lean.CDCL.WExec.queue): a literal is
queued by being pushed on the trail, and processed by moving the head past it. A conflict with
no decision on the trail ends with a certificate; otherwise it is analysed, the learned clause is
minimized (Cslib.Algorithms.Lean.CDCL.Learned.minimize), and Backjump and Learn follow; the
variables met by the analysis are bumped
(Cslib.Algorithms.Lean.CDCL.Activity.bump). With the queue empty, it checks the short clauses for
a conflict or a unit, then decides an unassigned variable of the database of greatest activity
(VSIDS, Cslib.Algorithms.Lean.CDCL.WExec.pickVar), popped from the variable order
(Cslib.Algorithms.Lean.CDCL.VarOrder.pop), with its saved phase
(Cslib.Algorithms.Lean.CDCL.Phases.get), or returns the trail as a model. Backjump and Restart
save the phases of the literals they undo (Cslib.Algorithms.Lean.CDCL.ATrail.undoGo); the
variables bumped move up in the variable order and those undone go back in it, keeping its
invariant (Cslib.Algorithms.Lean.CDCL.WExec.OrderInv), under which the decision variable has the
greatest activity (Cslib.Algorithms.Lean.CDCL.WExec.Inv.pickVar_max). Every move lowers
the measure: the rank of the abstract system, times the number of variables plus two, plus the
length of the queue. A move is Cslib.Algorithms.Lean.CDCL.step; the loop makes up to 2 ^ d
moves by making 2 ^ (d - 1) moves twice, structurally on d, so the kernel can run the solver.
Since every state has measure below restartBound φ, a d with restartBound φ < 2 ^ d, computed
once, never runs out; the measure appears only in proofs, so at run time a move does no
arithmetic on it.
Reducing the learned clauses (Cslib.Algorithms.Lean.CDCL.WExec.maybeReduce). As in
MiniSat's reduceDB, once the learned clauses exceed the assigned variables by a limit, which
grows on a schedule, the less active half of them is forgotten
(Cslib.Algorithms.Lean.CDCL.Exec.forget), except the reasons of the trail and the clauses of at
most two literals, and the watch store is rebuilt on the trail
(Cslib.Algorithms.Lean.CDCL.WatchStore.build). This happens with the queue empty and no clause
false, and keeps the measure.
Certified deletion of root-satisfied clauses (Cslib.Algorithms.Lean.CDCL.WExec.maybeSimplify).
At decision level 0 (checked on the trail, WExec.maybeSimplify_root) and when the trail grew
since the last time, before the reduction, the clauses satisfied by a literal of the trail are
deleted, input clauses included (MiniSat's remove_satisfied, Options.removeSatisfied), except
the reasons of the trail; the watch store and the marks of the variables occurring in the database
are rebuilt (Cslib.Algorithms.Lean.CDCL.WExec.simplify). At level 0 the trail is its root, so
under total assignments the remaining clauses entail the input clauses, and with them the
clauses deleted; for partial assignments the guarantee concerns the input clauses only
(Cslib.Algorithms.Lean.CDCL.Exec.forget_inv). Each deletion is a step of the certificate. If no
clause is satisfied, only the schedule advances.
This is part of MiniSat's simplify, not all of it. MiniSat also removes the false literals from
the clauses it keeps, can delete a satisfied clause that is the reason of a root literal after
clearing that reason, and bounds the work of simplify by a budget of propagations; it checks the
restart budget before simplifying. Here reasons are kept, which keeps the LRAT proof of the root
literals simple, and kept clauses are not shortened.
Restarts (Cslib.Algorithms.Lean.CDCL.solveWith.search). As in MiniSat, once a run of the loop
has had its budget of conflicts (restartFirst times the Luby sequence, Options.restartBudget),
at the next point with an empty queue and no conflict it goes back to the root of the trail, the
literals implied below every decision (WExec.restart), keeping the learned clauses, the activities
and the phases. Restarts raise the measure, so each run is bounded by its own measure: each move of
the loop counts at most one conflict and lowers the measure, so a run that restarts has had fewer
conflicts than the bound restartBound φ on the measure of every state, which depends only on the
number of variables. The budgets are unbounded (luby_pow): the budget of restart
Options.restartRuns (restartBound φ) exceeds the bound (Options.lt_restartBudget), so that run
does not restart, and the search ends there. Termination is structural on d within a run, and on
the runs left before that one. This adapts Theorem 2.16 of Nieuwenhuis, Oliveras and Tinelli,
which asks the number of steps between restarts to increase: it is enough that some run's budget
exceeds the conflicts any run can have, with Forget keeping the measure.
Main definitions #
Cslib.Algorithms.Lean.CDCL.WExec,Cslib.Algorithms.Lean.CDCL.WExec.Inv: the state and its invariant.Cslib.Algorithms.Lean.CDCL.WExec.processFrom,Cslib.Algorithms.Lean.CDCL.WExec.processQueue: visiting a watch list, and processing the queue.Cslib.Algorithms.Lean.CDCL.Reduction,Cslib.Algorithms.Lean.CDCL.WExec.reduce: the reduction of the learned clauses.Cslib.Algorithms.Lean.CDCL.WExec.simplify: deleting the clauses satisfied at the root.Cslib.Algorithms.Lean.CDCL.step,Cslib.Algorithms.Lean.CDCL.loop,Cslib.Algorithms.Lean.CDCL.solveWith.search,Cslib.Algorithms.Lean.CDCL.solve: the solver.Cslib.Algorithms.Lean.CDCL.Options,Cslib.Algorithms.Lean.CDCL.Stats,Cslib.Algorithms.Lean.CDCL.solveWith: the solver with options, returning its statistics.
Main results #
Cslib.Algorithms.Lean.CDCL.solve_sat,Cslib.Algorithms.Lean.CDCL.solve_unsat: both answers are correct.Cslib.Algorithms.Lean.CDCL.isSat_solve_iff: the solver decides satisfiability.Cslib.Algorithms.Lean.CDCL.isSat_solveWith_iff: so it does whatever the options.Cslib.Algorithms.Lean.CDCL.WExec.Inv.pickVar_max: with VSIDS, every decision is of greatest activity among the unassigned variables.Cslib.Algorithms.Lean.CDCL.Options.lt_restartBudget,Cslib.Algorithms.Lean.CDCL.WExec.Inv.measure_lt_restartBound: some restart budget exceeds the conflicts of any run, so the search with restarts and Forget terminates, with no limit on the restarts.Cslib.Algorithms.Lean.CDCL.solveCompactWith_sat,Cslib.Algorithms.Lean.CDCL.solveCompactWith_unsat,Cslib.Algorithms.Lean.CDCL.isSat_solveCompactWith_iff: the same for the solver on renamed variables.
Variable names. solve keeps arrays indexed by variable, sized by the largest variable of the
formula (Cslib.Algorithms.Lean.CDCL.varSlots), so a formula such as [[], [(10⁹, true)]] with
one variable allocates 10⁹ + 1 slots, and a formula with no variables allocates none.
Cslib.Algorithms.Lean.CDCL.solveCompact first renames the k distinct variables to
0, …, k - 1 (Cslib.Logic.PL.CNF.denseRenaming), solves the renamed formula, and translates the
answer back: the model through the renaming, and the certificate through the injective map back
(Cslib.Logic.PL.CNF.checkLRUP_relabel). The renaming uses a hash map, which the kernel does not
evaluate, so decide +kernel clients call solve.
The minimization of the learned clauses, MiniSat's ccmin_mode: none (0), basic (1),
or recursive (2).
- none : CcminMode
No minimization (
ccmin_mode = 0). - basic : CcminMode
Basic minimization (
ccmin_mode = 1): a literal goes if the reason of its negation has only literals of the clause or implied at level0. - recursive : CcminMode
Recursive minimization (
ccmin_mode = 2).
Instances For
Options of the solver, after MiniSat's: VSIDS for the decision variable (otherwise the
first unassigned variable of the database); phase saving for its polarity (MiniSat's
phase_saving = 2; otherwise false, MiniSat's phase_saving = 0); and restarts, the i-th
after restartFirst * luby restartInc i more conflicts (MiniSat's luby_restart), or
restartFirst * restartInc ^ i without luby; the minimization of learned clauses (MiniSat's
ccmin_mode: 0 none, 1 basic, 2 recursive); and the reduction of the learned clauses
(MiniSat's reduceDB; otherwise they are kept). None affects correctness.
- vsids : Bool
Choose decision variables by VSIDS.
- phaseSaving : Bool
Choose polarities by phase saving.
- restarts : Bool
Restart.
- luby : Bool
Space the restarts by the Luby sequence, rather than geometrically.
- restartFirst : ℕ
The conflicts before the first restart (MiniSat's
restart_first). MiniSat requires it to be at least1; here0counts as1(Options.restartBudget). - restartInc : ℕ
The growth of the conflicts between restarts (MiniSat's
restart_inc). MiniSat requires it to exceed1; here0and1count as2, so that the budgets are unbounded (Options.restartBudget). With the Luby sequence, the peaks arerestartInc ^ m(Cslib.Algorithms.Lean.CDCL.luby_pow), unbounded from base2. - ccminMode : CcminMode
The minimization of the learned clauses (MiniSat's
ccmin_mode). - reduce : Bool
Forget learned clauses of low activity.
- learntsDivisor : ℕ
The limit on the learned clauses starts at the clauses of the formula divided by this (MiniSat's
1 / learntsize_factor). - removeSatisfied : Bool
Simplification deletes the input clauses satisfied at the root too, not only the learned ones (MiniSat's
remove_satisfied).
Instances For
The conflicts allowed before the restart numbered i. As MiniSat requires restart_first ≥ 1
and restart_inc > 1, restartFirst counts as at least 1 and restartInc as at least 2, so
that the budgets are unbounded.
A restart whose budget exceeds B: its index. With Luby restarts it ends a complete
subsequence of the Luby sequence (luby_pow).
Statistics of a run, as MiniSat reports them.
- conflicts : ℕ
Conflicts, the last one included when the formula is unsatisfiable.
- decisions : ℕ
Decisions.
- propagations : ℕ
Propagations, counted as MiniSat counts them: the literals taken from the propagation queue for processing, decisions and implied literals alike.
- restarts : ℕ
Restarts.
- maxLiterals : ℕ
Different literals of the learned clauses before minimization (MiniSat's
max_literals). - literals : ℕ
Different literals of the learned clauses (MiniSat's
tot_literals). - removed : ℕ
Learned clauses forgotten.
- simplified : ℕ
Clauses satisfied at the root, deleted by simplification.
Instances For
One more literal taken from the propagation queue.
Merge sort by le, to the depth of the length of the list, which is enough. Unlike
List.mergeSort, it is structurally recursive, so the kernel can run it.
Whether the clause numbered id is a learned clause of a formula of n clauses: the clauses of
the formula are numbered 1 to n. Counting the learned clauses at insertion and in the store
(Cslib.Algorithms.Lean.CDCL.WatchStore.learntCount) both use it.
The reduction of the learned clauses, after MiniSat: the clause activities, by number,
bumped for the clauses met by each analysis and decaying by 1 / 0.999 (MiniSat's
clause_decay); the number of learned clauses in the watch store; their limit (MiniSat's
max_learnts, a third of the clauses of the formula to begin with, by default); and the conflicts
between increases of the limit by a tenth, which grow by half each time, and the conflicts left
before the next one (MiniSat's learntsize_adjust_confl and learntsize_adjust_cnt).
MiniSat keeps the limit and the interval as floating-point numbers. Here they are natural numbers,
the limit in thousandths of a clause, so that growing it by a tenth keeps growing it: with 27
clauses and the default divisor 3 it goes 9000, 9900, 10890, … thousandths, as MiniSat's
goes 9, 9.9, 10.89, …. Divisions truncate. Each division falls short of the exact value by
less than one unit, but the errors accumulate: from an interval of 100, four increases by half
give 505 here and 506.25 unrounded.
The reduction for a formula of m clauses, the limit starting at m / d clauses, kept in
thousandths.
After a conflict whose analysis met the clauses used and learned the clause numbered id,
the log's next number being next: the clause activities of id and of used are bumped and
decay, the learned clause is counted if it is stored, and the limit grows on schedule. The solver
passes stored only for a clause added to the watch store with a learned number (isLearntId), the
rule by which WatchStore.learntCount counts the store.
As in MiniSat, each clause is bumped once: the solver's used is the conflict clause and the reason
of each trail entry resolved, and a clause is the reason of at most one entry of a trail and never
of one when it is false, while id is the log's next number, met by no analysis. Repetitions would
only bump a clause twice: the activities are a heuristic, and nothing else depends on them.
The state of the solver with watched literals: the state Exec, the value of each variable on
the trail, the watch store, the queue of trail literals whose watch lists are still to be visited,
the clauses with fewer than two different literals, the variable activities and order, the saved
phases, the reduction of the learned clauses, the options and the statistics.
- exec : Exec φ
The trail, database and log.
- assign : Assign
The value of each variable on the trail.
- occurs : Assign
The variables occurring in the database, marked.
- store : WatchStore
The watch store.
- qhead : ℕ
The position on the trail of the next literal to process (MiniSat's
qhead): the literals still to be processed are those of the trail from it up (WExec.queue). The clauses with fewer than two different literals.
- act : Activity
The variable activities of VSIDS, which choose the decision variables.
- order : VarOrder
The variable order of VSIDS, a heap of the variables by activity, with their positions.
- phase : Phases
The saved phases, which choose the polarities of the decisions.
- red : Reduction
The reduction of the learned clauses.
- level : ℕ
The number of decisions on the trail (MiniSat's
decisionLevel), which schedules simplification. - simpAssigns : ℕ
The length of the trail at the last simplification (MiniSat's
simpDB_assigns). - opts : Options
The options.
- stats : Stats
The statistics so far.
Candidate position on
exec.trof each variable (ATrail.reasonAtself-certifies).Ping-pong scratch array reused across watch-list visits when unshared and within capacity.
Cleared assignment array reused across conflicts to mark the current decision level and the backjump target.
Cleared assignment array reused across conflicts for
seenin conflict analysis and clause-variable marks in minimization.Cleared assignment array reused across conflicts for the memo of clause minimization.
The abstract trail.
The literals of the trail from position h up, oldest first.
The literals still to be processed, oldest first: those of the trail from position
S.qhead up. It appears only in the invariant: the solver reads the trail at S.qhead.
The invariant of the variable order over the variables of φ.
The invariant of the variable order survives assigning more variables.
The invariant of the variable order survives admitting fewer variables.
The invariant of the solver with watched literals: the invariant Exec.Inv, the
invariant of the watch store, the short clauses, and a queue of distinct trail literals above the
newest decision, with VSIDS the invariant of the variable order, and the array of values agreeing
with the trail.
The number of slots for arrays indexed by the variables of φ: one more than the largest
variable, and 0 when φ has no variables ([] and [[]]).
Every variable of φ has a slot.
The initial variable order: with VSIDS, every variable of φ, inserted with room for all.
The initial state, with the options o.
The number of variables of φ, bounding the length of the trail.
The measure of a state: the rank of its abstract state, weighted above the length of the queue.
Processing a literal #
The invariant while visiting the watch list of t.negate, with the watchers L still to be
visited: as WExec.Inv, except that a clause watching t.negate may have its watcher among L
instead of on the watch list, and every clause with a watcher put back on that list has a true
literal.
- covered (e : ℕ × Array (Logic.PL.Literal ℕ)) : e ∈ S.store.clauses → ∀ (w₁ w₂ : Logic.PL.Literal ℕ) (rest : List (Logic.PL.Literal ℕ)), e.2.toList = w₁ :: w₂ :: rest → Processed S.M S.queue (Std.Sat.Literal.negate w₁) → Processed S.M S.queue (Std.Sat.Literal.negate w₂) → ∃ b ∈ e.2.toList, Supported S.M b w₁ w₂
Starting to process t: its negation's watch list is emptied and becomes the list to visit.
The watchers kept are gathered in an array of the loop (WExec.withKept), not in the store.
Finishing the processing of t: the head moves past it.
Putting a watcher, of the clause at position k with the blocker of key b, back on the watch
list of t.negate.
Putting back the watcher w just visited, or a watcher of the same clause, with a blocker
of the clause, when the clause has a true literal.
A stored clause has two watched literals.
Skipping a watcher whose blocker is true: it goes back on the watch list.
Keeping a clause whose other watched literal is true: it goes back on the watch list, with that literal as blocker.
Dropping a watcher whose clause no longer watches the literal.
The clause of a store after WatchStore.moveTo: the literals of its array, as a list.
Moving a watch to a literal that is not false.
A literal that is neither true nor false is over an unassigned variable.
UnitPropagate during processing: the literal is added to the trail, with the clause
numbered id as its reason, and queued.
A unit clause: its other watched literal is propagated and queued, and its watcher goes back on the watch list with that literal as blocker.
A conflict: the clause numbered id is a clause of the database, the log names it, and the
trail falsifies it.
The state S with its parts: the clause arrays codes, the watch lists watches, the
trail tr, the assignment A, the position hints vpos, the head of the queue q and the count
p of propagations. While the queue is processed, these are arguments of the loops, held apart from
the rest of the state, so that moving a watch, propagating a literal or moving the head updates them
without rebuilding the state or a WatchStore wrapper; the invariants of the loops are stated on
S.withParts codes watches tr A vpos q p.
The result of visiting a watch list, from the state S₀.withParts codes watches tr A vpos q p
of measure at most m with c conflicts: done, with the parts of the state and the recycled
watch-list buffer wbuf after the visit, or a conflict, with a measure at most m and still c
conflicts.
- done {φ : Logic.PL.CNF ℕ} {S₀ : WExec φ} {q p m c : ℕ} {t : Logic.PL.Literal ℕ} (codes : Array (Array ℕ)) (watches : Watches) (tr : ATrail) (A : Assign) (vpos wbuf : Array ℕ) (h : (S₀.withParts codes watches tr A vpos q p).ProcInv t []) (hm : (S₀.withParts codes watches tr A vpos q p).measure ≤ m) (hc : (S₀.withParts codes watches tr A vpos q p).stats.conflicts = c) : ProcResult φ S₀ q p m c t
Every watcher on the list was visited: the parts of the state and the recycled buffer.
- conflict {φ : Logic.PL.CNF ℕ} {S₀ : WExec φ} {q p m c : ℕ} {t : Logic.PL.Literal ℕ} (S : WExec φ) (h : S.Inv) (e : ℕ × Logic.PL.Clause ℕ) (he : e ∈ S.exec.db) (hconf : S.M.Falsifies e.2) (hm : S.measure ≤ m) (hc : S.stats.conflicts = c) : ProcResult φ S₀ q p m c t
A clause of the database is false.
The state S with kept as the watch list of t.negate. During the visit of that list, the
watchers kept are pushed on kept, an argument of the loop, and written into the store once, at the
end: the invariant of the visit is stated on S.withKept t kept.
Restoring the watch list of t.negate after a conflict: the watchers kept, then the
numbers rest of the watchers still to be visited, pairs of numbers.
Visiting a watch list, the array ws read backwards from position n, two numbers per
watcher, from a state of measure at most m with c conflicts: each watcher is visited in turn,
until a conflict. The literal {t} is erased at run time (u holds the key of t.negate),
codes and watches are held unpacked, and at the end ws is cleared in place (ATrail.popN)
and returned as the ping-pong buffer for the next literal, reused when unshared and within
capacity.
The result of processing the queue from a state of measure at most m with c conflicts:
stopped, at an empty queue or after enough literals, with a lower measure, or a conflict, with a
measure at most m; with still c conflicts either way.
- stop {φ : Logic.PL.CNF ℕ} {m c : ℕ} (T : WExec φ) (hT : T.Inv) (hm : T.measure < m) (hc : T.stats.conflicts = c) : QueueResult φ m c
The literals processed, with no conflict.
- conflict {φ : Logic.PL.CNF ℕ} {m c : ℕ} (T : WExec φ) (hT : T.Inv) (e : ℕ × Logic.PL.Clause ℕ) (he : e ∈ T.exec.db) (hconf : T.M.Falsifies e.2) (hm : T.measure ≤ m) (hc : T.stats.conflicts = c) : QueueResult φ m c
A clause of the database is false.
Processing the queue, from the state S₀.withParts codes watches tr A vpos q p with the
literal at the head q still to process, reusing the ping-pong buffer wbuf when unshared and
within capacity without building Literal pairs or WatchStore wrappers.
Moves at the top level #
The variables of the entries M, as Trail.vars of their trail (XTrail.vars_eq), mapped in
one pass.
Unassigning the variables of the entries M, folding over them, without listing them:
Assign.unassign of their variables (Assign.unassignEntries_eq).
Saving the phases of the literals of the entries M, folding over them in order: what
Phases.save does on their trail (Phases.saveEntries_eq), without listing them.
The variable order H after a conflict undoing the entries U, with VSIDS: the variables
undone are inserted with the activities A, unless they are in the heap, as MiniSat's
insertVarOrder does.
The phases after undoing the entries U: those of the literals undone are saved, if phase
saving is on.
The reduction after a conflict learning L, stored if stored: updated, if reduction is on.
One more conflict, learning a clause of k different literals, k₀ before minimization.
Assigning the current level on top of A, read from the arrays of the trail: the
decision at position p, then the entries above it, oldest first. It is Assign.assignTrail of
the level read back (ATrail.assignLevelAt_eq).
The marks after an analysis: the array the analysis returns, with the variables of the current level cleared, which leaves no value.
The marks for the backjump: the variables of the learned clause, marked in the array the analysis returned once its level is cleared.
Whether a variable is marked for the backjump. It reads one array, built once: the function is
Assign.assigned applied to jumpMarks sp L.
The marked variables are those of the learned clause: the array the analysis returns is cleared before the variables of the clause are marked.
The level kept by the backjump has a variable of the learned clause: either the trail
kept has no decision, or its top level, the decision d with the entries N above it, has the
variable of d or of an entry of N in the learned clause.
The marks after the backjump: the marks A of the backjump, those of the learned clause C
cleared again, which leaves no value.
The state with its conflict scratch arrays taken out, replaced by empty arrays, so that analysis, minimization and the backjump update them in place when unshared and within bounds.
The backjump on the arrays of the trail #
The marks for the backjump, read from the arrays of the trail: jumpMarks of the split at the
newest decision p, given L.marks and L.clause detached from L so m₀ is updated in place
(jumpMarksFrom_eq).
What undoing the entries of a backjump leaves (ATrail.undoGo).
Undoing the k entries from position lo up, newest first, in one loop over the arrays:
their variables are unassigned, put back in the variable order with VSIDS, their phases saved with
phase saving, and the decisions among them counted. Each part is the backjump's operation on the
entries T.seg lo k (ATrail.undoGo_assign, ATrail.undoGo_order, ATrail.undoGo_phase,
ATrail.undoGo_decisions).
The variable of the newest marked entry below position i, scanning down, or 0 if there
is none. Below the newest decision, with the variables of the learned clause marked, it is the
variable of the literal of the clause false at the highest level, the backjump level.
The clause C with its literal on the variable w second, if it has one after its first
literal. Stored with this order, a learned clause watches its asserting literal and, as in
MiniSat, the literal false at the backjump level, the last of the others to become unassigned when
backtracking, so that the clause is not left unit with a false watched literal.
Moving a literal second permutes the clause.
What ATrail.topMarked finds: the variable of the newest entry below position i whose
variable is marked, or 0 if there is none.
Moving the literal on w second: if a literal after the first is on the variable w,
the second literal is on w.
Moving a literal second keeps the first literal.
Backjump and Learn with watches, at the newest decision, at position p of the trail: the
state after the conflict, with the learned clause in the store, watching its asserting literal, or
among the short clauses, and the asserting literal queued. The entries undone are those from the
backjump point ATrail.cutPos up, read from the arrays of the trail and then popped
(Exec.afterConflictAt). The variables met by the analysis are bumped and, with those undone, put
back in the variable order, and the phases of the literals undone are saved; the statistics count
k₀ literals before minimization. The fields are taken out of S first, so that its arrays are
updated in place. The marks of the backjump are built once, read by the backjump and cleared after
it.
Adding a literal over an unassigned variable to the trail and the empty queue.
UnitPropagate from a short clause, at an empty queue.
The polarity of a decision on x: its saved phase, or false without phase saving.
pickVar with the variable order ord given apart from the state, so that the solver can take
it out of the state and pop the order in place.
The decision variable, and the variable order after choosing it. With VSIDS, it is popped
from the variable order (Cslib.Algorithms.Lean.CDCL.VarOrder.pop), with fuel enough to empty it
(Cslib.Algorithms.Lean.CDCL.VarOrder.pop_none). Without VSIDS, it is the first unassigned
variable of the database.
Decide the variable x, at an empty queue, with the variable order H.
With VSIDS, the decision variable has the greatest activity among the unassigned variables of the database.
With the queue empty, no clause of the database is false if no short clause is.
Restart, at an empty queue: back to the root of the trail, undoing the entries from
exec.tr.rootPos up in one pass (ATrail.undoGo, as MiniSat's cancelUntil(0) does): their
variables are unassigned in place, put back in the variable order with VSIDS, and their phases
saved with phase saving, before the trail arrays shrink in place.
Restart keeps the invariant: the processed literals kept were processed, and the clauses with both watched literals false keep their support, which is below the oldest decision.
The numbers of cand to delete: the learned ones (isLearntId n) not in locked,
without repetitions, which LRAT checkers such as drat-trim's lrat-check reject. Tested and
deduplicated via 1024-bucket tables (idBuckets, dedupIds) so that memory stays small even when
an early clause is locked or deleted alongside recent ones.
The learned clauses to forget, as MiniSat's reduceDB chooses them: the learned clauses
of the store, those of more than two literals first by increasing activity; of the less active
half, those of more than two literals, and of the other half, those of more than two literals and
activity below the increment divided by their number. Kept in any case are the clauses of φ, the
reasons of the trail (MiniSat's locked clauses) and the short clauses.
The number of learned clauses in the store, those numbered above n (isLearntId). Reduction
and simplification set the count of learned clauses from the rebuilt store, instead of subtracting
the numbers deleted.
Adding a clause to the store of two or more literals adds one to the count of learned clauses exactly when its number is a learned one.
The invariant does not read the bookkeeping of reduction and simplification, nor the statistics.
The position of a variable on the trail: on a trail without a variable twice, the
variable of the entry at position j, below n, gets j + 1.
Marking the variables of the numbered clauses db in a fresh assignment of slots slots,
without building the flattened variable list CNF.vars.
Forgetting clauses: the clauses numbered ids are forgotten, and the watch store, the
short clauses and the marks of the variables occurring in the database are rebuilt without
allocating CNF.vars. Reduction and simplification both use it, each with its own bookkeeping.
Forgetting clauses at an empty queue with no false clause, when Exec.forget keeps its
invariant, keeps the invariant and the measure, and no clause becomes false.
Forgetting the learned clauses numbered ids and rebuilding the watch store on the current
trail.
Reducing the learned clauses, at an empty queue: the clauses chosen are forgotten, and the watch store is rebuilt on the current trail. If none is chosen, nothing changes: the store is not rebuilt and the certificate gets no deletion step.
MiniSat's reduceDB, when due: if reduction is on and the learned clauses in the store
exceed the assigned variables by the limit, reduce.
Simplifying at the root #
The clauses to delete at the root (MiniSat's removeSatisfied, on the learned clauses, and
on the input clauses with removeSatisfied): those satisfied by a literal of the root of the
trail, except the reasons of the trail.
Simplifying at the root (MiniSat's simplify): the clauses satisfied by the root are
forgotten, input clauses included, and the watch store and the marks of the variables occurring in
the database are rebuilt.
MiniSat's simplify, when due: at decision level 0, if the trail grew since the last
simplification. The cached level is checked first; the trail is then checked to have no decision,
so that simplification provably happens at the root (WExec.maybeSimplify_root) whatever the
cache holds.
Simplification happens at the root: either nothing happens, or the trail has no decision.
The number of a learned clause is a learned number: the log's next number, beyond the clauses
of φ.
The count of learned clauses at insertion: with reduction on, a conflict whose learned
clause goes to the watch store (two or more literals) counts it exactly when its number is a
learned one (isLearntId), the rule by which WatchStore.learntCount counts the store
(WatchStore.learntCount_addClause).
A bound on the measure of every state, plus one; so on the conflicts of a run of the loop.
The answer of the solver, with its correctness: a model, or an LRUP (RUP-only LRAT)
certificate accepted by CNF.checkLRUP.
- sat {φ : Logic.PL.CNF ℕ} (σ : ℕ → Bool) (h : Logic.PL.CNF.eval σ φ = true) : Answer φ
A model.
- unsat {φ : Logic.PL.CNF ℕ} (cert : Array Std.Tactic.BVDecide.LRAT.IntAction) (h : φ.checkLRUP cert = true) : Answer φ
An accepted LRUP certificate.
A run of the loop for up to 2 ^ d moves from the state S, started with c₀ conflicts:
the answer with the statistics; a restarted state, whose conflicts have reached the limit and are
fewer than c₀ + restartBound φ; or, after 2 ^ d moves, the state reached, whose measure is
lower by at least 2 ^ d and whose conflicts plus measure have not grown.
- done {φ : Logic.PL.CNF ℕ} {limit : Option ℕ} {c₀ : ℕ} {S : WExec φ} {d : ℕ} (r : Answer φ × Stats) : Run φ limit c₀ S d
The answer, with the statistics.
- restart {φ : Logic.PL.CNF ℕ} {limit : Option ℕ} {c₀ : ℕ} {S : WExec φ} {d : ℕ} (S' : WExec φ) (h : S'.Inv) (hr : ∃ (n : ℕ), limit = some n ∧ n ≤ S'.stats.conflicts ∧ S'.stats.conflicts < c₀ + restartBound φ) : Run φ limit c₀ S d
A restarted state, whose conflicts have reached the limit and are fewer than
c₀ + restartBound φ. - next {φ : Logic.PL.CNF ℕ} {limit : Option ℕ} {c₀ : ℕ} {S : WExec φ} {d : ℕ} (T : WExec φ) (hT : T.Inv) (hm : T.measure + 2 ^ d ≤ S.measure) (hc : T.stats.conflicts + T.measure ≤ S.stats.conflicts + S.measure) : Run φ limit c₀ S d
The state after
2 ^ dmoves.
One move to the state T, which lowers the measure and counts at most one conflict.
A move of the CDCL loop with watched literals, restarting once the number of conflicts
reaches limit, if any. While the queue is not empty, the watch list of the negation of its first
literal is visited; a conflict is analysed, followed by Backjump and Learn, or ends with a
certificate when there is no decision. With the queue empty, the short clauses are checked for a
conflict or a unit; then the loop restarts if the limit is reached, decides an unassigned variable
of the database, or returns the trail as a model. A move lowers the measure and counts at most one
conflict, so the conflicts plus the measure never grow; as they start below c₀ + restartBound φ,
a restarted state has fewer conflicts than that.
The CDCL loop with watched literals: up to 2 ^ d moves (step), by running 2 ^ (d - 1)
moves twice. Each move lowers the measure, so d with S.measure < 2 ^ d lets the loop run until
it answers or restarts (solveWith.search). The recursion is structural on d, so the kernel can
run the solver, and the measure is only used in proofs; at run time a move costs no arithmetic on
the bound, and the recursion is at most d deep.
Search with restarts: runs of the loop, the i-th restarting after o.restartBudget i
conflicts, if restarts are on. A run has fewer conflicts than restartBound φ, so a run whose
budget exceeds it does not restart; one comes within k runs, so the search ends there. A loop
of solveWith, which starts it from WExec.init φ o, at the first run, with enough runs.
The CDCL solver with options: a model, or an LRAT certificate of unsatisfiability, with the statistics of the run.
The CDCL solver, with the default options.
The models returned by the solver are models, whatever the options.
The certificates returned by the solver are accepted by the LRUP (RUP-only LRAT) checker, whatever the options.
The solver decides satisfiability, whatever the options.
The models returned by the solver are models.
The certificates returned by the solver are accepted by the LRUP (RUP-only LRAT) checker.
The solver decides satisfiability.
Renaming the variables first #
The CDCL solver on renamed variables, with options: it renames the variables of φ to
0, …, k - 1, solves the renamed formula, and translates the model or certificate back, so its
arrays are indexed by at most k variables.
The CDCL solver on renamed variables, with the default options.
The models returned on renamed variables are models.
The certificates returned on renamed variables are accepted by the LRUP (RUP-only LRAT) checker.
The solver on renamed variables decides satisfiability, whatever the options.