logic design

The logic package turns the equality calculus of the kernel into propositional logic. It defines the connectives as kernel definitions, derives the natural-deduction rules from the ten primitive rules, and keeps the catalog of theorem names that proof scripts may cite. This page gives the definitions, derives the rules, and explains why the package can do all this without being trusted.

Design goal

The kernel knows only equality and choice. Users want ⊤\top, ⊥\bot, ∧\wedge, ⇒\Rightarrow, ¬\neg and ∨\vee with their usual rules. The goal is to provide them with no new authority: every connective is a definition admitted by the DefOK gate, and every rule is a MoonBit function that calls kernel rules. The package may be wrong in the sense of failing to prove something, but it cannot prove anything false.

Mathematical background

Connectives as definitions

QED follows the definitions of HOL Light, where every connective is reduced to equality.11 J. Harrison, HOL Light Tutorial, section on the logical constants; the definitions go back to Andrews’ type theory Q0. QED’s disjunction differs from HOL Light’s, see below. Let tt be the truth term (λx. x)=(λx. x)(\lambda x.\,x) = (\lambda x.\,x). The prelude defines

⊤:=t⊥:=(λp. p)=(λp. t)and:=λp q.  (λf. f p q)=(λf. f t t)imp:=λp q.  and′ p q=pnot:=λp.  imp′ p ⊥′or:=λp q.  imp′ (not′ p) q\begin{aligned} \top &:= t \\ \bot &:= (\lambda p.\,p) = (\lambda p.\,t) \\ \mathit{and} &:= \lambda p\,q.\;(\lambda f.\,f\,p\,q) = (\lambda f.\,f\,t\,t) \\ \mathit{imp} &:= \lambda p\,q.\;\mathit{and}'\,p\,q = p \\ \mathit{not} &:= \lambda p.\;\mathit{imp}'\,p\,\bot' \\ \mathit{or} &:= \lambda p\,q.\;\mathit{imp}'\,(\mathit{not}'\,p)\,q \end{aligned}

where a primed name stands for the definition body already expanded, so that each right-hand side is a closed term over == alone. The reading of each definition:

  • tt is true because it is an instance of REFL.
  • ⊥\bot says the identity predicate on booleans equals the constantly-true predicate, that is ∀p. p\forall p.\,p with ∀P:=(P=λx. t)\forall P := (P = \lambda x.\,t). It is false in the standard model because ⊥\bot itself would have to be true.
  • p∧qp \wedge q says the pair (p,q)(p, q) cannot be told apart from (t,t)(t, t) by any function ff, which holds exactly when pp and qq are both true.
  • p⇒qp \Rightarrow q is (p∧q)=p(p \wedge q) = p: adding qq to pp changes nothing.
  • ¬p\neg p is p⇒⊥p \Rightarrow \bot.
  • p∨qp \vee q is ¬p⇒q\neg p \Rightarrow q.

Basis terms

prop_mk_and and its siblings return the basis form, the expanded right-hand side, rather than the application and p q\mathit{and}\,p\,q of the constant. The rules below work on basis forms, because only on those can the kernel rules act directly; the constants exist so that the definitions are recorded, can be cited, and can be recognised in terms that users write.

Design decisions

Derive, do not postulate

Every rule of the package is a derivation. The derivations below are the ones the code performs; each line is a kernel rule.

Truth. From the definition ⊢⊤=t\vdash \top = t, symmetry gives ⊢t=⊤\vdash t = \top, and ⊢t\vdash t is REFL, so EQ_MP gives ⊢⊤\vdash \top (logic_prop_truth_const_thm). Symmetry itself is derived:

⊢(=)=(=)REFLΓ⊢(=) s=(=) tMK_COMB(⋅, Γ⊢s=t)Γ⊢(s=s)=(t=s)MK_COMB(⋅, ⊢s=s)Γ⊢t=sEQ_MP(⋅, ⊢s=s)\begin{aligned} &\vdash (=) = (=) && \textsf{REFL} \\ &\Gamma \vdash (=)\,s = (=)\,t && \textsf{MK\_COMB}(\cdot,\ \Gamma \vdash s = t) \\ &\Gamma \vdash (s = s) = (t = s) && \textsf{MK\_COMB}(\cdot,\ \vdash s = s) \\ &\Gamma \vdash t = s && \textsf{EQ\_MP}(\cdot,\ \vdash s = s) \end{aligned}

From a proof to an equation with truth. From Γ⊢p\Gamma \vdash p and ⊢t\vdash t, DEDUCT_ANTISYM_RULE gives Γ∖{t}⊢p=t\Gamma \setminus \{t\} \vdash p = t, and Γ∖{t}=Γ\Gamma \setminus \{t\} = \Gamma unless tt is itself a hypothesis, in which case dropping it is harmless because tt is provable. This “EQT_INTRO” step is how propositions are put inside terms.

Conjunction introduction. From Γ⊢p\Gamma \vdash p and Δ⊢q\Delta \vdash q obtain Γ⊢p=t\Gamma \vdash p = t and Δ⊢q=t\Delta \vdash q = t. For a fresh variable ff,

⊢f=fREFLΓ⊢f p=f tMK_COMBΓ∪Δ⊢f p q=f t tMK_COMBΓ∪Δ⊢(λf. f p q)=(λf. f t t)ABS, f∉FV(Γ∪Δ)\begin{aligned} &\vdash f = f && \textsf{REFL} \\ &\Gamma \vdash f\,p = f\,t && \textsf{MK\_COMB} \\ &\Gamma \cup \Delta \vdash f\,p\,q = f\,t\,t && \textsf{MK\_COMB} \\ &\Gamma \cup \Delta \vdash (\lambda f.\,f\,p\,q) = (\lambda f.\,f\,t\,t) && \textsf{ABS},\ f \notin \mathrm{FV}(\Gamma \cup \Delta) \end{aligned}

The last line is p∧qp \wedge q. Freshness of ff is what makes ABS applicable.

Conjunction elimination. Apply both sides of Γ⊢(λf. f p q)=(λf. f t t)\Gamma \vdash (\lambda f.\,f\,p\,q) = (\lambda f.\,f\,t\,t) to the selector λx y. x\lambda x\,y.\,x with MK_COMB and REFL, then reduce both sides with BETA and TRANS:

Γ⊢(λx y. x) p q=(λx y. x) t t⇝Γ⊢p=t\Gamma \vdash (\lambda x\,y.\,x)\,p\,q = (\lambda x\,y.\,x)\,t\,t \quad\leadsto\quad \Gamma \vdash p = t

Symmetry and EQ_MP with ⊢t\vdash t give Γ⊢p\Gamma \vdash p. The selector λx y. y\lambda x\,y.\,y gives qq.

Implication elimination. From Γ⊢(p∧q)=p\Gamma \vdash (p \wedge q) = p and Δ⊢p\Delta \vdash p: symmetry gives Γ⊢p=(p∧q)\Gamma \vdash p = (p \wedge q), EQ_MP gives Γ∪Δ⊢p∧q\Gamma \cup \Delta \vdash p \wedge q, and conjunction elimination gives qq.

Implication introduction. From Γ⊢q\Gamma \vdash q with p∈Γp \in \Gamma: conjunction introduction with {p}⊢p\{p\} \vdash p gives Γ⊢p∧q\Gamma \vdash p \wedge q, and elimination from the assumption gives {p∧q}⊢p\{p \wedge q\} \vdash p. Then

Γ⊢p∧q{p∧q}⊢p(Γ∖{p})∪({p∧q}∖{p∧q})⊢(p∧q)=p  DEDUCT_ANTISYM_RULE\frac{\Gamma \vdash p \wedge q \qquad \{p \wedge q\} \vdash p}{(\Gamma \setminus \{p\}) \cup (\{p \wedge q\} \setminus \{p \wedge q\}) \vdash (p \wedge q) = p}\;\textsf{DEDUCT\_ANTISYM\_RULE}

and the hypothesis set is Γ∖{p}\Gamma \setminus \{p\}. The conclusion is p⇒qp \Rightarrow q by definition. logic_prop_imp_intro_thm requires p∈Γp \in \Gamma; discharging an absent hypothesis would need weakening first.

Ex falso. From Γ⊢(λp. p)=(λp. t)\Gamma \vdash (\lambda p.\,p) = (\lambda p.\,t) and any proposition qq, MK_COMB with ⊢q=q\vdash q = q and two BETA steps give Γ⊢q=t\Gamma \vdash q = t, hence Γ⊢q\Gamma \vdash q. Negation elimination is implication elimination with conclusion ⊥\bot.

Disjunction introduction. From Γ⊢p\Gamma \vdash p: assume ¬p\neg p, eliminate it against pp to get ⊥\bot, derive qq by ex falso, and discharge ¬p\neg p:

Γ⊢¬p⇒q  =  p∨q.\Gamma \vdash \neg p \Rightarrow q \;=\; p \vee q.

From Δ⊢q\Delta \vdash q the right introduction discharges an unused ¬p\neg p after conjoining it with qq.

No disjunction elimination

The prelude defines p∨qp \vee q as ¬p⇒q\neg p \Rightarrow q. Introduction is derivable, as shown. Elimination, from p∨qp \vee q, p⇒rp \Rightarrow r and q⇒rq \Rightarrow r infer rr, is not: it needs a case split on pp, that is excluded middle p∨¬pp \vee \neg p. In HOL excluded middle follows from the choice axiom and extensionality (Diaconescu’s theorem),22 R. Diaconescu, “Axiom of choice and complementation”, Proc. AMS 51, 1975. HOL Light derives EXCLUDED_MIDDLE this way in class.ml. but the kernel exposes no theorem for the choice axiom and the package does not derive excluded middle. Rather than ship a rule it cannot justify, the catalog has or_intro_l and or_intro_r and no or_elim, and the tactic layer has left and right but no case analysis.

Trusted recognition of connective constants

Problem. A user can declare a constant named and that means something else. If prop_dest_and recognised any application of a constant called and, a tactic could treat an arbitrary term as a conjunction.

Choice. The destructors accept the basis form, which is checked structurally, and an application of a connective constant only when the state holds the canonical definition theorem for that constant (with the current identity). install_prop_prelude refuses to install over a placeholder constant with the right name and type but no definition.

Why. Recognition errors would not break soundness, because every rule is replayed through the kernel. They would produce confusing failures at replay time instead of clear failures at the tactic, and the specification requires connector recognition to be backed by definitions.

One catalog, two modes

Problem. exact th and apply th mean different things. exact needs a theorem whose conclusion is the goal; apply needs an implication whose consequent is the goal and leaves its antecedent as the new goal. Letting a name be used in the wrong mode silently would either fail late or, worse, make exact quietly behave like apply.

Choice. Each catalog entry records an exact_class and an apply_class. exact consults only the first, apply only the second, and a name that exists but is unusable in a mode resolves to KnownButUnavailable, which the tactics layer reports as a shape or apply mismatch. A local hypothesis name always takes precedence over a catalog name and never falls back to it.

Why. The table is the single source for the tactics layer, the prover’s corpus, the mapping matrix and the documentation, so the theorem names a user may write cannot drift between them.

Errors from the kernel only

Kernel error constructors are read-only outside the kernel. The package obtains the LogicError and SigError values it returns by running small kernel operations that are known to fail in the required way. This keeps the error vocabulary owned by the kernel, at the cost of less specific errors: many helper failures surface as TypeMismatch or AlphaMismatch.

Correctness and invariants

  • Soundness. Every Thm returned by this package is the result of kernel functions, so the kernel’s soundness argument covers it. The derivations above show that each rule is also complete for its intended use: whenever its premises have the stated shapes, it succeeds.
  • Conservativity of the prelude. The six constants are admitted by DefOK with closed right-hand sides, no type variables and no cycles, so the prelude is a conservative extension of the empty theory.
  • Idempotence. install_prop_prelude(install_prop_prelude(s)) equals install_prop_prelude(s): an existing canonical definition is accepted as is.
  • Exact sequents. The replay helpers check hypotheses as sets up to α-equivalence. logic_prop_strengthen_to_hyps only adds hypotheses, so a theorem that needs a hypothesis the goal does not have is rejected rather than accepted with extra assumptions.
  • β-normalisation is proof-producing. logic_beta_normalize_eq and logic_normalize_prop_beta build kernel equations step by step; the term-level logic_beta_nf_* functions return the right-hand side of such an equation. Normalisation does not enter abstractions and is bounded (512 steps per pass, 32 passes for the deep form), which suffices for the connective encodings.

Alternatives rejected

  • Connectives as kernel primitives. This would add rules to the kernel and to its soundness proof. Definitions cost nothing in trust.
  • HOL Light’s disjunction ∀r. (p⇒r)⇒(q⇒r)⇒r\forall r.\,(p \Rightarrow r) \Rightarrow (q \Rightarrow r) \Rightarrow r. With it, elimination is derivable without excluded middle, at the cost of a universal quantifier over propositions inside every disjunction. The prelude uses the shorter encoding and states its limit instead; switching would change every disjunction term and the corpus built on them.
  • A mixed resolver. logic_prop_resolve_ref resolves names without distinguishing modes; it is kept for tests, while the tactics layer uses the mode-specific resolvers.

Boundaries

  • The package proves propositional facts only; it has no quantifier rules beyond what the tactics layer builds for theorem-header binders.
  • It has no disjunction elimination, no excluded middle and no classical reasoning.
  • It does not store user theorems: the catalog is fixed in the source, and adding a name means adding code and a test.
  • It adds no authority. Any change to it is reviewed for usefulness, not for soundness.
  • It does not parse or print formulas; terms are built by the parser and printed by the kernel’s structural printer.

Footnotes

  1. J. Harrison, HOL Light Tutorial, section on the logical constants; the definitions go back to Andrews’ type theory Q0. QED’s disjunction differs from HOL Light’s, see below. ↩

  2. R. Diaconescu, “Axiom of choice and complementation”, Proc. AMS 51, 1975. HOL Light derives EXCLUDED_MIDDLE this way in class.ml. ↩