Express mathematics. Verify everything.
ProofLang is a language for formal mathematics that reads close to mathematics on paper. Its compiler, written in Dart, compiles it to Lean 4 and Mathlib.
theorem positive_product:
given:
a, b ∈ ℝ
a > 0
b > 0
prove:
a * b > 0
proof positive_product:
strategy automatic
A theorem is verified only when a kernel accepted its proof, with no
sorry and no axiom beyond Lean's standard three (propext,
Classical.choice, Quot.sound) and those the project declares. Either
of two kernels can do the checking:
- Lean's, when
prooflang verifybuilds the generated project with Lake; - ProofLang's own (since 0.6.0), which re-checks a proof certificate
down to Lean's
Initwith no Lean installed (verify --offline). The statement it checked must also link back to the ProofLang theorem by semantic hash, so a certificate cannot pass off a proof of a different statement.
Nothing else is trusted. The automation (strategies, search, the native prover and tactics) only proposes proofs, for a kernel to check.
Since 0.7.0, many proofs need no Lean to be found either. build --native proves a growing fragment itself, and certifies it for
ProofLang's kernel. It covers:
- arithmetic, and linear arithmetic over ℕ, ℤ and ℝ;
- ring identities and divisibility;
- logic and instance laws;
- a subset of Lean's tactics in
by:blocks; - induction over the project's definitions and inductive types, including indexed families (since 0.48.0) and reflexive types (since 0.49.0), but not yet mutual or nested ones.
Every example project listed below, and the 41-obligation automation
benchmark, is proved this way in full. Anything outside the fragment
still needs Lean to find its proof
(doc/independent_verification.md).
Version 0.49.0. See doc/roadmap.md and
CHANGELOG.md.
- Phases 0–3, done:
- Phase 0, the specification.
- Phase 1, the front end.
- Phase 2, semantic analysis into a typed IR.
- Phase 3, Lean 4 code generation and kernel verification.
- Phase 4, the Lean importer: theorems, definitions and whole modules, universe-polymorphic ones included, each import self-checked, with a Lean → ProofLang → Lean round-trip suite.
- Phase 5, proof automation: structured
haveproofs,calcchains, and theinduction,simplify,rewriteandsearchstrategies. The search finds lemmas by the shape of their conclusion and replays the scripts it found. A benchmark pins what each strategy closes. - Phase 6, the standard library, started: finite sets, NumberTheory, Analysis, functions, topology and matrices.
All 20 benchmark examples (23 proof obligations) are verified by Lean 4.36.0
with Mathlib v4.36.0.
You need Lean via elan, and a built Mathlib
at v4.36.0, meaning a Lake workspace that requires it and has run
lake exe cache get. One copy serves every project: about 3 GB once set
up, and leave about 8 GB free for the download.
Set it up with:
prooflang setup-mathlib # into this platform's default folder (below)
prooflang setup-mathlib --list # the folders it can use, numbered, with their state
prooflang setup-mathlib -i # list them and ask (a number, or a folder of your own)
prooflang setup-mathlib --select 2 # into the 2nd folder of --list
prooflang setup-mathlib --dir PATH # anywhere else (it says how to point ProofLang there)It writes a Lake workspace pinned to ProofLang's Mathlib, then runs lake update and lake exe cache get. That downloads the prebuilt files, so
nothing is compiled. It also checks that Lean is installed (if not, it
prints the install command for your OS) and warns when disk space is
short. A folder that already holds the Mathlib is left as it is
(--force redoes it), a folder holding anything else (your own Lean
project, say) is refused unless --force, and --dry-run shows the steps
without running them. Afterwards it says which Mathlib build will use.
ProofLang uses the first Mathlib it finds:
-
--lean-packages <workspace>/.lake/packages -
$PROOFLANG_LEAN_PACKAGES -
prooflang.toml:[lean] packages = "…" -
A cache folder named
prooflang/mathlib-v4.36.0, checked automatically:Platform Folders checked, in order (the first is setup-mathlib's default)macOS ~/Library/Caches, then$XDG_CACHE_HOME, then~/.cacheLinux $XDG_CACHE_HOME, then~/.cacheWindows %LOCALAPPDATA%
A cache folder holding a different Mathlib version is skipped with a note.
If nothing is found, build reports every folder it checked. Everything
except build and verify works without Lean.
dart pub get
# Build and kernel-verify (needs Lean + Mathlib, see above)
dart run bin/prooflang.dart verify example/benchmark
# ✓ verified Benchmark.PositiveProduct.positive_product
# …
# 20 modules, 23 obligations: 23 verified, 0 failed, 0 open
# Verify WITHOUT Lean: certify once (with Lean), then check the
# certificate anywhere with ProofLang's own kernel (doc/independent_verification.md)
dart run bin/prooflang.dart verify example/lean_to_prooflang/euler --certify
dart run bin/prooflang.dart verify example/lean_to_prooflang/euler --offline
# note: 9263 declarations checked by the ProofLang kernel in …
# 4 modules, 18 obligations: 18 verified, 0 failed, 0 open (ProofLang kernel, no Lean; 18 …)
# The benchmark too, strictly: every obligation links to ProofLang
# (recursive definitions by proof, structures and laws since 0.12.0):
dart run bin/prooflang.dart verify example/benchmark --offline
# Build WITHOUT Lean: ProofLang proves the natural-number fragment itself
dart run bin/prooflang.dart build example/automation --native
# Native: 41 proved without Lean, 0 need Lean (…)
# Again: since 0.47.0 the earlier build's proofs are reused, each checked by
# the kernel again (generated/native-cache/; --no-cache to prove afresh)
dart run bin/prooflang.dart build example/automation --native
# Native: 41 proved without Lean, 0 need Lean, 41 from the cache (…)
# Why a proof failed: the failing claim, its goal and context, and what was
# tried there (natively: the prover's strategies, lemmas, rewrites; with
# Lean: the alternatives of `strategy automatic`), since 0.37.0
dart run bin/prooflang.dart build test/golden/explain --native --explain
# explain Claims.steps — claim two (b < a): no native proof found
# goal: a: ℕ, b: ℕ, h: a ≤ b, one: a ≤ b + 1 ⊢ b < a
# tried: …
# ✗ failed Claims.steps — not proved natively (needs Lean): claim two (b < a): no native proof found
dart run bin/prooflang.dart verify test/golden/explain --explain
# error[PL5001]: Lean, at claim two: `strategy automatic` did not close it (11 alternatives; …)
# Look at the Lean that is generated, or explain one declaration
dart run bin/prooflang.dart compile example/benchmark/05_positive_product.prooflang --target lean
dart run bin/prooflang.dart explain positive_product example/benchmark
# Import a Lean/Mathlib theorem as ProofLang (statement converted and
# self-checked; the proof cites the original), or a whole module
dart run bin/prooflang.dart import-lean Mathlib.Data.Nat.Prime.Infinite \
--decl Nat.exists_infinite_primes
dart run bin/prooflang.dart import-lean Mathlib.Data.Nat.Dist --all -o Dist.prooflang
# Check sources through the front-end phases only (parse, semantic, type)
dart run bin/prooflang.dart check example/benchmark
dart run bin/prooflang.dart check example/prooflang_project --format json
dart run bin/prooflang.dart check Main.prooflang --info # also open obligations
# Look inside: tokens, AST, typed IR, dependencies, proof obligations
dart run bin/prooflang.dart inspect example/benchmark/05_positive_product.prooflang --format ast
dart run bin/prooflang.dart inspect example/benchmark/05_positive_product.prooflang --format ir
dart run bin/prooflang.dart inspect example/benchmark/19_monoid.prooflang --format obligations--format obligations prints every goal as a readable sequent, for example
a: ℝ, b: ℝ, h₁: a > 0, h₂: b > 0 ⊢ a * b > 0, together with its IR. An
external tool or AI agent can work on a goal without reading Lean.
Each example imports a Mathlib theorem with import-lean, re-proves it in
ProofLang with textbook definitions, and connects the two by a
kernel-checked bridge. Each is measured against a like-for-like plain Lean 4
proof.
- Euclid's theorem
(
example/lean_to_prooflang/euclid/). The textbook definition of prime is proved equivalent to Mathlib's, and the two statements have the same semantic hash. - Euler's theorem
(
example/lean_to_prooflang/euler/). Mathlib proves it through group theory. The ProofLang version uses the elementary residue argument, built on finite sets, products and set images, then derives Fermat's little theorem. - Inequalities over ℝ
(
example/lean_to_prooflang/inequalities/). Nothing is imported here. Ring identities and linear and nonlinear inequalities, proved with Lean'sring,linarithandnlinarith, and again withstrategy automatic. Since 0.22.0, all of them are also proved without Lean; since 0.43.0 with comparisons with quotients too (31 obligations). - Limits of real sequences
(
example/lean_to_prooflang/limits/). ε–N convergence as a first course states it: sums, uniqueness, boundedness, the squeeze theorem and 1/(n+1) → 0. Since 0.23.0, all 6 are also proved without Lean. Since 0.25.0, four of them are proved again with ProofLang's ownintro,obtainandusesteps andstrategy automatic, with Lean and without; since 0.26.0 five, withsuppose(by contradiction),casesandsplittoo. - Continuity of real functions
(
example/lean_to_prooflang/continuity/). ε–δ continuity at a point: constants, the identity, linear functions, sums, compositions, and positivity near a point. All six theorems are proved twice, once with Lean tactic blocks and once with ProofLang's structured steps, using a common δmin(δ₁, δ₂)and a δ ofε / (|m| + 1). Since 0.27.0, all 13 obligations are proved with Lean and also without it. - Derivatives of real functions
(
example/lean_to_prooflang/derivatives/). ε–δ difference quotients, as a first course defines the derivative: of constants, the identity, linear functions andx², and of sums and constant multiples; since 0.35.0 also continuity, the product rule and the chain rule with an affine inner function. Every quotient divides byx − a, which is only known to be nonzero. Since 0.35.0, all 19 obligations are proved with Lean and also without it. - The completeness of the reals
(
example/lean_to_prooflang/completeness/). Mathlib's supremum by an extern: it bounds a set, is its least bound, has elements just below it, and a monotone bounded sequence converges to the supremum of its values; since 0.41.0 also the infimum, the supremum of a sequence, and√2as a supremum. All 16 obligations are proved with Lean, and since 0.44.0 all of them also without it (√2before needed Lean);verify --offlinelinks them. - Real sequences, Cauchy and geometric
(
example/lean_to_prooflang/sequences/). A convergent sequence is Cauchy, a Cauchy (or convergent) sequence is bounded (since 0.45.0, by the largest of its first terms), and the geometric series converges to1 / (1 − r), through the closed form of its partial sums andrⁿ → 0. All 15 obligations are proved with Lean and also without it, andverify --offlinelinks them. - Series over ℝ
(
example/lean_to_prooflang/series/). Since 0.46.0: Mathlib'sFinset.sumoverrange(n), a telescoping sum, the geometric sum in closed form,∑ 1/((k+1)(k+2)) = 1 − 1/(n+1)and its limit, increasing partial sums, and the comparison test's bound. All 11 obligations are proved with Lean and also without it, andverify --offlinelinks them. - Number theory over the integers
(
example/lean_to_prooflang/integers/). Divisibility with negatives, parity, Euclidean division (/and%), congruences kept by+,·and powers, and Bézout's identity from Mathlib. The structured proofs give witnesses fora ∣ band prove claims by steps of their own. Since 0.30.0, all its obligations are proved with Lean and also without it (24 since 0.31.0, withcongruent_powby aninductionstep). - Proofs by induction
(
example/lean_to_prooflang/sums/). Sums defined by recursion (of the naturals, of the odd numbers, of the squares, of the powers of two),n < 2ⁿ, and Bernoulli's inequality over ℝ. The structured proofs use ProofLang'sinductionstep, with azero:and asucc k, ih:case. Since 0.31.0, all 12 obligations are proved with Lean and also without it. - Strong induction
(
example/lean_to_prooflang/recursion/). The Fibonacci numbers (fib(n) < 2ⁿ, with the hypothesis two steps back) and a prime factor of every number from 2 on, without Mathlib's lemma, and (since 0.33.0) the odd part of every number. The structured proofs useinduction n strong, ih:andcases n:on a number's shape. Since 0.33.0, all 10 obligations are proved with Lean and also without it. - Structural induction on your own types
(
example/lean_to_prooflang/trees/). Binary trees (leaves and size, mirroring) and lists of naturals (length, appending), withinduction tand a block per constructor. Since 0.34.0, all 12 obligations are proved with Lean and also without it. - Indexed families
(
example/lean_to_prooflang/families/). Since 0.48.0: vectors that carry their length in their type (counted length, a bound on the sum), and predicates defined by rules (an order, the even numbers), by induction on a vector or on a derivation. All 10 obligations are proved with Lean and also without it, andverify --offlinelinks them. - Infinitely branching trees
(
example/lean_to_prooflang/branching/). Since 0.49.0: a reflexive type (a node with one child per natural number), doubling and adding trees, and their sizes, by induction whose hypothesis at such a node holds of every child. All 10 obligations are proved with Lean and also without it, andverify --offlinelinks them.
All of it is kernel-verified, and the comparisons are reported honestly. ProofLang's statements and definitions read closer to the mathematics.
- Hand-written. With Lean
by:proofs, neither example is shorter than plain Lean. - Automated. Each example also has a version proved with ProofLang's
automation, stating the same theorems (checked by semantic hash).
- Euclid's is about a third shorter than the Lean baseline.
- Euler's is not shorter, because its finite-product steps need specific Mathlib lemmas that automation does not find yet.
The tables in each COMPARISON.md are measured and pinned by tests.
example/automation/ measures each proof
strategy on its own. It pins which obligations each strategy closes,
including the ones it should not.
- Declarations:
definitiontheorem, written inline or asgiven:/prove:structurewithlaws:, andclass, for instance searchinductive, with constructor patterns inmatch(and_), indexed families, reflexive types (lim(f: ℕ → Ord)) andmutual inductivegroupsinstance,law,axiom,coercion fexternandextern class, which name a Lean constant or class
- Universes:
Type(u),Sort(max(u, v)). - Parameters:
x ∈ ℝ,h: x > 0and{α: Type}(implicit). Unbound Greek letters are auto-bound as type variables. - Proofs:
strategy automatic,induction(on = n),simplify(using = […]),rewrite(using = […])orsearch(depth, timeout)- a verbatim Lean
by:block - a structured proof made of
haveclaims, each one justified - a
calc:chain, each link justified
- Notation:
∀ ∃ ∃! λ ∧ ∨ ¬ → ↔ = ≠ < ≤ ∈ ∉ ⊆ ∪ ∩ × ∘ ∣ ∏ ∑. Each has an ASCII alias (forall,->,in,<=,union,prod,sum, …). - Notation forms:
- set builder
{x ∈ S | P}and set image{f(x) | x ∈ S} - relation chains
0 < x ≤ 1, and binders∀ ε > 0 ∏ x ∈ S: f(x)|x|,a[i],p.1,n!,a ≡ b (mod n)let x := v: body- dependent types
(x: A) → B(x)
- set builder
- Standard library: the number types,
SetandFinset, NumberTheory (Prime,Coprime,ModEq,φ,choose, …), limits (Tendsto,atTop,nhds),Injective/Surjective/Bijective,Continuous, andMatrixwithtransposeanddet. Each entry is Mathlib's own definition. - Structure: indentation is significant. Laws of a structure are proof obligations that each instance must discharge.
The full grammar is in doc/language_spec.md.
| Document | Contents |
|---|---|
| architecture | pipeline, layers, phases, determinism, trust boundary |
| language_spec | lexical rules, grammar, precedence |
| semantic_model | meaning, identity, semantic hashing |
| type_system | dependent types, with Lean as the authority |
| ir_spec | typed IR, proof graph, serialization |
| lean_backend | code generation, Lake, source maps, verification records, importer |
| proof_engine | strategies, resource limits, AI interface |
| roadmap | phases and task breakdown |
| testing · risks | acceptance criteria, risks |
dart analyze
dart test -x lean # Lean-backed tests (Phase 3+) are tagged `lean`
UPDATE_GOLDENS=1 dart test test/golden # regenerate golden files, then review the diff