Mathlib4 is a collaborative, community-driven project and welcomes contributions of all kinds — new theorems, improved proofs, tactics, documentation, and infrastructure fixes. Whether you are formalizing a piece of undergraduate mathematics or a cutting-edge research result, the community is here to help you get your work merged. This page walks through everything you need to know before opening your first pull request.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/leanprover-community/mathlib4/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Before contributing you should have the following in place:- Lean 4 and
elaninstalled via the official getting-started guide. Theelantoolchain manager handles Lean version pinning automatically. - Lake — Lean’s build system, which ships with every
elan-managed toolchain. No separate installation is needed. - A GitHub account with a fork of leanprover-community/mathlib4.
- Familiarity with Lean 4 syntax — the Mathematics in Lean book and the Lean 4 survival guide for Lean 3 users are good starting points.
You do not need to build all of Mathlib from scratch. Running
lake exe cache get downloads precompiled .olean files and will save many hours of compilation time.Community and Support
The main communication hub for Mathlib development is the Zulip chat at leanprover.zulipchat.com. The#mathlib4 stream is the right place to:
- Introduce yourself and your contribution plans.
- Ask for guidance on whether a formalization fits Mathlib’s scope.
- Get code review advice before opening a formal PR.
- Discuss design questions about definitions and theorem names.
Code of Conduct
Mathlib follows the Contributor Covenant Code of Conduct. Participation in any community space — Zulip, GitHub issues, PRs, or elsewhere — requires:- Empathy and kindness toward all contributors, regardless of experience level.
- Respect for differing opinions and the willingness to give and receive constructive feedback gracefully.
- Constructive engagement: focus on what is best for the community, not just for the individual.
- Zero tolerance for harassment, insulting comments, personal attacks, or the publication of others’ private information.
Pull Request Workflow
Fork leanprover-community/mathlib4 on GitHub, clone your fork locally, and create a feature branch with a descriptive name:
git clone https://github.com/<your-username>/mathlib4.git
cd mathlib4
git checkout -b feat/add-my-theorem
Always do this before building. It downloads cached build artifacts from Mathlib’s CI servers and avoids recompiling the entire library from scratch:
Add new Lean files under the appropriate
Mathlib/ subdirectory, or edit existing ones. Every new file must:/-! ... -/) describing its contents.See the Style Guide and Naming Conventions pages for the detailed rules that reviewers enforce.
This executes all tests defined under
MathlibTest/. A clean run is required before requesting review.This runs both the Python-based text linters and the Lean-based style linters. Fix all reported issues before opening a PR. See Building & Testing for a full reference of available linting commands.
Push your branch to your fork and open a PR against the
master branch of leanprover-community/mathlib4. The PR title must satisfy the format checked by check_title_labels — keep it concise, descriptive, and in the imperative mood (e.g., feat(Algebra.Group): add commutativity lemma for ...).Reviewers will comment directly on your diff. Address all requested changes by pushing additional commits to the same branch. The CI will re-run automatically on each push.
Linter Options
Mathlib enforces a standard set of linters vialakefile.lean. The most important options are listed below.
| Option | Effect |
|---|---|
linter.mathlibStandardSet | Enables Mathlib’s full default set of linters |
linter.style.header | Checks that every file has a valid copyright/author header |
linter.style.longFile | Warns when a file exceeds 1500 lines |
linter.checkInitImports | Validates imports in Mathlib.Init files |
linter.allScriptsDocumented | Requires all scripts to have documentation |
linter.pythonStyle | Enforces Python-style indentation rules in scripts |
autoImplicit | Set to false — all variables must be declared explicitly |
mathlibLeanOptions in lakefile.lean as weak options, meaning they apply to every lake build invocation across Mathlib, Archive, and Counterexamples.
The autolabel Tool
Mathlib uses a GitHub label system to categorize PRs by mathematical topic (e.g., t-algebra, t-topology, t-number-theory). The autolabel executable infers the correct label from the files your PR modifies.
To preview labels without applying them:
gh to be installed):
Related Pages
Style Guide
File headers, line length, Unicode, indentation, and proof formatting rules.
Naming Conventions
How theorems, definitions, instances, and namespaces are named in Mathlib.
Building & Testing
Lake commands for building, testing, linting, and generating HTML docs.