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:
| Rule | From | Infer | Condition |
|---|---|---|---|
| ∀E | for any term | ||
| ∃I | |||
| ∀I | is in no premise or open assumption | ||
| ∃E | and a subproof from to | is new: not in , the premises, or | |
| =I | |||
| =E | and | with some 's written (or 's written ) | only free occurrences: no variable of or is bound where it is replaced |
The conditions are what make the rules sound. ∀I generalises from only if nothing was assumed about , so was an arbitrary choice. ∃E names the witness , so must not escape into the conclusion. =E replaces only where the replacement stays free: from and it does not give , which is false on the domain with and true only at 0, though both premises are true there. The derived rule set adds CQ, the quantifier negation laws such as .
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. (and ) is used once, with a new name: something is , call it . (and ) 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 never gets used up, a tree for an invalid argument can grow without end: makes a new name, which the 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
| Export | What 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, .derived | Rule 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. |
@ratmath/logic and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.