Documentation

CslibFrontier.Algorithms.Lean.CDCL.Watched

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 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 #

Main results #

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 level 0.

  • 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 least 1; here 0 counts as 1 (Options.restartBudget).

    • restartInc : ℕ

      The growth of the conflicts between restarts (MiniSat's restart_inc). MiniSat requires it to exceed 1; here 0 and 1 count as 2, so that the budgets are unbounded (Options.restartBudget). With the Luby sequence, the peaks are restartInc ^ m (Cslib.Algorithms.Lean.CDCL.luby_pow), unbounded from base 2.

    • 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.

        @[specialize #[]]
        def Cslib.Algorithms.Lean.CDCL.sortBy.merge {α : Type} (le : α → α → Bool) (fuel : ℕ) :
        List α → List α → List α

        Merging two lists sorted by le, in at most fuel steps. A loop of sortBy, which supplies enough fuel.

        The elements of a list at even positions, and those at odd positions.

        @[specialize #[]]
        def Cslib.Algorithms.Lean.CDCL.sortBy.go {α : Type} (le : α → α → Bool) (fuel : ℕ) :
        List α → List α

        Merge sort by le, to depth fuel. A loop of sortBy, which supplies enough fuel.

        @[specialize #[]]
        def Cslib.Algorithms.Lean.CDCL.sortBy {α : Type} (le : α → α → Bool) (xs : List α) :
        List α

        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.

        • act : Activity

          The clause activities, by number.

        • learnts : ℕ

          The learned clauses in the watch store.

        • max : ℕ

          The limit on the learned clauses beyond the assigned variables, in thousandths.

        • adjust : ℕ

          The conflicts between increases of the limit.

        • countdown : ℕ

          The conflicts left before the next increase.

        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.

        • vpos : Array ℕ

          Candidate position on exec.tr of each variable (ATrail.reasonAt self-certifies).

        • wbuf : Array ℕ

          Ping-pong scratch array reused across watch-list visits when unshared and within capacity.

        • marks : { A : Assign // ∀ (v : ℕ), A.value v = none }

          Cleared assignment array reused across conflicts to mark the current decision level and the backjump target.

        • seenMarks : { A : Assign // ∀ (v : ℕ), A.value v = none }

          Cleared assignment array reused across conflicts for seen in conflict analysis and clause-variable marks in minimization.

        • memoMarks : { A : Assign // ∀ (v : ℕ), A.value v = none }

          Cleared assignment array reused across conflicts for the memo of clause minimization.

        @[reducible, inline]

        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 queue starts with the literal at S.qhead.

        Pushing an entry on the trail queues its literal last.

        With the head at the end of the trail, pushing an entry makes it the whole queue.

        @[reducible, inline]

        The invariant of the variable order over the variables of φ.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.OrderInv.extend {φ : Logic.PL.CNF ℕ} {S S' : WExec φ} (h : S.OrderInv) (horder : S'.order = S.order) (hact : S'.act = S.act) (hocc : S'.occurs = S.occurs) (hM : ∀ v ∈ S.M.vars, v ∈ S'.M.vars) :

        The invariant of the variable order survives assigning more variables.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.OrderInv.restrict {φ : Logic.PL.CNF ℕ} {S S' : WExec φ} (h : S.OrderInv) (horder : S'.order = S.order) (hact : S'.act = S.act) (hM : S'.M = S.M) (hocc : ∀ (v : ℕ), S'.occurs.assigned v = true → S.occurs.assigned v = true) :

        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 empty cleared scratch assignment, placed in the state while its scratch arrays are updated in place.

        The initial state, with the options o.

        @[reducible, inline]

        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.

        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.

        Finishing the head of the queue removes it.

        theorem Cslib.Algorithms.Lean.CDCL.otherWatch_spec {u w₁ w₂ : Logic.PL.Literal ℕ} (hne : w₁ ≠ w₂) :
        (w₁ = u → otherWatch u w₁ w₂ = w₂) ∧ (w₂ = u → otherWatch u w₁ w₂ = w₁)
        theorem Cslib.Algorithms.Lean.CDCL.otherWatch_mem {u w₁ w₂ : Logic.PL.Literal ℕ} {rest : Logic.PL.Clause ℕ} :
        otherWatch u w₁ w₂ ∈ w₁ :: w₂ :: rest

        Putting a watcher, of the clause at position k with the blocker of key b, back on the watch list of t.negate.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.ProcInv.putBack {φ : Logic.PL.CNF ℕ} {S : WExec φ} {t : Logic.PL.Literal ℕ} {w : Watcher} {L : List Watcher} (h : S.ProcInv t (w :: L)) (k b : ℕ) (hx : k = w.clause) (hmem : ∃ (hk : k < S.store.clauses.size), litOfKey b ∈ S.store.clauses[k].2.toList) (htrue : ∀ (hk : k < S.store.clauses.size), ∃ b ∈ S.store.clauses[k].2.toList, b ∈ S.M.lits) :
        (S.putBack t k b).ProcInv t L

        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.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.ProcInv.exists_cons {φ : Logic.PL.CNF ℕ} {S : WExec φ} {t : Logic.PL.Literal ℕ} {L : List Watcher} (h : S.ProcInv t L) {k : ℕ} (hk : k < S.store.clauses.size) :
        ∃ (w₁ : Logic.PL.Literal ℕ) (w₂ : Logic.PL.Literal ℕ) (rest : List (Logic.PL.Literal ℕ)), S.store.clauses[k].2.toList = w₁ :: w₂ :: rest

        A stored clause has two watched literals.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.ProcInv.skip {φ : Logic.PL.CNF ℕ} {S : WExec φ} {t : Logic.PL.Literal ℕ} {k b : ℕ} {L : List Watcher} (h : S.ProcInv t ({ clause := k, blocker := litOfKey b } :: L)) (hv : VisitSpec S.store S.M (Std.Sat.Literal.negate t) { clause := k, blocker := litOfKey b } Visit.skip) :
        (S.putBack t k b).ProcInv t L

        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.

        theorem Cslib.Algorithms.Lean.CDCL.perm_cons_set {α : Type} {rest : List α} {i : ℕ} {x u : α} (h : rest[i]? = some x) :
        (x :: rest.set i u).Perm (u :: rest)

        Putting u in place of the element x at position i, then x in front, permutes u in front of the list.

        theorem Cslib.Algorithms.Lean.CDCL.toList_moveTo {a : Array (Logic.PL.Literal ℕ)} {w₁ w₂ o x u : Logic.PL.Literal ℕ} {rest : Logic.PL.Clause ℕ} {i : ℕ} (ha : a.toList = w₁ :: w₂ :: rest) :
        (((a.setIfInBounds 0 o).setIfInBounds 1 x).setIfInBounds (i + 2) u).toList = o :: x :: List.set rest i u

        The clause of a store after WatchStore.moveTo: the literals of its array, as a list.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.ProcInv.move {φ : Logic.PL.CNF ℕ} {S : WExec φ} {t : Logic.PL.Literal ℕ} {w : Watcher} {L : List Watcher} {j : ℕ} {x b : Logic.PL.Literal ℕ} (h : S.ProcInv t (w :: L)) (hv : VisitSpec S.store S.M (Std.Sat.Literal.negate t) w (Visit.move j x b)) :
        { exec := S.exec, assign := S.assign, occurs := S.occurs, store := S.store.moveTo w.clause j (WordRAM.ClauseCode.litCode b) (WordRAM.ClauseCode.litCode x) (WordRAM.ClauseCode.litCode (Std.Sat.Literal.negate t)), qhead := S.qhead, short := S.short, act := S.act, order := S.order, phase := S.phase, red := S.red, level := S.level, simpAssigns := S.simpAssigns, opts := S.opts, stats := S.stats, vpos := S.vpos, wbuf := S.wbuf, marks := S.marks, seenMarks := S.seenMarks, memoMarks := S.memoMarks }.ProcInv t L

        Moving a watch to a literal that is not false.

        A variable of the trail has a literal on it.

        theorem Cslib.Algorithms.Lean.CDCL.not_mem_vars_of_undef {M : Trail} {l : Logic.PL.Literal ℕ} (h₁ : l ∉ M.lits) (h₂ : Std.Sat.Literal.negate l ∉ M.lits) :
        l.1 ∉ M.vars

        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.

        def Cslib.Algorithms.Lean.CDCL.WExec.withParts {φ : Logic.PL.CNF ℕ} (S : WExec φ) (codes : Array (Array ℕ)) (watches : Watches) (tr : ATrail) (A : Assign) (vpos : Array ℕ) (q p : ℕ) :

        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.

        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.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.ProcInv.restore_inv {φ : Logic.PL.CNF ℕ} {S : WExec φ} {t : Logic.PL.Literal ℕ} {kept rest : Array ℕ} (h : (S.withKept t kept).ProcInv t (unpackWatchers rest.toList.reverse)) (he : rest.size % 2 = 0) :
        (S.withKept t (kept ++ rest)).Inv ∧ (S.withKept t (kept ++ rest)).measure = (S.withKept t kept).measure

        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.

        def Cslib.Algorithms.Lean.CDCL.WExec.processFrom {φ : Logic.PL.CNF ℕ} {t : Logic.PL.Literal ℕ} (u : ℕ) (hu : u = WordRAM.ClauseCode.litCode (Std.Sat.Literal.negate t)) (m c n : ℕ) (ws kept : Array ℕ) (S : WExec φ) (codes : Array (Array ℕ)) (watches : Watches) (tr : ATrail) (A : Assign) (vpos : Array ℕ) (q p : ℕ) :
        n ≤ ws.size → ((S.withParts codes watches tr A vpos q p).withKept t kept).ProcInv t (unpackWatchers (List.take n ws.toList).reverse) → (S.withParts codes watches tr A vpos q p).measure ≤ m → (S.withParts codes watches tr A vpos q p).stats.conflicts = c → ProcResult φ S q p m c t

        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.

        def Cslib.Algorithms.Lean.CDCL.WExec.processQueue {φ : Logic.PL.CNF ℕ} (S₀ : WExec φ) (m c fuel : ℕ) (codes : Array (Array ℕ)) (watches : Watches) (tr : ATrail) (A : Assign) (vpos wbuf : Array ℕ) (q p : ℕ) :
        q < tr.size → (S₀.withParts codes watches tr A vpos q p).Inv → (S₀.withParts codes watches tr A vpos q p).measure ≤ m → (S₀.withParts codes watches tr A vpos q p).stats.conflicts = c → QueueResult φ m c

        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 #

        theorem Cslib.Algorithms.Lean.CDCL.lits_below {N M₀ : Trail} {d x : Logic.PL.Literal ℕ} (hx : x ∈ M₀.lits) :
        x ∈ (N ++ { lit := d, decision := true } :: M₀).lits

        The literals below a decision of a trail are on the trail.

        A learned clause has no repetitions.

        The activities A and the variable order H after a conflict meeting the variables vs, listed once each, with VSIDS: the variables are bumped, and those in the heap move up (VarOrder.bumpDistinct).

        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 variables undone are inserted as VarOrder.addAll inserts them, without listing them.

        The phases P after undoing the entries U: those of the literals undone are saved, if phase saving is on.

        The phases after undoing the entries U: those of the literals undone are saved, if phase saving is on.

        def Cslib.Algorithms.Lean.CDCL.reducedWith (o : Options) (R : Reduction) (used : List ℕ) (id next : ℕ) (stored : Bool) :

        The reduction R after a conflict meeting the clauses used and learning the clause numbered id, the log's next number being next, stored if stored: updated, if reduction 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).

        def Cslib.Algorithms.Lean.CDCL.clearedMarks {φ : Logic.PL.CNF ℕ} {log : φ.LRATLog} (sp : Split) (L : Learned log (sp.above.trail ++ [{ lit := sp.decision, decision := true }]) sp.below.trail) :
        { A : Assign // ∀ (v : ℕ), A.value v = none }

        The marks after an analysis: the array the analysis returns, with the variables of the current level cleared, which leaves no value.

        def Cslib.Algorithms.Lean.CDCL.jumpMarks {φ : Logic.PL.CNF ℕ} {log : φ.LRATLog} (sp : Split) (L : Learned log (sp.above.trail ++ [{ lit := sp.decision, decision := true }]) sp.below.trail) :

        The marks for the backjump: the variables of the learned clause, marked in the array the analysis returned once its level is cleared.

        def Cslib.Algorithms.Lean.CDCL.jumpMarked {φ : Logic.PL.CNF ℕ} {log : φ.LRATLog} (sp : Split) (L : Learned log (sp.above.trail ++ [{ lit := sp.decision, decision := true }]) sp.below.trail) :
        ℕ → Bool

        Whether a variable is marked for the backjump. It reads one array, built once: the function is Assign.assigned applied to jumpMarks sp L.

        theorem Cslib.Algorithms.Lean.CDCL.jumpMarked_iff {φ : Logic.PL.CNF ℕ} {log : φ.LRATLog} (sp : Split) (L : Learned log (sp.above.trail ++ [{ lit := sp.decision, decision := true }]) sp.below.trail) (v : ℕ) :

        The marked variables are those of the learned clause: the array the analysis returns is cleared before the variables of the clause are marked.

        theorem Cslib.Algorithms.Lean.CDCL.jumpMarked_of_mem {φ : Logic.PL.CNF ℕ} {log : φ.LRATLog} (sp : Split) (L : Learned log (sp.above.trail ++ [{ lit := sp.decision, decision := true }]) sp.below.trail) (v : ℕ) :
        theorem Cslib.Algorithms.Lean.CDCL.ExecL.jump_kept_learned {φ : Logic.PL.CNF ℕ} {S : ExecL φ} (sp : Split) (L : S.LearnedAt sp) :
        (∀ x ∈ (S.jump sp (jumpMarked sp L)).2, x.entry.decision = false) ∨ ∃ (N : List XEntry) (d : Logic.PL.Literal ℕ) (M₀ : List XEntry), (S.jump sp (jumpMarked sp L)).2 = N ++ XEntry.decision d :: M₀ ∧ (∀ x ∈ N, x.entry.decision = false) ∧ (d.1 ∈ List.map Prod.fst L.clause ∨ ∃ x ∈ N, x.entry.lit.1 ∈ List.map Prod.fst L.clause)

        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).

        • assign : Assign

          The assignment with the variables undone unassigned.

        • order : VarOrder

          The variable order with the variables undone put back.

        • phase : Phases

          The phases with those of the literals undone saved.

        • decisions : ℕ

          The decisions among the entries undone.

        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).

        theorem Cslib.Algorithms.Lean.CDCL.ATrail.undoGo_assign (T : ATrail) (o : Options) (act : Activity) (lo k : ℕ) (A : Assign) (H : VarOrder) (P : Phases) (n : ℕ) :
        (T.undoGo o act lo k A H P n).assign = A.unassignEntries (T.seg lo k)
        theorem Cslib.Algorithms.Lean.CDCL.ATrail.undoGo_order (T : ATrail) (o : Options) (act : Activity) (lo k : ℕ) (A : Assign) (H : VarOrder) (P : Phases) (n : ℕ) :
        (T.undoGo o act lo k A H P n).order = reorderedWith o H act (T.seg lo k)
        theorem Cslib.Algorithms.Lean.CDCL.ATrail.undoGo_phase (T : ATrail) (o : Options) (act : Activity) (lo k : ℕ) (A : Assign) (H : VarOrder) (P : Phases) (n : ℕ) :
        (T.undoGo o act lo k A H P n).phase = savedWith o P (T.seg lo k)
        theorem Cslib.Algorithms.Lean.CDCL.ATrail.undoGo_decisions (T : ATrail) (o : Options) (act : Activity) (lo k : ℕ) (A : Assign) (H : VarOrder) (P : Phases) (n : ℕ) :
        (T.undoGo o act lo k A H P n).decisions = n + List.countP XEntry.isDecision (T.seg lo k)

        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.

        theorem Cslib.Algorithms.Lean.CDCL.ATrail.topMarked_eq (T : ATrail) (marked : ℕ → Bool) (i : ℕ) :
        T.topMarked marked i = (Option.map (fun (x : XEntry) => x.lit.1) (List.find? (fun (e : XEntry) => marked e.lit.1) (T.seg 0 i))).getD 0

        What ATrail.topMarked finds: the variable of the newest entry below position i whose variable is marked, or 0 if there is none.

        theorem Cslib.Algorithms.Lean.CDCL.secondOn_var {w : ℕ} {l : Logic.PL.Literal ℕ} {rest : Logic.PL.Clause ℕ} (h : ∃ y ∈ rest, y.1 = w) :
        ∃ (y : Logic.PL.Literal ℕ) (rest' : List (Logic.PL.Literal ℕ)), secondOn w (l :: rest) = l :: y :: rest' ∧ y.1 = w

        Moving the literal on w second: if a literal after the first is on the variable w, the second literal is on w.

        theorem Cslib.Algorithms.Lean.CDCL.secondOn_cons (w : ℕ) (l : Logic.PL.Literal ℕ) (rest : Logic.PL.Clause ℕ) :
        ∃ (rest' : List (Logic.PL.Literal ℕ)), secondOn w (l :: rest) = l :: rest'

        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.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.afterConflict_spec {φ : Logic.PL.CNF ℕ} {S : WExec φ} (hS : S.Inv) {e : ℕ × Logic.PL.Clause ℕ} (he : e ∈ S.exec.db) (hconf : S.M.Falsifies e.2) {p : ℕ} (hp : S.exec.tr.IsNewest p) (L : S.exec.LearnedAt (S.exec.tr.splitAt p)) (k₀ : ℕ) :
        (S.afterConflict p L k₀).Inv ∧ (S.afterConflict p L k₀).measure < S.measure
        theorem Cslib.Algorithms.Lean.CDCL.WExec.Inv.push {φ : Logic.PL.CNF ℕ} {S S' : WExec φ} (hS : S.Inv) (hq : S.queue = []) {l : Logic.PL.Literal ℕ} {b : Bool} (hexec : S'.exec.Inv) (hM : S'.M = { lit := l, decision := b } :: S.M) (hq' : S'.queue = [l]) (hdb : S'.exec.db = S.exec.db) (hstore : S'.store = S.store) (hshort : S'.short = S.short) (hundef : l.1 ∉ S.M.vars) (horder : S'.opts.vsids = true → S'.OrderInv) (hassign : S'.assign = S.assign.assign l) (hocc : S'.occurs = S.occurs) :
        S'.Inv

        Adding a literal over an unassigned variable to the trail and the empty queue.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.measure_push_lt {φ : Logic.PL.CNF ℕ} {S S' : WExec φ} (hq : S.queue = []) (hq' : S'.queue.length = 1) (hrank : rank φ.vars S'.exec.state < rank φ.vars S.exec.state) :

        The measure falls when the rank falls and one literal is queued on an 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.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.M_decide {φ : Logic.PL.CNF ℕ} (S : WExec φ) (x : ℕ) (H : VarOrder) :
        (S.decide x H).M = { lit := (x, S.polarity x), decision := true } :: S.M

        The variables of the database are variables of φ.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.Inv.pickVar_some {φ : Logic.PL.CNF ℕ} {S : WExec φ} (hS : S.Inv) {x : ℕ} {H : VarOrder} (h : S.pickVar = { var := some x, order := H }) :
        x ∈ S.exec.clauses.vars ∧ x ∉ S.M.vars

        The decision variable is an unassigned variable of the database.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.Inv.pickVar_none {φ : Logic.PL.CNF ℕ} {S : WExec φ} (hS : S.Inv) {H : VarOrder} (h : S.pickVar = { var := none, order := H }) (x : ℕ) :
        x ∈ S.exec.clauses.vars → x ∈ S.M.vars

        Without a decision variable, every variable of the database is assigned.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.Inv.pickVar_max {φ : Logic.PL.CNF ℕ} {S : WExec φ} (hS : S.Inv) (hv : S.opts.vsids = true) {x : ℕ} {H : VarOrder} (h : S.pickVar = { var := some x, order := H }) (y : ℕ) :
        y ∈ S.exec.clauses.vars → y ∉ S.M.vars → S.act.get y ≤ S.act.get x

        With VSIDS, the decision variable has the greatest activity among the unassigned variables of the database.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.Inv.pickVar_order {φ : Logic.PL.CNF ℕ} {S : WExec φ} (hS : S.Inv) {x : ℕ} {H : VarOrder} (h : S.pickVar = { var := some x, order := H }) (hv : (S.decide x H).opts.vsids = true) :

        After deciding the decision variable, the variable order keeps its invariant.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.Inv.noConflict {φ : Logic.PL.CNF ℕ} {S : WExec φ} (hS : S.Inv) (hq : S.queue = []) (hshort : ∀ e ∈ S.short, ¬S.M.Falsifies e.2) (c : Logic.PL.Clause ℕ) :

        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.

        theorem Cslib.Algorithms.Lean.CDCL.mem_chooseIds {n : ℕ} {locked cand : List ℕ} {i : ℕ} :
        i ∈ chooseIds n locked cand ↔ i ∈ cand ∧ n < i ∧ i ∉ locked

        The numbers chosen are the learned ones of cand not in locked.

        theorem Cslib.Algorithms.Lean.CDCL.nodup_chooseIds (n : ℕ) (locked cand : List ℕ) :
        (chooseIds n locked cand).Nodup

        Each number is chosen once.

        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.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.Inv.withBookkeeping {φ : Logic.PL.CNF ℕ} {S : WExec φ} (h : S.Inv) (red : Reduction) (simpAssigns : ℕ) (stats : Stats) :
        { exec := S.exec, assign := S.assign, occurs := S.occurs, store := S.store, qhead := S.qhead, short := S.short, act := S.act, order := S.order, phase := S.phase, red := red, level := S.level, simpAssigns := simpAssigns, opts := S.opts, stats := stats, vpos := S.vpos, wbuf := S.wbuf, marks := S.marks, seenMarks := S.seenMarks, memoMarks := S.memoMarks }.Inv

        The invariant does not read the bookkeeping of reduction and simplification, nor the statistics.

        The positions of the variables on the trail, one past each, 0 for a variable not on it, in an array of n slots. They order the watches of a rebuilt store (watchOrderAt).

        The positions of the variables of the k entries from position i up, set in P.

        theorem Cslib.Algorithms.Lean.CDCL.ATrail.positions_lit {T : ATrail} {n j : ℕ} (hj : j < T.size) (hnd : ∀ i < T.size, (T.lit i).1 = (T.lit j).1 → i = j) (hn : (T.lit j).1 < n) :
        (T.positions n).getD (T.lit j).1 0 = j + 1

        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.

        theorem Cslib.Algorithms.Lean.CDCL.ATrail.positions_of_not_mem {T : ATrail} {n v : ℕ} (hv : ∀ j < T.size, (T.lit j).1 ≠ v) :
        (T.positions n).getD v 0 = 0

        A variable not on the trail gets 0.

        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.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.Inv.forgetRebuilt {φ : Logic.PL.CNF ℕ} {S : WExec φ} (hS : S.Inv) (hq : S.queue = []) (hnoconf : ∀ c ∈ S.exec.clauses, ¬S.M.Falsifies c) {ids : List ℕ} (hexec : (S.exec.forget ids).Inv) :

        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.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.mem_reduceIds {φ : Logic.PL.CNF ℕ} {S : WExec φ} {i : ℕ} (h : i ∈ S.reduceIds) :
        List.length φ < i ∧ i ∉ S.exec.trail.reasonIds ∧ ∀ e ∈ S.short, e.1 ≠ i
        theorem Cslib.Algorithms.Lean.CDCL.WExec.Inv.reduce {φ : Logic.PL.CNF ℕ} {S : WExec φ} (hS : S.Inv) (hq : S.queue = []) (hnoconf : ∀ c ∈ S.exec.clauses, ¬S.M.Falsifies c) :

        Reducing at an empty queue with no false clause keeps the invariant and the measure, and no clause becomes false.

        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.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.mem_simplifyIds {φ : Logic.PL.CNF ℕ} {S : WExec φ} (hS : S.Inv) {i : ℕ} (h : i ∈ S.simplifyIds) :
        i ∉ S.exec.trail.reasonIds ∧ ∃ e ∈ S.exec.db, e.1 = i ∧ ∃ l ∈ e.2, l ∈ S.exec.trail.root.trail.lits

        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.

        theorem Cslib.Algorithms.Lean.CDCL.WExec.Inv.simplify {φ : Logic.PL.CNF ℕ} {S : WExec φ} (hS : S.Inv) (hq : S.queue = []) (hnoconf : ∀ c ∈ S.exec.clauses, ¬S.M.Falsifies c) :

        Simplifying at an empty queue with no false clause keeps the invariant and the measure, and no clause becomes false.

        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 conflict counts one.

        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.

        inductive Cslib.Algorithms.Lean.CDCL.Run (φ : Logic.PL.CNF ℕ) (limit : Option ℕ) (c₀ : ℕ) (S : WExec φ) (d : ℕ) :

        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.

        def Cslib.Algorithms.Lean.CDCL.Run.move {φ : Logic.PL.CNF ℕ} {limit : Option ℕ} {c₀ : ℕ} {S : WExec φ} (T : WExec φ) (hT : T.Inv) (hm : T.measure < S.measure) (hc : T.stats.conflicts ≤ S.stats.conflicts + 1) :
        Run φ limit c₀ S 0

        One move to the state T, which lowers the measure and counts at most one conflict.

        def Cslib.Algorithms.Lean.CDCL.step (φ : Logic.PL.CNF ℕ) (limit : Option ℕ) (c₀ : ℕ) (S : WExec φ) (hS : S.Inv) (hP : S.stats.conflicts + S.measure < c₀ + restartBound φ) :
        Run φ limit c₀ S 0

        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.

        def Cslib.Algorithms.Lean.CDCL.loop (φ : Logic.PL.CNF ℕ) (limit : Option ℕ) (c₀ d : ℕ) (S : WExec φ) :
        S.Inv → S.stats.conflicts + S.measure < c₀ + restartBound φ → Run φ limit c₀ S d

        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.

        def Cslib.Algorithms.Lean.CDCL.solveWith.search (φ : Logic.PL.CNF ℕ) (o : Options) (D : ℕ) (hD : restartBound φ < 2 ^ D) (i k : ℕ) (S : WExec φ) :
        S.Inv → (∃ (j : ℕ), i ≤ j ∧ j ≤ i + k ∧ restartBound φ < o.restartBudget j) → Answer φ × Stats

        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.