Truth trees
A truth tree asks whether some formulas can all be true at once, by breaking them into parts. A branch that comes to hold a formula and its negation closes. If every branch closes, the formulas cannot be true together; an open branch that has been fully worked out describes a way they can.
Testing an argument
To test an argument, put the premises and the negation of the conclusion at the root. The argument is valid exactly when the tree closes.
import { tableauProof } from "@ratmath/logic";
const result = tableauProof("p -> q, q -> r", "p -> r");
result.status; // "valid"
String(result.tableau);
// 1. p → q premise
// 2. q → r premise
// 3. ¬(p → r) negated conclusion
// 4. p ¬→ 3
// 5. ¬r ¬→ 3
// ├─
// │ 6. ¬p → 1
// │ ✗ 4, 6
// └─
// 7. q → 1
// ├─
// │ 8. ¬q → 2
// │ ✗ 7, 8
// └─
// 9. r → 2
// ✗ 5, 9
Each line names the rule and the line it was applied to. A branch ends in ✗ with the two lines that contradict each other. When a branch stays open, its atoms are a countermodel:
const bad = tableauProof("p -> q", "q -> p");
bad.status; // "invalid"
bad.countermodel; // { p: false, q: true }
String(bad.tableau);
// 1. p → q premise
// 2. ¬(q → p) negated conclusion
// 3. q ¬→ 2
// 4. ¬p ¬→ 2
// ├─
// │ 5. ¬p → 1
// │ ○ open
// └─
// 6. q → 1
// ⋯ not continued
One open branch settles the question, so the others are not continued. Pass { all: true } to work out every branch.
The rules
A rule either extends a branch or splits it. The rules that extend are applied first, which keeps trees small.
| Formula | Add to the branch | Or split into |
|---|---|---|
| , | ||
| , | ||
| , | ||
| | | ||
| | | ||
| | | ||
| | | ||
| | |
Each rule says: the formula is true exactly when everything on one of its branches is. That is why the method is sound and complete: truth is carried down some branch at every step, and an open finished branch has had every formula on it accounted for. The rules are exported as data in tableauRules, each a pattern and its branches.
Satisfiability directly
import { tableau, checkTableau } from "@ratmath/logic";
const t = tableau("p | q, ~p");
t.status; // "open"
t.model; // { p: false, q: true }
checkTableau(t); // { ok: true, closed: false, errors: [], model: { p: false, q: true } }
checkTableau goes over a finished tree with separate code: every line must follow from the line it cites by the rule it names, every closed branch must hold the contradiction it claims, and a model read from an open branch must make the root formulas true. A tree that would pass a budget of lines (20,000 unless you say otherwise) is returned as "unresolved".
Reference
| Export | What it does |
|---|---|
tableau(formulas, { budget, all }) | A Tableau: status ("closed", "open", "unresolved"), closed, model, lines, branches, root, toString(). |
tableauProof(premises, conclusion, options) | "valid" with the closed tableau, or "invalid" with a countermodel and the tree. |
checkTableau(tableau) | { ok, closed, errors, model }. |
tableauRules | The rules: { name, pattern, branches }. |
@ratmath/logic and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.