Documentation

CslibFrontier.Logics.Propositional.CNF.LRATRat

RAT and PR steps in LRAT and LPR certificates #

Cslib.Logic.PL.CNF.checkLRUP checks the RUP-only (LRUP) fragment of LRAT: it rejects RAT additions. The full LRAT format of Cruz-Filipe et al. also adds clauses with the RAT property. A clause C whose first literal is p has it with respect to a formula F when, for every clause D of F containing ¬p, the resolvent C ∨ (D \ {¬p}) follows from F by unit propagation, or is a tautology. Adding such a clause does not preserve the models of F, only its satisfiability: a model of F falsifying C becomes a model of F ∧ C once p is made true. Solvers emit RAT steps for bounded variable addition, as CaDiCaL's --factor does, and extended resolution.

Cslib.Logic.PL.CNF.checkLRATRat checks full LRAT certificates with RAT steps. A RAT step .addRat id c _ rup rat carries RUP hints rup and RAT hints rat, pairs (i, hs) of a clause number and a hint list. It is accepted (Cslib.Logic.PL.CNF.ratWith) when the RUP hints refute the negation of c, or else when every clause d numbered i that contains ¬p has a tautological resolvent with c or a resolvent refuted by unit propagation along rup followed by the hints that rat gives to i. This is Algorithm check_RAT of the paper (Section 4), with the following differences, each of which only accepts more certificates:

As in the paper's algorithm, a candidate with a tautological resolvent needs no RAT hint, and a RAT step with no candidate needs no hints at all: Lean core's parser reads a clause with no hints as such a step, which is how CaDiCaL writes the definition clauses of --factor. Drat-trim's lrat-check rejects those steps, since it does not check that no candidate exists.

The checker numbers clauses as checkLRUP does, and reads a clause number as its first entry in the database, the clause a later one with the same number shadows being gone. Accepted certificates refute their formula (Cslib.Logic.PL.CNF.not_satisfiable_of_checkLRATRat), and it accepts every certificate checkLRUP accepts (Cslib.Logic.PL.CNF.checkLRATRat_of_checkLRUP), so it is also complete (Cslib.Algorithms.Lean.DPLL.exists_checkLRATRat_iff). The RAT check is written for any clause lookup and any test over the stored clauses, so that the kernel checker Cslib.Logic.PL.CNF.checkLRATKernel and the array checker Cslib.Logic.PL.CNF.checkLRATFast run the same check on their own databases.

PR steps and the LPR format #

A clause C is propagation redundant (PR) with respect to F when some assignment ω satisfies C and F restricted by the negation α of C implies F restricted by ω by unit propagation Tan, Heule and Myreen (Definition 2, which attributes the notion to Heule, Kiesl and Biere). It suffices to check, for each clause D of F that ω reduces (falsifies a literal of without satisfying it), that unit propagation refutes α and the negation of D restricted by ω. A model of F falsifying C becomes a model of F ∧ C once the literals of ω are made true. RAT is the case ω = {p}.

The LPR format of the same paper (Section 3, Fig. 1) writes the witness on the clause line of LRAT: "the (potentially empty) witness starts from the second occurrence of the first literal of the clause until the first 0 that separates the unit clause hints"; the unit hints for a reduced clause follow as the RAT hints of LRAT. So Lean core's LRAT parser reads an LPR line as an LRAT step whose clause is the clause followed by the witness, and Cslib.Logic.PL.Clause.splitWitness splits it again. This is also how cake_lpr reads it: parse_clause_witness and parse_until_k in examples/lpr_checker/lpr_parsingScript.sml of CakeML (commit 080a3bd) return the literals before the repeat as the clause and the literals from it on as the witness.

Cslib.Logic.PL.CNF.prWith is the PR check of a step, the algorithm of Fig. 3 of the paper and check_PR and is_PR of examples/lpr_checker/lprScript.sml in CakeML, with the differences listed for ratWith above and these, each of which only accepts more certificates:

It also checks what Fig. 3 leaves to the format: that ω satisfies the clause, and that it is consistent, as is_PR does.

Cslib.Logic.PL.CNF.checkLPR checks LPR certificates: an addition whose clause repeats its first literal is a PR step with the witness read by splitWitness, and other additions are checked as by checkLRATRat. Accepted certificates refute their formula (Cslib.Logic.PL.CNF.not_satisfiable_of_checkLPR). The two checkers read the same certificate differently when a clause repeats its first literal, which LRAT allows; on certificates where none does (Cslib.Logic.PL.CNF.noWitness) they agree (Cslib.Logic.PL.CNF.checkLPR_eq_checkLRATRat).

Main definitions #

Main results #

References #

The clause and the witness of an LPR addition Tan et al. (Section 3): if the first literal p of c occurs again, the clause is the literals of c before that second occurrence and the witness the literals from it on, so that the witness starts with p; if it does not, none.

def Cslib.Logic.PL.CNF.ratWith (lookup : ℕ → Option (Clause ℕ)) (all : (ℕ → Clause ℕ → Bool) → Bool) :

The RAT check of the clause c, whose pivot is its first literal p, with the RUP hints rup and the RAT hints rat, reading clauses with lookup; all f tells whether f n d holds for every clause d that lookup gives the number n. Either unit propagation along rup refutes the negation of c, or every clause d containing ¬p has a resolvent c ∨ (d \ {¬p}) that is a tautology or whose negation unit propagation refutes along rup followed by the hints rat gives to the number of d.

theorem Cslib.Logic.PL.CNF.all_eq_of_forall_lookup {lookup : ℕ → Option (Clause ℕ)} {all all' : (ℕ → Clause ℕ → Bool) → Bool} (h : ∀ (f : ℕ → Clause ℕ → Bool), all f = true ↔ ∀ (n : ℕ) (d : Clause ℕ), lookup n = some d → f n d = true) (h' : ∀ (f : ℕ → Clause ℕ → Bool), all' f = true ↔ ∀ (n : ℕ) (d : Clause ℕ), lookup n = some d → f n d = true) :
all = all'

Two clause enumerations of one database are equal if each tells whether f n d holds for every clause d that lookup gives the number n. The RAT and PR checks (ratWith, prWith) read the stored clauses only through such an enumeration, so a checker may substitute its own.

theorem Cslib.Logic.PL.CNF.ratWith_congr {lookup : ℕ → Option (Clause ℕ)} {all all' : (ℕ → Clause ℕ → Bool) → Bool} (h : ∀ (f : ℕ → Clause ℕ → Bool), all f = true ↔ ∀ (n : ℕ) (d : Clause ℕ), lookup n = some d → f n d = true) (h' : ∀ (f : ℕ → Clause ℕ → Bool), all' f = true ↔ ∀ (n : ℕ) (d : Clause ℕ), lookup n = some d → f n d = true) (c : Clause ℕ) (rup : List ℕ) (rat : List (ℕ × List ℕ)) :
ratWith lookup all c rup rat = ratWith lookup all' c rup rat

The RAT check reads the stored clauses only through what all tells about them.

theorem Cslib.Logic.PL.CNF.exists_eval_of_ratWith {lookup : ℕ → Option (Clause ℕ)} {all : (ℕ → Clause ℕ → Bool) → Bool} (hall : ∀ (f : ℕ → Clause ℕ → Bool), all f = true → ∀ (n : ℕ) (d : Clause ℕ), lookup n = some d → f n d = true) {c : Clause ℕ} {rup : List ℕ} {rat : List (ℕ × List ℕ)} (h : ratWith lookup all c rup rat = true) {σ : ℕ → Bool} (hσ : ∀ (n : ℕ) (d : Clause ℕ), lookup n = some d → Clause.eval σ d = true) :
∃ (τ : ℕ → Bool), (∀ (n : ℕ) (d : Clause ℕ), lookup n = some d → Clause.eval τ d = true) ∧ Clause.eval τ c = true

A RAT step keeps a database satisfiable: if the RAT check of c succeeds and σ satisfies every clause that lookup returns, some assignment satisfies them and c. It is σ if σ satisfies c, and otherwise σ with the pivot made true.

PR steps #

def Cslib.Logic.PL.CNF.prWith (lookup : ℕ → Option (Clause ℕ)) (all : (ℕ → Clause ℕ → Bool) → Bool) (c : Clause ℕ) (w : List (Literal ℕ)) (rup : List ℕ) (rat : List (ℕ × List ℕ)) :

The PR check of the clause c with the witness w, the RUP hints rup and the RAT hints rat, reading clauses with lookup; all f tells whether f n d holds for every clause d that lookup gives the number n (Tan et al., Fig. 3). Either unit propagation along rup refutes the negation of c, or w satisfies c, contains no literal together with its negation, and every clause d that w reduces is satisfied by w, or has a restriction d' by w such that c ∨ d' is a tautology or its negation is refuted by unit propagation along rup followed by the hints rat gives to the number of d.

theorem Cslib.Logic.PL.CNF.exists_eval_of_prWith {lookup : ℕ → Option (Clause ℕ)} {all : (ℕ → Clause ℕ → Bool) → Bool} (hall : ∀ (f : ℕ → Clause ℕ → Bool), all f = true → ∀ (n : ℕ) (d : Clause ℕ), lookup n = some d → f n d = true) {c : Clause ℕ} {w : List (Literal ℕ)} {rup : List ℕ} {rat : List (ℕ × List ℕ)} (h : prWith lookup all c w rup rat = true) {σ : ℕ → Bool} (hσ : ∀ (n : ℕ) (d : Clause ℕ), lookup n = some d → Clause.eval σ d = true) :
∃ (τ : ℕ → Bool), (∀ (n : ℕ) (d : Clause ℕ), lookup n = some d → Clause.eval τ d = true) ∧ Clause.eval τ c = true

A PR step keeps a database satisfiable: if the PR check of c with the witness w succeeds and σ satisfies every clause that lookup returns, some assignment satisfies them and c. It is σ if σ satisfies c, and otherwise σ with the literals of w made true.

The checker #

Whether f n d holds for each clause d of the database db that its number n looks up, as ratWith reads the clauses: a clause shadowed by an earlier one with the same number is not read.

theorem Cslib.Logic.PL.CNF.allLookup_eq_true {db : List (ℕ × Clause ℕ)} {f : ℕ → Clause ℕ → Bool} :
allLookup db f = true ↔ ∀ (n : ℕ) (d : Clause ℕ), List.lookup n db = some d → f n d = true

allLookup tests every clause that a number looks up.

The RAT hints of a step as lists.

How a checker reads the clause c of an addition: in the LPR format (lpr = true) a repeated first literal starts a witness (Clause.splitWitness), and in LRAT (lpr = false) it does not.

The checker with RAT steps on a database of numbered clauses, and with PR steps if lpr.

The LRAT checker with RAT steps: the clauses of φ are numbered from 1, and the certificate must reach an empty-clause step through RUP steps, RAT steps (CNF.ratWith) and deletions.

The LPR checker Tan et al.: as CNF.checkLRATRat, except that an addition whose clause repeats its first literal is a PR step (CNF.prWith) adding the clause before the repeat, with the witness from the repeat on (Clause.splitWitness).

Whether no addition of the certificate repeats the first literal of its clause, so that the LPR format reads no witness in it.

Soundness and completeness #

theorem Cslib.Logic.PL.CNF.false_of_checkLRATRatAux {lpr : Bool} {db : List (ℕ × Clause ℕ)} {cert : List Std.Tactic.BVDecide.LRAT.IntAction} (h : checkLRATRatAux lpr db cert = true) {σ : ℕ → Bool} (hdb : ∀ (n : ℕ) (d : Clause ℕ), List.lookup n db = some d → Clause.eval σ d = true) :

If the checker accepts on a database, no assignment satisfies the clauses it looks up.

A formula with a certificate accepted by the checker with RAT steps is unsatisfiable.

A formula with an LPR certificate accepted by CNF.checkLPR is unsatisfiable.

The checker with RAT steps accepts on a database whatever checkLRUPAux accepts.

The full LRAT checker with RAT steps accepts every certificate checkLRUP accepts.

On a certificate whose additions do not repeat their first literal, the checker reads no witness, with or without lpr.

On certificates whose additions do not repeat their first literal, the LPR checker agrees with the LRAT checker with RAT steps.