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
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
Same Simulation, Different Evidence: Where Retrieved Tool Output Costs LLM Agents Accuracy
Saving long tool output to files cut GPT-5.1 accuracy by 11.3 points; naming the authoritative file restored it.
Fake News, Real Crashes: Information Injection Attacks on LLM Financial Trading Agents
Fake headlines hijacked LLM trading agents 62% of the time versus 14% for prompt injection.
Harness Engineering 101: The LLM is the brain, the harness is the body
An agent is a loop managing a JSON array; 16 chapters build one from scratch
Harness2 by Google Research – Recursive Agent Harnessing
Recursively refining the harness with fixed model weights raised benchmark scores by up to 11.8 points.
Ousted Savannah police officer gave ICE agent husband access to Flock system
A police officer shared her Flock login with her ICE-agent husband; an audit found 983 searches and she was fired
Tmux and Claude Code: Sessions, Send-Keys, and the Ceiling
Running Claude Code agents in tmux works well, but limits appear around four agents.