agentleFS
FrankieeWFrankieeW/agent-skills/mathlib-style/SKILL.md

mathlib-style

Skill0 starsChanged 8 months agoMITView on GitHub

Use when writing or reviewing Lean 4 mathlib code for style, naming, docs, and lint.

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
  1. Distinctive:

    Use this skill to make Lean code acceptable for mathlib review.

    line 8
  2. Distinctive:

    Start narrow, then open only the references needed for the task.

    line 18
  3. Distinctive:

    Apply the relevant checklist below: Prefer small edits and avoid unrelated refactors.

    line 37
  4. Distinctive:

    Run executable checks: Use the command checklist that matches the repository and the files touched.

    line 39
  5. Distinctive:

    Use this first for every mathlib edit.

    line 44
  6. Very specific:

    Use namespace, section, open, and variable for ownership and scope.

    line 53
  7. Very specific:

    Do not use $; use <|, |>, or parentheses.

    line 60
  8. Very specific:

    Write anonymous functions with fun (not λ) and prefer ↦ over =>.

    line 61
  9. Distinctive:

    Avoid empty lines inside declarations.

    line 63
  10. Very specific:

    Do not squeeze terminal simp unless performance or brittleness requires it.

    line 64
  11. Very specific:

    Prefer API lemmas over forcing unfolding with erw or rfl after simp/rw.

    line 65
  12. Very specific:

    Use where syntax for structures and instances.

    line 66
  13. Very specific:

    Add deprecation aliases/messages with @[deprecated (since := "YYYY-MM-DD")] when renaming or removing public declarations.

    line 67
  14. Very specific:

    When an UpperCamelCase name appears inside a theorem name, lower-camel it inside the snake_case name, e.g.

    line 76
  15. Very specific:

    Use mathlib's symbol dictionary: and, or, iff, ne, le, lt, mem, union, inter, smul, dvd, iSup, iInf, and so on.

    line 79
  16. Very specific:

    Use namespace-qualified structural names where appropriate: .ext, .ext_iff, .inj, .inj_iff, .rec, .recOn, .induction, .induction_on.

    line 82
  17. Very specific:

    Every file has a module docstring /-!

    line 89
  18. Distinctive:

    Every definition and major theorem has a doc string.

    line 95
  19. Very specific:

    Use sectioning comments /-!

    line 101
  20. Distinctive:

    Run the narrowest checks that prove the edit.

    line 106
  21. Very specific:

    Use lake exe mk_all when adding, deleting, moving, or renaming modules.

    line 114
  22. Very specific:

    If lake lint is unavailable downstream, the project likely needs a lintDriver such as batteries/runLinter.

    line 133
  23. Very specific:

    Use @[nolint ...] only for justified false positives.

    line 147
  24. Distinctive:

    Do not introduce a new abstraction just to make a short proof prettier.

    line 152
  25. Very specific:

    Do not replace a stable terminal simp with a long squeezed simp only.

    line 153
  26. Distinctive:

    Do not change neighboring naming schemes without checking adjacent files.

    line 154
  27. Distinctive:

    Do not add broad imports when a narrower import builds.

    line 155
  28. Very specific:

    Do not leave temporary #check, #eval, #lint, or search commands in PR code.

    line 156
  29. Very specific:

    Do not use irreducible to seal an API.

    line 157
  30. Very specific:

    Do not reach for nonrec unless required.

    line 158

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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:

Progressive Disclosure Workflow

Start narrow, then open only the references needed for the task.

  1. Triage the change. Identify whether the work is mainly formatting, naming, documentation, API design, proof maintenance, or lint cleanup.
  2. 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.
  3. Inspect nearby mathlib code. Match local conventions in adjacent files before introducing a new pattern.
  4. Apply the relevant checklist below. Prefer small edits and avoid unrelated refactors.
  5. 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 import and import declarations 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, and variable for 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.
  • := by and tactic-mode by stay 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 simp unless performance or brittleness requires it.
  • Prefer API lemmas over forcing unfolding with erw or rfl after simp/rw.
  • Use where syntax 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 UpperCamelCase name appears inside a theorem name, lower-camel it inside the snake_case name, 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 of in 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_all

Use 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_linters

For downstream projects configured with a Lake lint driver, run:

lake lint
lake test

If 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 simp with a long squeezed simp 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 irreducible to seal an API; prefer structures or explicit lemmas.
  • Do not reach for nonrec unless required; prefer restructuring the declaration.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.