Topic

Sequent calculus

A sequent Γ⊢Δ\Gamma \vdash \Delta says: if everything on the left holds, something on the right does. A derivation takes a sequent apart one connective at a time until only axioms are left. Read from the bottom up it is a search procedure, which is why this is the calculus the library searches in.

Deriving a sequent

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

const found = proveSequent("p -> q, q -> r |- p -> r");
found.status;                // "proved"
String(found.derivation);
// 1. q → r, p ⊢ r, p        Ax
// 2. p, q ⊢ r, q            Ax
// 3. p, q, r ⊢ r            Ax
// 4. q → r, p, q ⊢ r        →L 2, 3
// 5. p → q, q → r, p ⊢ r    →L 1, 4
// 6. p → q, q → r ⊢ p → r   →R 5
found.derivation.check().ok; // true: checked again, line by line

The last line is the sequent proved. Each line above it follows from the lines it cites by one rule, and a line marked Ax has the same formula on both sides (or ⊥\bot on the left, or ⊤\top on the right).

The rules

Each connective has a left rule and a right rule. Read upward, a rule replaces a formula by its parts:

RuleTo deriveDerive
∧LΓ,A∧B⊢Δ\Gamma, A \land B \vdash \DeltaΓ,A,B⊢Δ\Gamma, A, B \vdash \Delta
∧RΓ⊢Δ,A∧B\Gamma \vdash \Delta, A \land BΓ⊢Δ,A\Gamma \vdash \Delta, A and Γ⊢Δ,B\Gamma \vdash \Delta, B
∨LΓ,A∨B⊢Δ\Gamma, A \lor B \vdash \DeltaΓ,A⊢Δ\Gamma, A \vdash \Delta and Γ,B⊢Δ\Gamma, B \vdash \Delta
∨RΓ⊢Δ,A∨B\Gamma \vdash \Delta, A \lor BΓ⊢Δ,A,B\Gamma \vdash \Delta, A, B
→LΓ,A→B⊢Δ\Gamma, A \to B \vdash \DeltaΓ⊢Δ,A\Gamma \vdash \Delta, A and Γ,B⊢Δ\Gamma, B \vdash \Delta
→RΓ⊢Δ,A→B\Gamma \vdash \Delta, A \to BΓ,A⊢Δ,B\Gamma, A \vdash \Delta, B
¬L, ¬RΓ,¬A⊢Δ\Gamma, \lnot A \vdash \Delta; Γ⊢Δ,¬A\Gamma \vdash \Delta, \lnot AΓ⊢Δ,A\Gamma \vdash \Delta, A; Γ,A⊢Δ\Gamma, A \vdash \Delta

This is the calculus G3cp. Every one of its rules is invertible: the sequent below is valid exactly when the sequents above are. So the search never has to go back on a choice, it always ends, and a branch that ends at a sequent of atoms that is not an axiom gives a countermodel: make the atoms on the left true and those on the right false.

proveSequent("p -> q |- q -> p");
// { status: "invalid", countermodel: { p: false, q: true } }

The intuitionistic calculus

Intuitionistic logic is the same rules with one restriction: at most one formula on the right. The restriction is what removes the law of the excluded middle. In the classical derivation of p∨¬pp \lor \lnot p the right side holds two formulas at once, which the restricted calculus forbids:

String(proveSequent("|- p | ~p").derivation);
// 1. p ⊢ p      Ax
// 2. ⊢ p, ¬p    ¬R 1
// 3. ⊢ p ∨ ¬p   ∨R 2

const result = proveSequent("|- p | ~p", { logic: "intuitionistic" });
result.status;             // "unprovable"
result.classicallyValid;   // true
String(result.kripke);
// world 0: nothing true yet
// world 1 (after world 0): p true

When there is no intuitionistic derivation the answer comes with a Kripke model: stages of knowledge, where what is known stays known. A conditional or a negation holds at a stage when it holds at every later stage. At world 0 above, pp is not yet known, and ¬p\lnot p fails because pp becomes known later, so p∨¬pp \lor \lnot p does not hold. forces(model, world, formula) evaluates a formula at a world, and the search checks its own countermodel with it before returning.

The double negation of the excluded middle is provable, as Glivenko's theorem says the double negation of every classical tautology is:

String(proveSequent("|- ~~(p | ~p)", { logic: "intuitionistic" }).derivation);
// 1. ¬(p ∨ ¬p), p ⊢ p        Ax
// 2. ¬(p ∨ ¬p), p ⊢ p ∨ ¬p   ∨R1 1
// 3. ¬(p ∨ ¬p), p ⊢ ⊥        ¬L 2
// 4. ¬(p ∨ ¬p) ⊢ ¬p          ¬R 3
// 5. ¬(p ∨ ¬p) ⊢ p ∨ ¬p      ∨R2 4
// 6. ¬(p ∨ ¬p) ⊢ ⊥           ¬L 5
// 7. ⊢ ¬¬(p ∨ ¬p)            ¬R 6

In this calculus (G3ip) the rules ∨R1, ∨R2 and →L are not invertible, so the search has to try alternatives and come back. It does so within a budget, and answers "unresolved" if the budget runs out before it has either a derivation or a countermodel.

Checking a derivation

import { checkDerivation, calculi } from "@ratmath/logic";

const text = `
1. p, q |- q        Ax
2. p, q |- p        Ax
3. p, q |- q & p    &R 1, 2
4. p & q |- q & p   &L 3`;
checkDerivation(text).proves;      // "p ∧ q ⊢ q ∧ p"

checkDerivation(text.replace("&R", "|R")).errors[0].message;
// "line 3: ∨R works on a formula of the form A ∨ B on the right, and p, q ⊢ q ∧ p has none"

calculi.classical.rules["→L"];
// { side: "L", kind: "imp", premises: [{ right: ["A"] }, { left: ["B"] }] }

A calculus is a table of such rules: the side, the connective, and for each premise what replaces the formula. calculus(name, table, { maxRight }) builds one of your own.

Reference

ExportWhat it does
proveSequent(sequent, { logic, budget })"proved" with a derivation, "invalid" with a countermodel, "unprovable" with a kripke model, or "unresolved".
sequent(text), sequent(left, right)A Sequent with left and right; the turnstile may be typed |-.
checkDerivation(text or Derivation, { calculus }){ ok, errors, proves, lines, calculus }.
parseDerivation(text, { calculus })A Derivation tree: sequent, rule, premises, lines(), size, check().
calculi.classical, calculi.intuitionisticG3cp and G3ip as data.
calculus(name, rules, { maxRight, logic })A calculus from a rule table.
forces(model, world, formula)Whether a formula holds at a world of a Kripke model { parent, holds }.
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