QED

This manual documents v0.1.0 of Luna-Flow/QED, as it stands on main.

Overview

QED (Quite Easy Deduction) is a theorem prover for higher-order logic written in MoonBit. It follows the LCF approach: a small trusted kernel implements the primitive inference rules of HOL and is the only code that can create theorems, and everything else, from the parser to the command-line tool, builds on it without being trusted. Proofs are written as short theorem scripts with goal-directed steps; a script either yields a kernel theorem, fails with a structured diagnostic, or reports an unfinished proof. A formal specification defines the kernel, and the Typed HOL development in formal_verification/ proves the mathematical calculus; MoonBit refinement remains separate.

The shipped proof language covers propositional logic with equality, theorem-header binders and goal-level forall; the user manual has the exact support matrix.

Install

moon add Luna-Flow/QED@0.1.0

Then import the packages you need in your moon.pkg, for example "Luna-Flow/QED/prover" to run theorem scripts or "Luna-Flow/QED/kernel" to build theorems directly. QED needs the MoonBit toolchain 0.10.20 or later (moonc ≥ 0.10.20), and depends on moonbitlang/x for file access in the command-line tool.

To work in the repository:

moon check --target all
moon test
moon run src/cmd examples/truth_file.qed

Formal specification

The formal specification is the only normative source for the kernel.

Formal description includes the embedded PDF preview of the QED formal specification.

Pages

The packages are layered: each depends only on packages to its left, kernel → logic/elab → parser → tactics → prover → cmd, and only kernel is trusted. research_rewrite sits outside this chain.

PartTutorialAPIDesign
kernel: types, terms, theorems, primitive rules, scoped signature, extension gatestutorialAPIdesign
logic: connectives as definitions, derived rules, replay helpers, theorem catalogtutorialAPIdesign
elab: name resolution with frozen constant identities, core typing, loweringtutorialAPIdesign
parser: normalisation, terms, goals, theorem scripts, source positionstutorialAPIdesign
tactics: backward proof states, replayed forward to kernel theoremstutorialAPIdesign
prover: theorem-script driver, structured results, regression corpustutorialAPIdesign
cmd: the command-line tool qed-cmd (executable package)tutorialAPIdesign
research_rewrite: research-only rewriting prototype, not shippedtutorialAPIdesign

Repository guides:

GuideContents
User manualThe user guide and implementation contract, with the support matrix and the stable examples
Syntax guideThe theorem-script syntax
Compliance reviewImplementation mapping, proof obligations, evidence boundary, and contributor checks
Formal descriptionNormative specification entry point and PDF preview
Initial verification audit (2026-10-14)Research-only baseline, reproducible evidence and next promotion

Blackbox test files (*_test.mbt) and the alias files alias.mbt and alias_test.mbt belong to their packages; the compliance review defines their maintenance obligations. The theorem files in examples/ and prelude/ are inputs for the command-line tool, not packages.

Exported items

Trusted kernel

  • Types and terms: HolType, Term, DbTerm and their constructors, destructors and substitutions
  • Theorems: the abstract Thm, read with thm_concl, thm_hyps and thm_is_admissible
  • Primitive rules: refl_checked, assume_checked, trans_checked, mk_comb_rule_checked, abs_rule_checked, beta_rule_checked, eq_mp_checked, deduct_antisym_rule_checked, inst_type, inst_checked, and the derived add_assum_checked
  • State and gates: KernelState, scopes, ks_define_const_thm (DefOK), ks_register_type_definition (TypeDefOK), ks_specify_const (SpecOK), audit certificates

Untrusted layers

  • logic: install_prop_prelude, the connective builders prop_mk_* and recognisers prop_dest_*, the natural-deduction rules logic_prop_*_thm, the theorem catalog
  • elab: RTerm, elab_resolve_*, elab_check_core_type, elab_lower_to_term
  • parser: parse_term, parse_goal, parse_theorem_script_raw and their _raw and _with_env variants, ParseError with raw offsets
  • tactics: ProofState, ps_init, ps_apply, ps_qed, the steps step_intro, step_split, step_left, step_right, step_apply, step_exact, step_assumption
  • prover: prove_theorem_script_detailed, prove_theorem_file_results_detailed, ProverRunResult, the regression corpus
  • New to proof assistants: read “For readers new to HOL” and the quick start in the user manual, then run the examples with the cmd tutorial. The syntax guide answers “how do I write this step”.
  • Using QED from MoonBit: start with the prover tutorial to run scripts and read results. Go down to the tactics tutorial to drive proofs step by step, and to the logic and kernel tutorials to build theorems forwards. Keep the API pages at hand; each lists the failure cases of every function.
  • Checking why it is sound: read the kernel design, which derives the rules and explains why soundness reduces to the kernel, then the logic and tactics designs, which show that the upper layers add no authority. The formal specification above is normative.
  • Contributing: read the compliance review for the code/test mapping, proof obligations, package boundaries, and evidence limits. The initial verification audit records dated research evidence.

Validation

Recommended release checks:

moon check --target all
moon test

The examples on the package pages compile against the current code; specification conformance describes how they are checked. The Typed HOL proof builds separately with lake build in formal_verification/; it formalizes the mathematical calculus and does not yet prove a refinement from the MoonBit implementation.