Documentation

CslibFrontier.Logics.Propositional.Resolution.LRATLog

LRAT certificates built step by step #

A solver that learns clauses builds its certificate as it runs. Cslib.Logic.PL.CNF.LRATLog φ is a certificate under construction for φ: the steps so far, the numbered clauses they lead to, an index of them by number, which Cslib.Logic.PL.CNF.LRATLog.clause? reads in constant time instead of searching the database (Cslib.Logic.PL.CNF.LRATLog.clause?_eq), and the next unused number, together with the facts that the checker passes the steps (Cslib.Logic.PL.CNF.LRATLog.run) and that every clause of the database holds in every model of φ (Cslib.Logic.PL.CNF.LRATLog.implied).

The log grows by RUP steps (Cslib.Logic.PL.CNF.LRATLog.addRup): a clause is added under the next number with hints along which the checker's unit propagation, from the negation of the clause, reaches a conflict. A solver that learns clauses by resolution can build those hints without building the resolvents (Cslib.Logic.PL.CNF.RupHints): the hints refuting a clause, after a clause R of the database, refute any clause containing its resolvent with R (Cslib.Logic.PL.CNF.RupHints.resolve), since R then propagates the literal resolved on. Chaining this from a conflict clause gives the hints of the clause learned from it, with no step for the intermediate resolvents. Clauses can be deleted (Cslib.Logic.PL.CNF.LRATLog.delete), which clears their index entries in place but still filters the database list. Closing the log with an empty-clause step, given hints refuting the empty clause, gives a RUP-only (LRUP) certificate that Cslib.Logic.PL.CNF.checkLRUP accepts (Cslib.Logic.PL.CNF.LRATLog.checkLRUP_finish).

Main definitions #

Main results #

@[reducible, inline]

An index in chunks: the entries by number, in arrays of 256, so that updating a shared index copies the array of chunks and one chunk rather than every entry.

def Cslib.Logic.PL.CNF.chunkGet {α : Type} (a : Chunks α) (i : ℕ) :

The entry i of a chunked index, none past the end.

def Cslib.Logic.PL.CNF.chunkSet {α : Type} (a : Chunks α) (i : ℕ) (x : Option α) :

Setting the entry i of a chunked index, growing it if needed.

theorem Cslib.Logic.PL.CNF.chunkGet_chunkSet {α : Type} (a : Chunks α) (i j : ℕ) (x : Option α) :
chunkGet (chunkSet a i x) j = if j = i then x else chunkGet a j
def Cslib.Logic.PL.CNF.chunkClear {α : Type} (a : Chunks α) (i : ℕ) :

Clearing the entry i of a chunked index, in place: nothing changes if i is past the end.

Clearing the entries is of a chunked index, in place.

The chunked index of numbered clauses: the clause of each number, the first one listed.

theorem Cslib.Logic.PL.CNF.chunkGet_chunkIndexOf {α : Type} (db : List (ℕ × α)) (i : ℕ) :
chunkGet (chunkIndexOf db) i = Option.map (fun (x : ℕ × α) => x.2) (List.find? (fun (x : ℕ × α) => x.1 == i) db)

Hints built by resolution #

theorem Cslib.Logic.PL.CNF.propagateHints_cons_unit {db : List (ℕ × Clause ℕ)} {t : List (Literal ℕ)} {r : ℕ} {hs : List ℕ} {R : Clause ℕ} {l : Literal ℕ} (hR : List.find? (fun (x : ℕ × Clause ℕ) => x.1 == r) db = some (r, R)) (hfalse : ∀ y ∈ R, y ≠ l → Std.Sat.Literal.negate y ∈ t) (h : propagateHints db (l :: t) hs = true) :
propagateHints db t (r :: hs) = true

A hinted clause whose literals other than l are false propagates l: the shared rule Cslib.Logic.PL.CNF.propagateHints_cons_of_forall_ne, with propagation from l succeeding.

theorem Cslib.Logic.PL.CNF.propagateHints_mono {db : List (ℕ × Clause ℕ)} {t t' : List (Literal ℕ)} {hs : List ℕ} :
(∀ l ∈ t, l ∈ t') → propagateHints db t hs = true → propagateHints db t' hs = true

Unit propagation along hints succeeds from more literals. A clause with no open literal from t has none from t', and one with the single open literal l from t has its other literals false under t', so the shared rule applies.

Hints refuting the clauses containing C: from the negation of any clause containing the literals C, unit propagation along hints in db reaches a conflict.

theorem Cslib.Logic.PL.CNF.RupHints.single {db : List (ℕ × Clause ℕ)} {C : Literal ℕ → Prop} {i : ℕ} {c : Clause ℕ} (hc : List.find? (fun (x : ℕ × Clause ℕ) => x.1 == i) db = some (i, c)) (hC : ∀ y ∈ c, C y) :
RupHints db C [i]

A clause of the database hints its own refutation.

theorem Cslib.Logic.PL.CNF.RupHints.mono {db : List (ℕ × Clause ℕ)} {C C' : Literal ℕ → Prop} {hints : List ℕ} (h : RupHints db C hints) (hC : ∀ (y : Literal ℕ), C y → C' y) :
RupHints db C' hints

Hints refuting the clauses containing C refute those containing more.

theorem Cslib.Logic.PL.CNF.RupHints.resolve {db : List (ℕ × Clause ℕ)} {C C' : Literal ℕ → Prop} {hints : List ℕ} (h : RupHints db C hints) {r : ℕ} {R : Clause ℕ} {l : Literal ℕ} (hR : List.find? (fun (x : ℕ × Clause ℕ) => x.1 == r) db = some (r, R)) (hRC : ∀ y ∈ R, y ≠ l → C' y) (hC : ∀ (y : Literal ℕ), C y → y = Std.Sat.Literal.negate l ∨ C' y) :
RupHints db C' (r :: hints)

Resolving with a clause of the database: if C' contains every literal of the clause R numbered r other than l, and every literal of C other than the negation of l, then the hints refuting C, after r, refute C': the clause R propagates l, and then the negation of C holds.

theorem Cslib.Logic.PL.CNF.RupHints.propagateHints_eq {db : List (ℕ × Clause ℕ)} {C : Literal ℕ → Prop} {hints : List ℕ} (h : RupHints db C hints) {D : Clause ℕ} (hD : ∀ (y : Literal ℕ), C y → y ∈ D) :

Hints refuting the clauses containing C refute a clause D containing C as a RUP step.

A certificate under construction for φ: the steps so far, newest first, the numbered clauses they lead to, indexed by number, and the next unused number.

The empty log: the clauses of φ, numbered from 1.

The clause numbered i, if any, read from the index.

theorem Cslib.Logic.PL.CNF.LRATLog.clause?_eq {φ : CNF ℕ} (log : φ.LRATLog) (i : ℕ) :
log.clause? i = Option.map (fun (x : ℕ × Clause ℕ) => x.2) (List.find? (fun (x : ℕ × Clause ℕ) => x.1 == i) log.db)

The clause numbered i is the first of that number in the database.

theorem Cslib.Logic.PL.CNF.LRATLog.find?_of_clause? {φ : CNF ℕ} {log : φ.LRATLog} {i : ℕ} {c : Clause ℕ} (h : log.clause? i = some c) :
List.find? (fun (x : ℕ × Clause ℕ) => x.1 == i) log.db = some (i, c)
theorem Cslib.Logic.PL.CNF.LRATLog.vars_mem_of_clause? {φ : CNF ℕ} {log : φ.LRATLog} {i : ℕ} {c : Clause ℕ} (h : log.clause? i = some c) (l : Literal ℕ) :
l ∈ c → l.1 ∈ φ.vars

A clause of the log uses variables of φ.

theorem Cslib.Logic.PL.CNF.LRATLog.eval_of_clause? {φ : CNF ℕ} {log : φ.LRATLog} {i : ℕ} {c : Clause ℕ} (h : log.clause? i = some c) {σ : ℕ → Bool} (hσ : eval σ φ = true) :

A clause of the log holds in every model of φ.

A log extends another if every number of the other still names the same clause.

theorem Cslib.Logic.PL.CNF.LRATLog.Extends.trans {φ : CNF ℕ} {log₁ log₂ log₃ : φ.LRATLog} (h₁ : log₁.Extends log₂) (h₂ : log₂.Extends log₃) :
log₁.Extends log₃
theorem Cslib.Logic.PL.CNF.LRATLog.lt_next_of_clause? {φ : CNF ℕ} {log : φ.LRATLog} {i : ℕ} {c : Clause ℕ} (h : log.clause? i = some c) :
i < log.next

A number naming a clause is below next.

def Cslib.Logic.PL.CNF.LRATLog.addRup {φ : CNF ℕ} (log : φ.LRATLog) (c : Clause ℕ) (hints : List ℕ) (hprop : propagateHints log.db (List.map Std.Sat.Literal.negate c) hints = true) (hvars : ∀ l ∈ c, l.1 ∈ φ.vars) :

Adding a RUP clause: c, over variables of φ, under the next number, hinting hints, given that unit propagation along the hints from the negation of c reaches a conflict.

theorem Cslib.Logic.PL.CNF.LRATLog.clause?_addRup {φ : CNF ℕ} {log : φ.LRATLog} {c : Clause ℕ} {hints : List ℕ} {hprop : propagateHints log.db (List.map Std.Sat.Literal.negate c) hints = true} {hvars : ∀ l ∈ c, l.1 ∈ φ.vars} :
(log.addRup c hints hprop hvars).clause? log.next = some c

After adding a RUP clause, the new number names it.

theorem Cslib.Logic.PL.CNF.LRATLog.extends_addRup {φ : CNF ℕ} {log : φ.LRATLog} {c : Clause ℕ} {hints : List ℕ} {hprop : propagateHints log.db (List.map Std.Sat.Literal.negate c) hints = true} {hvars : ∀ l ∈ c, l.1 ∈ φ.vars} :
log.Extends (log.addRup c hints hprop hvars)

Adding a RUP clause extends the log.

A 1024-bucket table of clause numbers for fast membership tests without allocating an array spanning max - min (which reaches hundreds of thousands of slots on long runs when an old clause is locked or deleted alongside recent ones).

@[inline]

Whether i is in the bucket table b.

Removing repeated clause numbers via a 1024-bucket table, preserving order.

Accumulating unseen numbers of ids in acc (reversed) using bucket table seen.

The numbered clauses db without those numbered in ids: the clauses whose number is not in ids (eraseIds_eq), tested via a fixed-size 1024-bucket table (idBuckets).

def Cslib.Logic.PL.CNF.LRATLog.delete {φ : CNF ℕ} (log : φ.LRATLog) (ids : List ℕ) :

Deleting clauses from the log. An empty list deletes nothing and adds no step. The index entries are cleared in place (chunkClear), so deleting a number that names no clause does not grow the index.

theorem Cslib.Logic.PL.CNF.LRATLog.clause?_delete {φ : CNF ℕ} {log : φ.LRATLog} {ids : List ℕ} {i : ℕ} (hi : i ∉ ids) :
(log.delete ids).clause? i = log.clause? i

Deleting clauses keeps the clauses of the numbers not deleted.

Closing the log with an empty-clause step, given hints along which unit propagation reaches a conflict from no assumption.

theorem Cslib.Logic.PL.CNF.LRATLog.checkLRUP_finish {φ : CNF ℕ} {log : φ.LRATLog} {hints : List ℕ} (h : propagateHints log.db [] hints = true) :
φ.checkLRUP (log.finish hints h) = true

A closed log is accepted by the LRUP checker.