@ratmath/logic

Logic where every verdict comes with its evidence

Formal logic you can compute with. A formula is valid with a proof you can replay, invalid with a countermodel that has been checked, or reported as unresolved within a stated budget. Proofs written by hand are checked line by line, and a hint gives the next line and no more.

What is here

Propositional logic, in two parts: what a formula means (tables, normal forms, satisfiability, shortest forms) and how a formula is proved (four proof systems, each with a checker). Then predicate logic with finite models and quantifier proofs; circuits, syllogisms and modal logic; and the machines of computability, from finite automata to Turing machines. What is still planned is listed at the bottom of this page.

A first program

import { parse, truthTable, valid, entails, simplify, checkProof, prove, hint } from "@ratmath/logic";

String(parse("~p & q -> (r | s)"));      // "(¬p ∧ q) → (r ∨ s)": typed on any keyboard, printed properly

valid("((p -> q) & (q -> r)) -> (p -> r)").status;   // "valid", and .refutation is the proof
entails("p -> q, q", "p").countermodel;              // { p: false, q: true }: the argument fails here
String(simplify("(a & b) | (~a & c) | (b & c)"));    // "(a ∧ b) ∨ (¬a ∧ c)"

checkProof(`1. p -> q    premise
2. q         premise
3. p         ->E 1, 2`).errors[0].message;
// 'line 3: to give "p", →E needs a line reading "φ → p"; line 1 reads "p → q"'

String(prove("p -> q", "~q -> ~p").proof);           // a seven-line proof, written for you

Three rules the library keeps

No bare verdicts. "Valid" comes with a proof and "invalid" with a countermodel, and both are checked by code much simpler than the code that found them. A search that runs out of its budget answers "unresolved": it never guesses. See Satisfiability and validity.

Rules are data. A natural deduction rule is a name and a pattern such as "from A→BA \to B and AA, infer BB". The checker reads the rule set it is given, so a course can use its own rules, and classical and intuitionistic logic are two rule sets that are never mixed. See Natural deduction.

Mistakes are explained, hints are small. A proof that fails to check names the line, the rule, and what the rule needed and did not find. A hint is the next line of a proof that continues from what is already written. See Proof search and hints.

What is planned

From the library roadmap. Sizes are rough estimates in lines of source.

PhaseContentsEstimate
1Propositional formulas, tables, normal forms, satisfiability, simplificationbuilt
2Proof checkers, rule sets, proof search and hintsbuilt
3Predicate logic: syntax, finite models, model search, quantifier rulesbuilt
4Circuits, Karnaugh maps, syllogismsbuilt
5Modal logicbuilt
6Ordinals, cardinals, Peano arithmetic, Gödel numbering500
7Automata, grammars, Turing machinesbuilt
8Pictures500 in graphics

What is built depends on no other library. The discrete library will use it for Boolean functions.

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