Topic

First-order proofs and trees

The proof systems for propositional logic extend to quantifiers with a few rules each. The care is all in the names: what may be said about "everything" from one example, and what may be concluded from "something".

Natural deduction

checkFOProof reads the same layout as propositional proofs, with every propositional rule, and adds six:

RuleFromInferCondition
∀E∀x A(x)\forall x\, A(x)A(t)A(t) for any term tt
∃IA(t)A(t)∃x A(x)\exists x\, A(x)
∀IA(c)A(c)∀x A(x)\forall x\, A(x)cc is in no premise or open assumption
∃E∃x A(x)\exists x\, A(x) and a subproof from A(c)A(c) to BBBBcc is new: not in BB, the premises, or ∃x A(x)\exists x\, A(x)
=It=tt = t
=Ea=ba = b and AAAA with some aa's written bb (or bb's written aa)only free occurrences: no variable of aa or bb is bound where it is replaced

The conditions are what make the rules sound. ∀I generalises from cc only if nothing was assumed about cc, so cc was an arbitrary choice. ∃E names the witness cc, so cc must not escape into the conclusion. =E replaces only where the replacement stays free: from x=ax = a and ∀x P(a)\forall x\, P(a) it does not give ∀x P(x)\forall x\, P(x), which is false on the domain {0,1}\{0, 1\} with a=x=0a = x = 0 and PP true only at 0, though both premises are true there. The derived rule set adds CQ, the quantifier negation laws such as ¬∀x A⊢∃x ¬A\lnot\forall x\, A \vdash \exists x\, \lnot A.

import { checkFOProof } from "@ratmath/logic";

checkFOProof(`1. ∀x (P(x) → Q(x))    premise
2. ∀x P(x)             premise
3. P(a) → Q(a)         ∀E 1
4. P(a)                ∀E 2
5. Q(a)                →E 3, 4
6. ∀x Q(x)             ∀I 5`).proves;
// "∀x (P(x) → Q(x)), ∀x P(x) ⊢ ∀x Q(x)"

checkFOProof(`1. P(a)       premise
2. ∀x P(x)    ∀I 1`).errors[0].message;
// 'line 2: a occurs in the premise "P(a)", so what holds of a need not hold of everything'

checkFOProof(`1. ∃x P(x)      premise
2. | P(c)       assumption
3. | P(c)       R 2
4. P(c)         ∃E 1, 2-3`).errors[0].message;
// 'line 4: c occurs in "P(c)", so the conclusion would say something about the witness'

checkFOProof(`1. x = a       premise
2. ∀x P(a)     premise
3. ∀x P(x)     =E 1, 2`).status;
// "errors": the inserted x would be captured by ∀x

Truth trees

A first-order truth tree has the propositional rules and four more. ∃x A\exists x\, A (and ¬∀x A\lnot\forall x\, A) is used once, with a new name: something is AA, call it c1c_1. ∀x A\forall x\, A (and ¬∃x A\lnot\exists x\, A) may be used again for every name on the branch, and so is never used up. The tree tries names oldest first, so every name gets its turn.

import { foTableau, showTableau } from "@ratmath/logic";

const t = foTableau("∀x (H(x) → M(x)), H(s)", "M(s)");
t.status;                 // "valid"
showTableau(t.tree);
// ∀x (H(x) → M(x))    (premise)
// H(s)    (premise)
// ¬M(s)    (negated conclusion)
// H(s) → M(s)    (from ∀x (H(x) → M(x)), with s)
// ┌ branch 1
//   ¬H(s)    (from H(s) → M(s))
//   × closed: H(s) and ¬H(s)
// └ branch 2
//   M(s)    (from H(s) → M(s))
//   × closed: M(s) and ¬M(s)

A branch that stays open after every rule has been applied describes a countermodel: its names are the domain and its atoms say where each predicate holds. The model is checked against the root before it is returned.

const u = foTableau("∃x P(x) ∧ ∃x Q(x)", "∃x (P(x) ∧ Q(x))");
u.status;                          // "invalid"
u.countermodel.describe().predicates;   // { P: ["c1"], Q: ["c2"] }: one thing is P, another is Q

Because a ∀\forall never gets used up, a tree for an invalid argument can grow without end: ∀x ∃y L(x,y)\forall x\, \exists y\, L(x, y) makes a new name, which the ∀\forall applies to, which makes another. The tree stops at its budget and says "unresolved". foEntails combines the methods: a short tree first, then a countermodel search, then a longer tree.

foTableau("∀x ∃y L(x, y)", "∃y ∀x L(x, y)", { budget: 200 }).reason;
// "the tree was still growing after 200 steps"
foEntails("∀x ∃y L(x, y)", "∃y ∀x L(x, y)").status;   // "invalid", from a 2-element countermodel

Every first-order consequence has a closed tree (Gödel's completeness theorem, 1929), so with enough budget "valid" is always found. "Invalid" can only be found when there is a finite countermodel: that is the undecidability again.

Reference

ExportWhat it does
checkFOProof(text, { rules, premises, conclusion })The same report as checkProof: status ("proof" when it checks), errors, proves.
parseFOProof(text, { rules })A Proof read from text.
foRules.intuitionistic, .classical, .derivedRule sets: the propositional rules lifted to first-order formulas, with ∀E ∃I ∀I ∃E =I =E; derived adds CQ.
foTableau(premises, conclusion, { budget })"valid" with the closed tree; "invalid" with a checked countermodel; or "unresolved". With no conclusion, "valid" means the premises cannot all be true.
showTableau(tree)The tree as text.
foEntails(premises, conclusion, { maxSize, budget })Tree, then countermodel search, then a longer tree.
Try itEdit the code and run it with @ratmath/logic and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs