Skip to content

Commit 04a5a82

Browse files
authored
naming advice around inj and ext (#60)
* naming advice around `inj` and `ext`. * Apply suggestions from code review
1 parent c999685 commit 04a5a82

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

templates/contribute/naming.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,44 @@ check le_of_mul_le_mul_left
259259
check le_of_mul_le_mul_right
260260
```
261261

262+
## Naming of structural lemmas ##
263+
264+
We are trying to standardize certain naming patterns for structural lemmas.
265+
At present these are not uniform across mathlib.
266+
267+
### Extensionality ###
268+
269+
A lemma of the form `(∀ x, f x = g x) → f = g` should be named `.ext`,
270+
and labelled with the `@[ext]` attribute.
271+
Often this type of lemma can be generated automatically by putting the
272+
`@[ext]` attribute on a structure.
273+
(However an automatically generated lemma will always be written in terms
274+
of the structure projections, and often there is a better statement,
275+
e.g. using coercions, that should be written by hand then marked with `@[ext]`.)
276+
277+
278+
A lemma of the form `f = g ↔ ∀ x, f x = g x` should be named `.ext_iff`.
279+
280+
### Injectivity ###
281+
282+
Injectivity lemmas should usually be written as bidirectional implications,
283+
e.g. as `f x = f y ↔ x = y`. Such lemmas should be named `f_inj`
284+
(although if they are in an appropriate namespace `.inj` is good too).
285+
Bidirectional injectivity lemmas are often good candidates for `@[simp]`.
286+
There are still many unidirectional implications named `inj` in mathlib,
287+
and it is reasonable to update and replace these as you come across them.
288+
289+
Note however that constructors for inductive types have
290+
automatically generated unidirectional implications, named `.inj`,
291+
and there is no intention to change this.
292+
When such an automatically generated lemma already exists,
293+
and a bidirectional lemma is needed, it may be named `.inj_iff`.
294+
295+
Injectivity lemmas written in terms of an `injective f` conclusion
296+
should instead use the full word `injective`, typically as `f_injective`.
297+
The form `injective_f` still appears often in mathlib.
298+
299+
262300
------
263301
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
264302
Released under Apache 2.0 license as described in the file LICENSE.

0 commit comments

Comments
 (0)