mathlib-style
Skill0 starsChanged 8 months agoMITView on GitHub
Use when writing or reviewing Lean 4 mathlib code for style, naming, docs, and lint.
In this repository13 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- ccswitchSkill
- code-rulesSkill
- leanmgr-cache-managerSkill
- learn-math-by-lean-notebookSkill
- lmfdb-cliSkill
- mathlib-workflowSkill
- openclaw-rssSkill
- pre-initSkill
- pr-worktree-workflowSkill
- sshSkill
- tmuxSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
30 rules. About 0 are common, 11 are distinctive, and 19 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈11
Distinctive · estimate
This author's own choices. Worth a look.
19
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Use this skill to make Lean code acceptable for mathlib review.
- Distinctive: line 18
Start narrow, then open only the references needed for the task.
- Distinctive: line 37
Apply the relevant checklist below: Prefer small edits and avoid unrelated refactors.
- Distinctive: line 39
Run executable checks: Use the command checklist that matches the repository and the files touched.
- Distinctive: line 44
Use this first for every mathlib edit.
- Very specific: line 53
Use namespace, section, open, and variable for ownership and scope.
- Very specific: line 60
Do not use $; use <|, |>, or parentheses.
- Very specific: line 61
Write anonymous functions with fun (not λ) and prefer ↦ over =>.
- Distinctive: line 63
Avoid empty lines inside declarations.
- Very specific: line 64
Do not squeeze terminal simp unless performance or brittleness requires it.
- Very specific: line 65
Prefer API lemmas over forcing unfolding with erw or rfl after simp/rw.
- Very specific: line 66
Use where syntax for structures and instances.
- Very specific: line 67
Add deprecation aliases/messages with @[deprecated (since := "YYYY-MM-DD")] when renaming or removing public declarations.
- Very specific: line 76
When an UpperCamelCase name appears inside a theorem name, lower-camel it inside the snake_case name, e.g.
- Very specific: line 79
Use mathlib's symbol dictionary: and, or, iff, ne, le, lt, mem, union, inter, smul, dvd, iSup, iInf, and so on.
- Very specific: line 82
Use namespace-qualified structural names where appropriate: .ext, .ext_iff, .inj, .inj_iff, .rec, .recOn, .induction, .induction_on.
- Very specific: line 89
Every file has a module docstring /-!
- Distinctive: line 95
Every definition and major theorem has a doc string.
- Very specific: line 101
Use sectioning comments /-!
- Distinctive: line 106
Run the narrowest checks that prove the edit.
- Very specific: line 114
Use lake exe mk_all when adding, deleting, moving, or renaming modules.
- Very specific: line 133
If lake lint is unavailable downstream, the project likely needs a lintDriver such as batteries/runLinter.
- Very specific: line 147
Use @[nolint ...] only for justified false positives.
- Distinctive: line 152
Do not introduce a new abstraction just to make a short proof prettier.
- Very specific: line 153
Do not replace a stable terminal simp with a long squeezed simp only.
- Distinctive: line 154
Do not change neighboring naming schemes without checking adjacent files.
- Distinctive: line 155
Do not add broad imports when a narrower import builds.
- Very specific: line 156
Do not leave temporary #check, #eval, #lint, or search commands in PR code.
- Very specific: line 157
Do not use irreducible to seal an API.
- Very specific: line 158
Do not reach for nonrec unless required.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
mathlib Style
Use this skill to make Lean code acceptable for mathlib review. Treat the upstream guides as the source of truth and use this file as an execution checklist.
Sources:
- Style: https://leanprover-community.github.io/contribute/style.html
- Naming: https://leanprover-community.github.io/contribute/naming.html
- Documentation: https://leanprover-community.github.io/contribute/doc.html
Progressive Disclosure Workflow
Start narrow, then open only the references needed for the task.
- Triage the change. Identify whether the work is mainly formatting, naming, documentation, API design, proof maintenance, or lint cleanup.
- Load the minimum reference.
- Unsure which topic applies: read
references/README.md. - File headers/imports: read
references/style/header-imports.md. - Declaration/proof layout: read
references/style/declaration-layout.md. - Tactic proof style: read
references/style/tactic-proofs.md. - API, normal forms, transparency, deprecation: read
references/style/api-design.md. - Declaration names: read
references/naming/capitalization.md. - Theorem-name atoms and symbols: read
references/naming/symbols.md. - Structural theorem naming: read
references/naming/structural-lemmas.md. - Module docs: read
references/docs/module-docs.md. - Declaration doc strings: read
references/docs/docstrings.md. - Citations and generated docs: read
references/docs/citations-and-sections.md. - Linter commands and responses: read
references/lint/checks.md.
- Unsure which topic applies: read
- Inspect nearby mathlib code. Match local conventions in adjacent files before introducing a new pattern.
- Apply the relevant checklist below. Prefer small edits and avoid unrelated refactors.
- Run executable checks. Use the command checklist that matches the repository and the files touched.
Core Review Checklist
Use this first for every mathlib edit.
- File names are
UpperCamelCase.lean, except rare Zulip-discussed exceptions. - New mathlib files start with copyright/authors, then
module, then imports, then a module docstring. public importandimportdeclarations are grouped separately and kept alphabetic within each block.- Lines are at most 100 characters unless there is a compelling local exception.
- Top-level commands and declarations are flush-left, even inside namespaces.
- Use
namespace,section,open, andvariablefor ownership and scope; keep broad effects close to the declarations that need them. - Declaration arguments and return types are explicit enough to read on GitHub.
- Multi-line theorem statements indent continuation lines by 4 spaces; proofs indent by 2 spaces.
:= byand tactic-modebystay on the preceding line, never alone.- Focusing bullets use
·for subgoals. - Do not use
$; use<|,|>, or parentheses. - Write anonymous functions with
fun(notλ) and prefer↦over=>. - In
rw/simp, write←with a following space. - Avoid empty lines inside declarations; use a short comment if separation matters.
- Do not squeeze terminal
simpunless performance or brittleness requires it. - Prefer API lemmas over forcing unfolding with
erworrflaftersimp/rw. - Use
wheresyntax for structures and instances. - Add deprecation aliases/messages with
@[deprecated (since := "YYYY-MM-DD")]when renaming or removing public declarations.
Naming Checklist
- Proofs/theorems/terms of
Prop:snake_case. Prop,Type,Sort, structures, classes, and inductives:UpperCamelCase.- Functions are named like their return values.
- Other terms of
Type:lowerCamelCase. - When an
UpperCamelCasename appears inside a theorem name, lower-camel it inside thesnake_casename, e.g.neZero_iff. - Declaration names use American English spelling.
- Use mathlib's symbol dictionary:
and,or,iff,ne,le,lt,mem,union,inter,smul,dvd,iSup,iInf, and so on. - Name hypotheses with
ofin statement order:C_of_A_of_B. - Use namespace-qualified structural names where appropriate:
.ext,.ext_iff,.inj,.inj_iff,.rec,.recOn,.induction,.induction_on. - Predicates normally appear as prefixes, except established suffix families
such as
_injective,_surjective,_mono,_monotone,_strictMono.
Documentation Checklist
- Every file has a module docstring
/-! ... -/after imports. - Module docs include a title and summary; add sections only when useful:
Main definitions,Main statements,Notation,Implementation notes,References,Tags. - New bibliography entries go in
docs/references.bib; cite with mathlib's bracket style. - Every definition and major theorem has a doc string. Lemmas with mathematical content should usually have one too.
- Doc strings use
/-- ... -/, Markdown, and LaTeX where helpful. - Complete-sentence doc strings end with periods.
- Named theorems in prose are bold, for example
**Mean Value Theorem**. - Multi-line declaration doc strings are not indented after the first line.
- Use sectioning comments
/-! ### Section title -/for generated docs; use ordinary comments for implementation-only notes.
Executable Checks
Run the narrowest checks that prove the edit. In mathlib itself, prefer:
lake build Mathlib.Path.To.Module
lake exe lint-style
lake exe mk_allUse lake exe mk_all when adding, deleting, moving, or renaming modules.
For focused declaration linting while editing a Lean file, temporarily add one of these commands near the end of the file, run the file, then remove it before committing unless the project intentionally keeps it:
#lint
#lint only docBlame docBlameThm
#list_lintersFor downstream projects configured with a Lake lint driver, run:
lake lint
lake testIf lake lint is unavailable downstream, the project likely needs a lintDriver
such as batteries/runLinter; do not add project configuration unless the task
explicitly includes downstream setup.
Lint Response Hints
docBlame: add a doc string to the reported definition.docBlameThm: add a doc string to a theorem or lemma with reusable mathematical content.- Naming lints: rename the declaration and add a deprecation alias if it is public.
- Style lints on whitespace/line endings/unicode: fix the source text rather than silencing the linter.
- Unused argument or generated-name lints: prefer strengthening the statement,
naming arguments intentionally, or using local conventions over adding
nolint. - Use
@[nolint ...]only for justified false positives; include a nearby comment when the reason is not obvious.
Common Anti-Patterns
- Do not introduce a new abstraction just to make a short proof prettier.
- Do not replace a stable terminal
simpwith a long squeezedsimp only. - Do not change neighboring naming schemes without checking adjacent files.
- Do not add broad imports when a narrower import builds.
- Do not leave temporary
#check,#eval,#lint, or search commands in PR code. - Do not use
irreducibleto seal an API; prefer structures or explicit lemmas. - Do not reach for
nonrecunless required; prefer restructuring the declaration.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

