A proof checker whose whole language is Brainfuck's eight characters:
+ - < > [ ] . ,
The claim +[.[.]-]- says "every proposition implies itself". The proof is
+[.[]].
python3 mean.py examples/identity.claim.bl examples/identity.proof.bl
# {"assuming": [], "claim": "(forall x0 : Prop, (forall x1 : x0, x0))", "status": "proved"}It's a real checker! A program builds a term in the Calculus
of Constructions, and mean.py accepts a proof only if it proves exactly the
claim, under exactly the assumptions the claim lists. It is one Python file,
standard library only, Python 3.9+. The language is specified in
SPEC.md.
| Example | Says | Characters | Assuming |
|---|---|---|---|
identity |
every proposition implies itself | 15 | nothing |
one-plus-one |
1 + 1 = 2 | 238 | nothing |
cantor |
Cantor's theorem: no map from A to the predicates on A reaches every predicate | 539 | nothing |
euclid |
there are infinitely many primes | 161,469 | the Peano axioms |
fermat |
Fermat's little theorem: for prime p, aᵖ = a + p·k for some k | 1,053,776 | the Peano axioms |
Here's what the proofs look like. Each image is the complete proof file, shrunk until it fits. The claims are separate files and aren't shown.
Each example is a claim and a proof in examples/. The claim comes first:
python3 mean.py examples/euclid.claim.bl examples/euclid.proof.blFermat is too deep for the default budget, increase it like this:
python3 mean.py examples/fermat.claim.bl examples/fermat.proof.bl --depth 300 --steps 10000000The Peano axioms have no power function, so fermat defines "aⁿ = r" as a
relation built from multiplication, the usual way in first-order arithmetic.
pow-spec proves the relation behaves like aⁿ: a⁰ = 1, aⁿ⁺¹ = aⁿ·a, and every
aⁿ exists and is unique.
examples/src/ has the sources the
bigger examples were compiled from, and tools/assemble.py turns them into
eight-character files and checks the result with mean.py. The assembler isn't
trusted, just mean.py's verdict on the final files counts.
python3 tools/assemble.py examples/src/euclid.ls --out buildmean.py prints JSON with the explicit assumptions, the claim and a status.
Exit code 0 means proved, 1 means not proved, and 2 means it ran out of
budget (--steps, --seconds, --depth). When a proof proves the wrong thing, proof_proves shows what it
proved instead.
What logic is it? The two-sort Calculus of Constructions (Prop : Type, impredicative Prop), with beta conversion only. It has no inductive types, no universes beyond those two sorts, no quotients and no proof irrelevance. Numbers are Church numerals.
Can it do induction? Not on its own. Pure Calculus of Constructions can't
prove 0 ≠ 1 or anything that needs induction. Mean can prove 1 + 1 = 2 by
computation, but it can't prove 1 + 1 ≠ 3 without assumptions. That's why
euclid and fermat assume the Peano axioms, including induction. The
checker lists them in its output.
Can I assume excluded middle? You can assume anything, but be careful. Data lives in Prop here. In the Calculus of Constructions, classical axioms (excluded middle with a choice principle) imply proof irrelevance, which is Berardi's paradox. Proof irrelevance makes all numbers equal, and together with 0 ≠ 1 that is a contradiction. All the examples are constructive.
Is this actual Lean? No. Nothing here uses Lean, and Lean's logic is far stronger. I might make a version that's more powerful another time.
Is the checker proved correct? No. But it's like 300 lines and has been fuzzed (millions of short programs, no false claim accepted), but there is no machine-checked proof that it's sound.