Propositional tautologies over Prop from LRAT certificates #
lrat_tauto proves a goal built from ∧, ∨, →, ¬, ↔, True and False over arbitrary
propositions, the atoms, from an LRAT certificate cert : Array LRAT.IntAction: one generated
at elaboration time by the CDCL solver, or one supplied as lrat_tauto using cert. The kernel
checks the certificate; the proof uses no native evaluation, and its axioms are those of
Cslib.Logic.PL.Proposition.eval_prop_of_checkLRATRat.
The tactic reads the goal P as a proposition A : Proposition (Fin n) and a valuation
v : Fin n → Prop of its atoms, with A.eval v ↔ P. It then applies
Cslib.Logic.PL.Proposition.eval_prop_of_checkLRATRat to A and v. Its hypothesis, that
Cslib.Logic.PL.CNF.checkLRATRat accepts cert on (imp A falsum).plaistedGreenbaumNumberedCNF,
is proved by decide for the checker built for kernel reduction,
Cslib.Logic.PL.CNF.checkLRATKernel, and rewritten with
Cslib.Logic.PL.CNF.checkLRATKernel_eq_checkLRATRat. So the kernel runs that checker, and only
that run is trusted; where the certificate came from does not matter. The goals proved are the
classical tautologies, since eval_prop_of_checkLRATRat decides each atom classically. Without
using, P is P₁ → ⋯ → Pₖ → G for the goal G and the premises Pᵢ that the tactic finds
in the context or is given as lrat_tauto [t₁, …, tₙ] (see "Hypotheses and leaves"); the trusted
step is the same, on a larger formula.
Reading the goal #
- Leading binders whose type is not a proposition, as in
∀ (p q : Prop) (n : ℕ), …, are introduced first. The hypotheses of the local context are read as premises (see below). P ∧ Q,P ∨ Q,Falseand an implicationP → Qbetween propositions (a non-dependent arrow whose domain is a proposition) are read as the constructorsand,or,falsumandimp.Propositionhas no other constructors, so the other connectives are encoded:¬Pasimp P falsum,Trueasimp falsum falsum, andP ↔ Qasand (imp P Q) (imp Q P).a ≠ bis read as¬a = b, which it unfolds to at reducible transparency, so a hypothesish : a ≠ bfixes the atoma = b. A β-redex(fun x => P x) ais read asP a.- Every other subterm is an atom: an equation
f x = y, an order factn < 3, a dependent∀or∃, a definition other than≠that unfolds to connectives, such asXor' p q. Atoms are numbered from0in order of first occurrence, left to right, in the goal and then in the premises, and two atoms are the same when they are definitionally equal at reducible transparency. - An equation is the same atom as its swap:
b = ais read as the atoma = bwhen that atom occurs first, andHEq b aasHEq a b. The orientation of the atom is the one in which it first occurs, soh : b = afixes the atoma = bof the goal, anda ≠ bandb ≠ aare the negations of one atom. The valuation sends the atom to its first orientation, and the proof rewrites each swapped occurrence byeq_comm(HEq.comm), so the theorem proved is the goal as written. No other theory of equality is used:a = b → b = c → a = cis not proved.
Hypotheses and leaves #
Without using, the tactic proves P₁ → ⋯ → Pₖ → G for the goal G and premises Pᵢ, read
over shared atoms, and applies the proof to the premises' proofs; nothing is reverted. The
premises are:
- the hypotheses of the local context whose types are propositions, other than implementation
details, in the order of the context. A hypothesis that is not a propositional formula, such as
h : ∀ x, f x = 0, is an atom, as such subterms of the goal are; its type may mention other hypotheses and variables.lrat_tauto -hypsleaves them out. - the terms of
lrat_tauto [t₁, …, tₙ], in the order given, after the hypotheses, assimp [..]takes lemmas. Each is elaborated in the context of the goal, after its leading binders are introduced, and must be a proof of a proposition with no metavariables left: arguments that elaboration does not determine, as inh _, must be given. Its type, orTfor a type ascription(t : T)as forhave h : T := t, is read as a hypothesis's is, solrat_tauto [h a, Nat.le_total x y]supplies the instances ofh : ∀ x, f x = 0 ∨ p xand of a lemma that the tactic would not find: it instantiates no quantifier itself. The terms are used with-hypstoo. - the atoms that reflexivity proves,
a = bbyEq.reflandHEq a bbyHEq.reflwhenaandbare definitionally equal at instance transparency (unfolding reducible definitions and instances, assimpdoes when it rewrites witheq_self_iff_true), with that proof, as the leavestautocloses byrfl. This coversa = aunder≠:a ≠ ais read as¬a = a, and the atoma = ais proved. An↔is a connective, never an atom. No other tactic runs on the atoms. The leavestautocloses byassumptionare covered by the hypotheses: an atom that is a hypothesish : a, or whose negation is one,h : ¬a, is fixed by that premise.
Premises that a certificate does not need would still cost the kernel their clauses, so they are
dropped, terms as well as hypotheses: an unused term does not appear in the proof. The solver
refutes the formula with all the premises; those with a clause among the hints of the trimmed
certificate (one of the definitional clauses of its subformulas, or the clause of its imp node
asserting it) are kept, the formula is read again from them alone, numbering its atoms afresh, and
the solver refutes that formula. The kernel checks the certificate for that formula. If the solver
finds the smaller formula satisfiable, which the selection does not rule out, the formula with all
the premises and its certificate are used. This selection is untrusted, like the solver. Premises
that share no atom with the goal are not dropped before solving: they can still matter, as a
contradictory pair does.
A certificate supplied with using refutes the formula of the goal with only the terms as
premises, t₁ → ⋯ → tₙ → G for lrat_tauto [t₁, …, tₙ] using cert and G without terms, and
lrat_tauto? [t₁, …, tₙ] prints that formula: the clause numbers of a fixed certificate should not
depend on the context, so neither the hypotheses nor the facts found by rfl are premises, and
no premise is dropped. Pass the hypotheses that a supplied certificate needs as terms, or revert
them.
The certificate #
The certificate refutes the numbered Plaisted–Greenbaum transformation of imp A falsum
(Cslib.Logic.PL.Proposition.plaistedGreenbaumNumberedCNF), in which the atom numbered i is the
DIMACS variable i + 1 and the clauses are numbered 1, 2, … in order. It keeps, for each
subformula, only the direction of its Tseitin definition that the subformula's polarity needs.
lrat_tauto? prints that formula in DIMACS form, with the atoms in comment lines, so that a SAT
solver producing LRAT proofs can refute it. The lines of a textual LRAT proof are the addRup,
addEmpty and del actions of the certificate; the checker rejects RAT steps, which some solvers
emit after preprocessing (CaDiCaL does not with --plain).
The kernel checks the certificate once, as an auxiliary lemma that the proof then cites. If it
fails, lrat_tauto evaluates the checker in the kernel to tell a rejected certificate from one
the kernel cannot evaluate, such as a definition from another module whose body is not exposed,
and reports which.
Generating the certificate #
Without using, the tactic runs the CDCL solver Cslib.Algorithms.Lean.CDCL.solveCompact on the
formula, in Lean's interpreter during elaboration. If the formula is satisfiable, the goal does not
follow propositionally from the premises, and the error shows an assignment of truth values to the
atoms, read as independent propositions, under which the goal's propositional structure is false
and the premises are true; when the context has propositional hypotheses, it names them. It need
not be a countermodel of the goal itself, since the atoms may not be able to take those values:
for ∀ n : ℕ, 0 + n = n, the one atom 0 + n = n, which the reflexivity check does not prove,
is assigned False. Otherwise the solver
returns a certificate, which is proved correct (Cslib.Algorithms.Lean.CDCL.solveCompact_unsat)
but is not trusted here: the kernel checks it as it checks a supplied one. The certificate is first
trimmed to the steps that the empty clause depends on, without the deletions
(Cslib.Logic.PL.CNF.trimCert), and the clauses it adds are renumbered n + 1, n + 2, … after
the n clauses of the formula (Cslib.Logic.PL.CNF.renumberCert), which keeps the kernel
checker's trie shallow. Both are proved to preserve acceptance
(Cslib.Logic.PL.CNF.checkLRUP_renumberCert_trimCert), so the result is not checked before the
kernel checks it.
set_option trace.lrat_tauto true reports the sizes of the formula and of the certificate and
the times taken.
The solver is a single private definition, generateCert. Its type,
Cslib.Algorithms.Lean.DPLL.Result, guarantees neither a model nor a certificate, so a replacement
must meet this contract on each formula φ it is given:
- a result
.sat σhasσsatisfyingφ, since the error showsσon the atoms as the assignment under which the goal is false; - a result
.unsat certhasCslib.Logic.PL.CNF.checkLRUP φ cert = true:certreaches an empty-clause step through RUP additions and deletions, sincetrimCertandrenumberCertare proved for the RUP-only checkercheckLRUP.
The CDCL solver meets it (Cslib.Algorithms.Lean.CDCL.solveCompact_sat,
Cslib.Algorithms.Lean.CDCL.solveCompact_unsat), and so does the DPLL solver
Cslib.Algorithms.Lean.DPLL.solve (Cslib.Algorithms.Lean.DPLL.solve_sat,
Cslib.Algorithms.Lean.DPLL.solve_unsat), which replaces it by changing that definition alone. A
replacement that breaks the contract still cannot prove a goal that is not a tautology, since the
kernel checks every certificate; the tactic then fails, or shows a wrong assignment.
Main definitions #
lrat_tauto: close the goal, using the hypotheses, from a certificate generated by the CDCL solver;lrat_tauto -hypswithout the hypotheses.lrat_tauto [t₁, …, tₙ]: the same, with the termstᵢas further premises.lrat_tauto using cert: close the goal alone from the certificatecert;lrat_tauto [t₁, …, tₙ] using cert, the goal with the terms as premises.lrat_tauto?andlrat_tauto? [t₁, …, tₙ]: print the formula that a certificate for the goal, with the terms as premises, must refute.
Limitations #
↔is encoded by writing each side twice, so a goal that nests↔to depthdhas up to2 ^ dcopies of its innermost subformulas.- The kernel check takes most of the time. With the CDCL solver's certificates, trimmed, the kernel
checked the pigeonhole formulas for six pigeons in five holes and seven in six (certificates of
131 and 507 steps) in about 6 and 26 to 29 seconds, the chain of 320 implications (962 clauses,
one step) in about 2 seconds, and the distributivity of
∧over∨on six disjunctions (32 steps) and the associativity of↔on six atoms (68 steps) in about 2 seconds each. On goals with few steps most of that time goes to reading the formula, so the time grows with the number of clauses as well as with the number of steps and the length of the clauses the hints name. Against a numbered Tseitin transformation, which the tactic used before, the Plaisted–Greenbaum transformation halves the clauses and cut the kernel time by about a third on the chain and distributivity families, by 5% to 27% on↔and by 8% to 17% on the pigeonhole formulas for five and six pigeons. For seven pigeons, whose trimmed certificate grew from 461 to 507 steps, two runs took 26 and 29 seconds against 27. The final step, in which the kernel checks that the goal is the value ofAunderv, took under 0.3 seconds on each of these goals, finding each atom by a binary search on its number. The benchmark scriptLRATTautoBenchin the repository's scripts measures these families. - The solver runs in Lean's interpreter, and its work counts toward
maxHeartbeats; it takes a small fraction of the time of the kernel check, but on the larger formulas enough heartbeats thatset_option maxHeartbeatsmust be raised. When premises are dropped it runs twice, and the first run includes every propositional hypothesis of the context. On the pigeonhole formula for five pigeons in four holes, with twenty irrelevant hypotheses of three connectives each in the context, the tactic took about 1.6 seconds against 1.4 without them, the kernel time being the same, and about 2.1 seconds when every hypothesis was kept. - Atoms are compared at reducible transparency only, and equations are identified only with their
swaps:
a ≠ b → b = c → a ≠ cis not proved, since its atomsa = b,b = canda = care independent, and neither are facts such as0 ≠ 1orx ∉ [], whichtautogets fromcontradiction. A hypothesis whose type is only definitionally equal to a formula at a higher transparency is an atom.
lrat_tauto closes a goal built from ∧, ∨, →, ¬, ↔, True and False over
arbitrary propositions, from an LRAT certificate that refutes the numbered Plaisted–Greenbaum
transformation of the negated goal. The certificate is generated by the CDCL solver at
elaboration time, or supplied as lrat_tauto using cert with cert : Array LRAT.IntAction; when
the goal does not follow propositionally from the hypotheses, the error shows an assignment to the
atoms, read as independent propositions, under which it is false and they are true. The kernel
checks the certificate by evaluating Cslib.Logic.PL.CNF.checkLRATKernel. Leading binders over
non-propositions, such as ∀ p q : Prop, are introduced first. a ≠ b is read as ¬a = b. The
atoms are the maximal subterms that are not connectives, compared at reducible transparency, and
an equation b = a is the same atom as a = b.
Without using, the propositional hypotheses of the context are premises, then the terms of
lrat_tauto [t₁, …, tₙ], proofs of propositions that must elaborate without metavariables, with
the equations and HEqs that rfl proves at instance transparency; the premises that the
certificate does not need are dropped before the kernel check. lrat_tauto -hyps does not use
the hypotheses.
A supplied certificate refutes the formula of the goal with the terms alone as premises. It is a closed term the kernel can evaluate: a literal, or a definition whose body it can unfold. A certificate the checker rejects is reported as such.
lrat_tauto? [t₁, …, tₙ] prints the formula a supplied certificate must refute, in DIMACS
form.
lrat_tauto? prints the formula that a certificate for lrat_tauto using must refute: the
numbered Plaisted–Greenbaum transformation of the negated goal in DIMACS form, preceded by comment
lines naming the variable of each atom. lrat_tauto? [t₁, …, tₙ] prints the formula of
t₁ → ⋯ → tₙ → G for the goal G, which lrat_tauto [t₁, …, tₙ] using takes. It leaves the
goal unchanged.