MathCode, Mathematical Coding Agent
TL;DR Highlight
An agent turns plain-language math problems into Lean 4 theorems and tries formal proofs.
Who Should Read
An agent developer who wants to plug a proof checker (Lean) into an agent loop for mechanical verification of results
Core Mechanics
- Plain-language problems become Lean 4 theorems
- Give it a problem in plain words and it converts it to a Lean 4 theorem.
- It then attempts a formal proof, which a computer checks.
- Only Lean verification counts as done
- A fresh strict check verifies one declaration at the end.
- A successful verification certificate is required to count a proof as finished.
- The agent decides the proof strategy
- It writes candidates, inspects goals and diagnostics, and chooses what to try next.
- Subgoals, helper lemmas, branches and milestones are optional techniques, not a mandatory controller.
- Rich Lean environment integration
- A persistent Lean REPL and Lean LSP diagnostics drive repairs.
- It searches leansearch.net and Loogle for verified Mathlib lemmas.
- Reusable libraries and a knowledge graph
- Theorem and axiom libraries store compile-checked declarations.
- An Obsidian graph shows theorem-to-lemma dependencies.
- Requirements and how to run
- It needs macOS (arm64) or glibc Linux (x86_64, AVX2), plus the codex CLI for the default backend.
- Install with setup.sh, run mathcode -p "...", and use ./run webui for a browser UI.
Community Reactions
- Correct formalization is the hard part
- One commenter said the tricky bit is making sure an inaccurate plain-English statement is formalized correctly in Lean.
- Is it an AUTOLEAN wrapper?
- A commenter asked whether it wraps the AUTOLEAN project (T3S1AMAX/autolean).
- No license terms visible
- A commenter said there are no licensing terms, so it can't be used commercially.
- Show an example first
- A commenter wished the page led with an example rather than quickstart and feature lists.
How to Apply
- Install and run one example problem
- Install lightly with the --without-lean option.
- Run mathcode -p "prove that the square of an even number is even" and check the output.
- Switch agent completion to an external verifier
- Define done by a compiler or test passing, not the model's own judgment.
- Configure the final check to run fresh, without caches.
- Apply the same loop where verification is possible
- Build an agent loop of drafting, reading diagnostics, and retrying in domains with formal checks.
- Offer strategies as optional techniques rather than enforcing them.
- Check the license first
- Look for a license file in the repo before internal use.
- If missing, ask the authors before using it.
Try It
# Paste into a terminal (based on the original Quick Start; macOS arm64 or Linux x86_64 AVX2, codex CLI required)
git clone https://github.com/math-ai-org/mathcode.git
cd mathcode
bash setup.sh --without-lean
codex auth login
# Run
mathcode -p "prove that the square of an even number is even"
# Next: ./run webui for the browser UI, or --with-lean for the full Lean toolchainTerminology
Related Papers
Frostbite: A new CPU architecture discovered, designed and verified by AI
AI agents designed a CPU from scratch, claiming 4.59x perf/W over a traditional core
Restricting AI agents in mobile operating systems platforms from capturing data
Signal now blocks OS-level AI agents from reading its screen on iOS 27 and Android
Actions Speak Louder than Words: Stateful Privacy Sniffing of LLM Agents via Behavioral Covert Channels in Web Interactions
Agents' link choices alone let attackers rebuild user queries at F1 0.89; SOR cuts it to 0.39.
Tracking and Limiting Unsupported Claim Propagation in Multi-Agent LLM Systems: A Provenance-Aware Framework
Passing claims with source, evidence and history kept equivalence at 5 agent stages at 96% versus 31%.
LLM assisted reverse engineering
Pointing an agent at binaries with skills and MD notes made years-long hacks feasible
Metrics-in-the-Loop: Complexity Feedback Reshapes Agent-Written Code
Injecting per-turn complexity reports into coding agents cut code erosion without changing correctness
Why is Gemini 4 Carbon taking so long?
Carbon took nearly an hour on bug fixes that Astra and Opus finished in minutes, mostly from extra unrequested work.
Weight-Space Programming builds neural networks like a 1990s researcher
LLM hand-wrote MNIST weights to 91.3%, using 1990s-style techniques