MathCode turns plain-language math problems into Lean 4 proofs

MathCode is a terminal AI coding assistant with a built-in math formalization engine. A user gives it a math problem in plain language, and it automatically converts the statement into a Lean 4 theorem and attempts a formal proof. The system is built around a persistent Lean REPL, reusable theorem and axiom libraries, agentic proving, and an Obsidian knowledge graph that visualizes how theorems and lemmas depend on each other. To set it up, a user needs macOS (arm64) or Linux (x86_64) plus the codex CLI for the default backend, then clones the repository and runs a setup script that downloads the bundled runtime and Lean toolchain and installs a local mathcode launcher; a sample invocation is mathcode -p "prove that the square of an even number is even", with outputs written to a LeanFormalizations folder and an optional browser UI available through a webui command. On the engineering side, the persistent Lean language server brings compile checks down to about 0.4 seconds after a one-time warmup, versus about 30 seconds without it. Every proved theorem is auto-named, stored, and made importable so the prover and planner can reuse it, and conversational assumptions can be stored as persistent, compile-checked, consistency-reviewed Lean declarations. The tool also searches leansearch.net and Loogle for verified Mathlib lemmas and uses structured LSP diagnostics to repair failed proof attempts. Each proof runs as an interactive session in which the agent writes candidate proofs, reads the compiler's errors, and recompiles. For harder statements, MathCode decomposes a complex theorem into independent subgoals, proves them in parallel, and stitches the results back together; separately, it runs multiple planners in parallel to try diverse proof strategies and has the prover pick the best one. The project's own citation entry credits the work to "Team Math-AI" and dates it to April 2026, and states that the math formalization and proving pipeline is based on the AUTOLEAN project.

Key facts

  • MathCode converts a plain-language math problem into a Lean 4 theorem and attempts a formal proof automatically.
  • A persistent Lean language server cuts compile checks to about 0.4 seconds after a one-time warmup, down from about 30 seconds without it.
  • It decomposes complex theorems into independent subgoals proved in parallel, and separately runs multiple planners in parallel to pick the best proof strategy.
  • Requires macOS (arm64) or Linux (x86_64) and the codex CLI for its default backend; setup is via git clone plus a setup script.
  • Credited to 'Team Math-AI' in an April 2026 citation entry; the underlying formalization pipeline is based on the AUTOLEAN project.

Why it matters

Formal theorem proving in Lean 4 has traditionally meant slow, manual iteration: writing a candidate proof, waiting on the compiler, and repeating. MathCode targets that loop directly with a persistent Lean language server that drops compile checks from about 30 seconds to about 0.4 seconds after a one-time warmup, plus a growing, reusable library of proved theorems and consistency-checked assumptions the prover and planner can draw on across sessions. Running independent subgoals and multiple proof-strategy planners in parallel is an attempt to make automated formalization tractable on harder, multi-step theorems rather than only textbook-sized ones.

Who it affects

The tool is aimed at people doing formal verification and formalized mathematics in Lean 4: researchers working with Mathlib, engineers who want machine-checked proofs of properties in their code or math, and anyone exploring AI-assisted theorem proving. Its Obsidian knowledge graph output also targets users who want to navigate how a body of formalized theorems and lemmas depend on each other, not just prove one statement in isolation.

How to use it

MathCode requires macOS (arm64) or Linux (x86_64), plus the codex CLI for its default backend. Setup is git clone of the math-ai-org/mathcode repository followed by a bundled setup script and a codex auth login step; the script downloads the runtime and Lean toolchain and installs a user-local mathcode launcher. A basic call looks like mathcode -p "prove that the square of an even number is even", with results written to a LeanFormalizations folder, and a browser-based UI is available through a separate webui command. The source states no pricing or license terms.

How solid is it

The only account of MathCode is its own project page and GitHub repository, discussed on Hacker News (81 points, 26 comments at the time of writing). The source gives a concrete, verifiable engineering claim, the roughly 30-second to 0.4-second compile-time improvement from the persistent language server, but provides no benchmark results, accuracy figures, or proof-success rates for MathCode as a whole, and no comparison against other formalization or theorem-proving tools beyond that internal before/after timing.

Risks and caveats

Authorship is given only as the collective 'Team Math-AI' in the project's citation entry, with no individual names or institutional affiliation, and no release or launch date beyond the April 2026 citation year. The underlying AUTOLEAN project that the formalization pipeline is described as being based on is named but not further described, dated, or attributed. Without published accuracy or success-rate data, how well MathCode's automated proving actually performs on nontrivial theorems, beyond the compile-speed claim, remains unverified from the source alone.