Topic

Proof search and hints

prove writes a natural deduction proof of an argument, or shows why there is none. hint looks at a proof someone has started and gives the next line, and only the next line.

A proof, written for you

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

const found = prove("p -> q", "~q -> ~p");
found.status;           // "proved"
String(found.proof);
// 1. p → q     premise
// 2. │ ¬q      assumption
// 3. │ │ p     assumption
// 4. │ │ q     →E 1, 3
// 5. │ │ ⊥     ¬E 4, 2
// 6. │ ¬p      ¬I 3-5
// 7. ¬q → ¬p   →I 2-6

The proof uses the introduction and elimination rules only, so it reads the way a textbook proof does: to prove a conditional, assume its left side; to use a disjunction, take cases. Every proof returned has been through checkProof, and lines that turned out not to be needed are removed.

Three honest answers

An argument that is not valid has no proof in any system, and the answer is a countermodel:

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

Classical proofs are built from intuitionistic rules where those are enough, and use indirect proof (IP) only where it is needed. Ask for logic: "intuitionistic" and a formula that needs it is reported as unprovable, with the Kripke model that shows why (see Sequent calculus):

String(prove("", "p | ~p").proof);
// 1. │ ¬(p ∨ ¬p)   assumption
// 2. │ │ p         assumption
// 3. │ │ p ∨ ¬p    ∨I 2
// 4. │ │ ⊥         ¬E 3, 1
// 5. │ ¬p          ¬I 2-4
// 6. │ p ∨ ¬p      ∨I 5
// 7. │ ⊥           ¬E 6, 1
// 8. p ∨ ¬p        IP 1-7

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

The search works within a budget of steps (two million unless you pass budget). If that runs out the answer is { status: "unresolved" } with the reason. It is never a guess.

How the search works

A proof is found in the intuitionistic sequent calculus and then translated, rule for rule, into natural deduction: a right rule becomes an introduction, a left rule becomes an elimination applied to a line already in reach. For classical logic the goal is first taken apart as far as the introduction rules go, and each remaining part AA is proved by assuming ¬A\lnot A and deriving ⊥\bot, which by Glivenko's theorem the intuitionistic search can always do when AA is a classical consequence.

Hints

A hint is for someone in the middle of a proof. It continues from the lines already written, so it follows the writer's own approach wherever that can still succeed, and it gives one line.

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

const soFar = `
1. p -> q   premise
2. q -> r   premise`;
hint(soFar, { conclusion: "p -> r" }).text;                 // "3. │ p   assumption"

const next = hint(soFar + "\n3. | p   assumption", { conclusion: "p -> r" });
next.text;        // "4. │ q   →E 1, 3"
next.goal;        // "r": what this part of the proof is working toward

Before giving a hint, the lines already there are checked, and other answers are possible:

StatusMeaning
"hint"line, its text, and the goal it works toward.
"error"A line already written does not check. The error names it; fix that first.
"done"The proof is complete.
"invalid"The conclusion does not follow, so there is nothing to finish; a countermodel is given.
"stuck"The open subproof cannot lead anywhere useful; the message says why.
"unprovable"Valid classically, but out of reach of the intuitionistic rule set in use.
"unresolved"The budget ran out.

Leave premises out and the premises are the ones the proof writes down. Name them and a missing premise becomes the first hint.

Reference

ExportWhat it does
prove(premises, conclusion, { logic, budget })"proved" with a proof and its lines, "invalid" with a countermodel, "unprovable" with a kripke model, or "unresolved".
hint(proof, { premises, conclusion, rules, budget })The next line of a proof in progress, as above.
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