Reference

Reference

Every export, grouped by subject. Wherever a formula is expected, text such as "p -> q" is accepted; wherever several are, an array or text with commas.

Answers

Functions that decide something return an object with a status and the evidence for it:

StatusEvidence
"satisfiable", "invalid", "different"model or countermodel: a valuation, checked by evaluating the formulas.
"unsatisfiable", "valid", "equivalent"refutation: a resolution proof, checked step by step.
"proved"proof or derivation, checked by the proof checker for that system.
"unprovable"kripke: a Kripke model in which the formula fails. Intuitionistic logic only.
"unresolved"reason and the budget that ran out. Pass a larger budget to go further.

Arguments the library cannot work with are refused with a LogicError carrying a code: syntax, bad-argument, too-large or bad-proof.

Formulas

ExportWhat it does
parse(text)Text to a Formula. Accepts ~ ! ¬ not, & ^ ∧ and, | ∨ or, -> → implies, <-> ↔ iff, xor ⊕, and T ⊤ true 1, F ⊥ _|_ false 0.
formula(x), formulas(x)A formula from text or a formula; a list from an array or comma-separated text.
atom, not, and, or, implies, iff, xor, TRUE, FALSEBuilders. and and or take any number of parts.
Formulakind, parts, left, right, isAtom, isLiteral, atoms(), subformulas(), size, depth, equals(g), evaluate(valuation), substitute(map), toString({ style }), toTeX(), toJSON(), key.
matchSchema(pattern, formula), fillSchema(pattern, binding)Match a formula against a pattern whose capital letters stand for any formula; fill a pattern in.
atomsOf(formulas)The atoms of several formulas, in order.

Tables

ExportWhat it does
truthTable(f, { atoms, subformulas, order }){ atoms, columns, rows, kind, trueRows, toString() }; up to 16 atoms.
minterms(f), maxterms(f)Row numbers where the formula is true; false.
countModels(f), models(f)How many valuations satisfy it (a BigInt); the valuations.
fromMinterms(atoms, rows), fromMaxterms(atoms, rows)The canonical formula with that table.
tableBits(f, atoms)The table as bits, for up to 22 atoms.

Normal forms

ExportWhat it does
foldConstants(f)Remove ⊤ and ⊥ wherever a connective absorbs them.
nnf(f)Negation normal form: only ∧, ∨ and negated atoms.
cnf(f, { method, limit }), dnf(f, { method, limit })Method "distribute" or "table"; cnf also takes "tseitin".
tseitin(f){ formula, clauses, definitions, atoms }: an equisatisfiable form of linear size.
clauses(f)The clauses of a conjunctive form, as lists of literals.
isNnf(f), isCnf(f), isDnf(f)Whether a formula is already in that form.

Satisfiability

ExportWhat it does
satisfiable(f, { budget })"satisfiable" with a model or "unsatisfiable" with a refutation. A list of formulas is taken together.
valid(f, { budget })"valid" with a refutation of the negation, or "invalid" with a countermodel.
entails(premises, conclusion, { budget })The same for an argument.
equivalent(a, b, { budget })"equivalent" or "different" with a valuation that tells them apart.
classify(f)kind: "tautology", "contradiction" or "contingent", with trueUnder, falseUnder or a refutation.
satisfiableClauses(clauses, { budget })The solver on clauses directly.
clause, literal, showClause, resolveClauses and the resolution rule.
ResolutionProof, parseResolution, checkResolutionResolution refutations and their checker.

Simplification

ExportWhat it does
simplify(f, { form, dontCare })A shortest equivalent two-level formula; form "dnf", "cnf" or the shorter of the two.
minimize(f, { form, dontCare, atoms }){ formula, form, atoms, terms, literals, exact, primes }; up to 14 atoms.
primeImplicants(f)Every prime implicant with the rows it covers.

Natural deduction

ExportWhat it does
checkProof(proof, { rules, premises, conclusion }){ status, ok, complete, errors, note, proves, lines, rules }; each error is { line, rule, message }.
parseProof(text, { rules }), ProofLines of { n, depth, formula, rule, cites }; toString({ style }).
rules.intuitionistic, rules.classical, rules.derivedRule sets. checkProof uses rules.classical unless told otherwise.
ruleSet(name, list, { logic })A rule set from data: each rule is { name, aliases, about, forms: [{ from, infer }] }.
proofState(proof)Open and closed subproofs after the last line.
prove(premises, conclusion, { logic, budget })A proof, a countermodel, a Kripke model, or unresolved.
hint(proof, { premises, conclusion, rules, budget })The next line of a proof in progress.

Sequents and truth trees

ExportWhat it does
sequent(text), SequentΓ ⊢ Δ with left and right.
proveSequent(sequent, { logic, budget })A derivation, a countermodel, a Kripke model, or unresolved.
checkDerivation, parseDerivation, DerivationDerivations as numbered lines, and their checker.
calculi.classical, calculi.intuitionistic, calculus(name, rules, options)G3cp and G3ip as data, and a way to build another.
forces(model, world, f), kripkeCountermodel(left, right)Kripke models: evaluation, and a search for a countermodel on small trees.
tableau(formulas, { budget, all }), TableauA truth tree: status, model, lines, branches, root.
tableauProof(premises, conclusion)"valid" with a closed tree or "invalid" with a countermodel.
checkTableau(tableau), tableauRulesThe tree checker, and the rules as data.

Predicate logic

ExportWhat it does
parseFO(text), fo, foList, FOFormula, Term, parseTermFirst-order formulas: freeVariables(), isSentence, substitute(x, t) without capture, alphaEquals, signature(). See Predicate logic.
foNnf, prenex, skolemizeNormal forms; Skolem form is equisatisfiable.
structure(spec), Structure, evaluate(f, M, { assignment, explain })Finite structures, and truth in them with witnesses and counterexamples. See Finite models.
findModel(sentences, { maxSize }), countermodel(premises, conclusion)Model search by SAT, with each model checked; an empty search is "unresolved", never valid.
checkFOProof, parseFOProof, foRulesNatural deduction with ∀E ∃I ∀I ∃E =I =E. See First-order proofs and trees.
foTableau(premises, conclusion, { budget }), showTableau, foEntailsFirst-order truth trees, and the combined decision.

Circuits, syllogisms, modal logic

ExportWhat it does
circuit(spec), Circuit, circuitFrom(f, { gates }), circuitsEquivalent, addersCircuits: evaluation, truth tables, size, depth, NAND-only and NOR-only forms. See Circuits and Karnaugh maps.
karnaugh(f | { minterms, atoms, dontCares })A map with its groups and shortest sum of products.
categorical, categoricalText, syllogism, validSyllogismsSyllogisms decided on the Venn diagram. See Syllogisms.
parseModal, modal, kripke, Kripke, SYSTEMS, validOnFrameModal formulas, Kripke models and frames. See Modal logic.
modalValid(f, { system }), showModalTreeValidity in K, D, T, B, S4, S5 by labelled trees, with checked countermodels.

Automata and machines

ExportWhat it does
automaton(spec), Automaton, toDFA, complete, minimizeAutomatonFinite automata, the subset construction, the smallest DFA. See Automata and regular expressions.
equivalentAutomata(a, b), complement, productEquivalence with a shortest distinguishing word; Boolean operations.
parseRegex, regexToNFA, toRegexRegular expressions to automata and back.
grammar(text), Grammar, showTreeContext-free grammars: words, Chomsky normal form, CYK parsing with a tree. See Grammars and machines.
pda(spec), turing(spec), binaryIncrement()Pushdown automata and Turing machines, run with a step budget.
recursivePrimitive and general recursive functions built from zero, successor and projections.
planThe phases still to come.
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