Mathlib’s naming conventions are not merely aesthetic preferences — they form a systematic, predictable language that allows contributors to guess the name of a theorem before looking it up, and to understand a theorem’s content from its name alone. Following these conventions precisely is one of the most important aspects of writing Mathlib-quality code, and reviewers will request renames before merging a PR that deviates from them.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.
The Core Principle: Names Reflect Statements
Theorem names in Mathlib are constructed by concatenating the names of the mathematical objects and relations that appear in the statement. GivenNat.add_comm, you can infer that this is a theorem about Nat, involving add, stating commutativity — without reading the statement at all.
Casing Rules
| Identifier kind | Convention | Example |
|---|---|---|
| Types and structures | UpperCamelCase | NNReal, FreeGroup, LinearMap |
| Typeclasses | UpperCamelCase | CommRing, Fintype, MeasurableSpace |
| Definitions and functions | lowerCamelCase (in a namespace) | Finset.card, List.getLast |
| Theorem and lemma names | snake_case | Nat.add_comm, List.length_nil |
| Typeclass instances | instUpperCamelCase | instDecidableEqNat, instAddMonoidNat |
| Namespace names | UpperCamelCase | namespace Algebra, namespace List |
The distinction between definitions (
lowerCamelCase) and theorems (snake_case) is intentional: it lets you immediately tell from a name whether something is a computable piece of data or a proof.Namespace Conventions
Namespaces mirror the module path and the primary type or concept being developed:Finset live in the Finset namespace, allowing dot notation: s.card_union_add_card_inter t instead of Finset.card_union_add_card_inter s t.
Suffix Conventions
Suffixes encode the logical form of the statement. The table below lists the standard suffixes used across Mathlib._iff — biconditional characterizations
_iff — biconditional characterizations
Use
_iff when the statement is an ↔ (if and only if):_eq — equalities
_eq — equalities
Use Note: many equality theorems do not use
_eq when the statement is an =:_eq explicitly when the equality is already implied by the rest of the name (e.g., List.length_append is already clearly an equality statement)._ne — disequalities
_ne — disequalities
Use
_ne when the statement is a ≠:_le, _lt, _ge, _gt — order facts
_le, _lt, _ge, _gt — order facts
Use these suffixes for inequalities:
_comm and _assoc — algebraic laws
_comm and _assoc — algebraic laws
Use
_comm for commutativity and _assoc for associativity:_zero and _one — identity element facts
_zero and _one — identity element facts
Use
_zero for additive identities and _one for multiplicative identities:_add and _mul — operation facts
_add and _mul — operation facts
These suffixes indicate that the statement involves the additive or multiplicative operation acting on a compound expression:
_def — unfolding definitions
_def — unfolding definitions
Use
_def for lemmas that unfold or restate the definition of a term:Prefix Conventions
of_ — constructing from hypotheses
Use of_ as a prefix when a theorem or constructor produces a value given some hypothesis:
to_ — conversions between types
Use to_ as a prefix for functions or coercions that convert one type to another:
The Prime ' Suffix
A trailing prime (') marks a variant of an existing theorem — typically one with:
- Hypotheses in a different order
- A weaker or asymmetric statement
- An alternative formulation useful in specific contexts
Typeclass Instances
Instances use theinstXxx prefix in UpperCamelCase, followed by the name of the typeclass and the type:
inst prefix:
Decidable Instances
Decidable instances follow the sameinst convention. The Decidable prefix appears in the typeclass name, not as a separate prefix on the instance:
Plural vs. Singular
- Use singular for a predicate or property:
Nat.Prime,List.Nodup,Set.Finite. - Use plural for a set or collection of objects satisfying a property:
Nat.primes(the set of all prime naturals).
Avoiding Name Collisions
Before settling on a name, always verify it is not already taken:exact? and apply? in the editor to discover existing lemmas.