An LRAT checker for kernel reduction #
Cslib.Logic.PL.CNF.checkLRATRat is the reference LRAT checker with RAT steps
Cruz-Filipe et al.. The kernel can evaluate it,
but it keeps its clause database and its trail of true literals in lists: looking up a hinted
clause searches the list of all clauses, and testing whether a literal is false searches the
trail. Cslib.Logic.PL.CNF.checkLRATKernel checks the same certificates with data the kernel
reduces quickly:
- the clause database is a binary trie keyed by the digits of the clause number in bijective
base 2, least significant first (
Cslib.Logic.PL.CNF.ClauseTrie), so that looking up, adding and deleting a clause take a number of reduction steps proportional to the number's length; - the trail of a step is a bitmask, a natural number with the literal
(v, b)at bit2 v + b, its word code (Cslib.Algorithms.WordRAM.ClauseCode.litCode). Testing a literal isNat.testBit, a shift right and a conjunction, and setting it is a disjunction with a shifted1. The kernel evaluates these operations on numerals with GMP. Each step starts again from0, so no literal is ever unset.
The checker uses structural recursion only, and no Array. Looking up and deleting recurse on
the trie, and deleting stops at the first missing subtrie. Adding a clause may build the path to
its number, so it recurses on a bound on the number's length instead: the number itself.
As in checkLRATFast, the trail is indexed by literal rather than by variable: the reference
checker's trail holds both polarities of a variable when the added clause contains both, which
makes both literals false.
It checks RUP additions, empty-clause steps and deletions with the trie and the bitmask, and RAT
additions with the check Cslib.Logic.PL.CNF.ratWith of checkLRATRat, reading the trie and
visiting every clause it stores (Cslib.Logic.PL.CNF.ClauseTrie.all); within a RAT step the
trail is a list. It agrees with checkLRATRat on every formula and certificate
(Cslib.Logic.PL.CNF.checkLRATKernel_eq_checkLRATRat). Rewriting with that equation,
Cslib.Logic.PL.CNF.not_satisfiable_of_checkLRATRat and
Cslib.Algorithms.Lean.DPLL.exists_checkLRATRat_iff give its soundness and completeness. It
accepts every certificate of the RUP-only checker Cslib.Logic.PL.CNF.checkLRUP
(Cslib.Logic.PL.CNF.checkLRATRat_of_checkLRUP).
With PR steps, Cslib.Logic.PL.CNF.checkLPRKernel checks LPR certificates
Tan et al. as Cslib.Logic.PL.CNF.checkLPR does
(Cslib.Logic.PL.CNF.checkLPRKernel_eq_checkLPR): a PR step runs the check
Cslib.Logic.PL.CNF.prWith on the trie, as a RAT step runs ratWith.
It is the checker for kernel reduction. In compiled and interpreted code the array-based
Cslib.Logic.PL.CNF.checkLRATFast is faster, by 4.8 to 6.5 times compiled on SATLIB-scale
certificates and by 1.8 to 4 times interpreted on lrat_tauto's; in the kernel this checker is
the faster by far (0.67 s against 62.8 s on lrat_tauto's chain of 80 implications). The
measurements are in the module docstring of checkLRATFast.
Main definitions #
Cslib.Logic.PL.CNF.ClauseTrie: the clause database.Cslib.Logic.PL.CNF.checkLRATKernel: the checker.Cslib.Logic.PL.CNF.checkLPRKernel: the checker with PR steps.
Main results #
Cslib.Logic.PL.CNF.ClauseTrie.get_insert,Cslib.Logic.PL.CNF.ClauseTrie.get_erase: reading the trie after storing or deleting a clause.Cslib.Logic.PL.CNF.checkLRATKernel_eq_checkLRATRat: the checker agrees withcheckLRATRat.Cslib.Logic.PL.CNF.checkLPRKernel_eq_checkLPR: the checker with PR steps agrees withcheckLPR.
References #
The clause database #
A clause database as a binary trie keyed by clause number. The number 0 is stored at the
root, and the number n + 1 in the subtrie zero if n is even and one if n is odd, under
the key n / 2. So a number is found by reading the digits 1 and 2 of its bijective base-2
numeral, least significant first, and the trie has a node for every number of its paths. An
absent subtrie is a leaf.
- leaf : ClauseTrie
The empty trie.
- node (val : Option (Clause ℕ)) (zero one : ClauseTrie) : ClauseTrie
The clause numbered
0, if any, and the subtries of the numbersn + 1withneven andnodd.
The clause stored under the number n. The number is matched against 0 and n + 1, which
the kernel reduces faster than a test n = 0.
Store x under the number n, which has at most fuel digits. The recursion is on fuel,
since the path to n may not exist yet.
Store x under the number n: some c adds the clause c, and none deletes it.
The trie of an association list of numbered clauses; an earlier entry shadows a later one with
the same number, as in List.lookup.
Delete the clauses with the given numbers.
Whether f n c holds for every clause c stored under a number n. The numbers are rebuilt
from the path: the key k of the subtrie zero is the number 2 k + 1, and of one the
number 2 k + 2.
Trails as bitmasks #
The residual of a clause under the literals set in the bitmask mask, as
Cslib.Logic.PL.Clause.residual under a trail.
Unit propagation along hints, as Cslib.Logic.PL.CNF.propagateHints, reading the hinted
clauses from a trie and keeping the trail in a bitmask.
The checker on a clause database, with PR steps if lpr.
The LRAT checker for kernel reduction: it accepts exactly the certificates that
CNF.checkLRATRat accepts (CNF.checkLRATKernel_eq_checkLRATRat), RAT steps included, with the
clauses of φ numbered from 1. Clauses are looked up in a binary trie keyed by number, and the
literals assumed true in a RUP step are the bits set in a natural number. It is for kernel
reduction (decide); compiled and interpreted code should use the faster CNF.checkLRATFast.
The LPR checker for kernel reduction: it accepts exactly the certificates that
CNF.checkLPR accepts (CNF.checkLPRKernel_eq_checkLPR), on the trie and the bitmasks of
CNF.checkLRATKernel.
Agreement with the reference checker #
The kernel checker agrees with the reference checker on every formula and certificate.
The kernel LPR checker agrees with the reference LPR checker on every formula and certificate.