Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

naming advice around inj and ext #60

Merged
merged 2 commits into from
Jun 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions templates/contribute/naming.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,44 @@ check le_of_mul_le_mul_left
check le_of_mul_le_mul_right
```

## Naming of structural lemmas ##

We are trying to standardize certain naming patterns for structural lemmas.
At present these are not uniform across mathlib.

### Extensionality ###

A lemma of the form `(∀ x, f x = g x) → f = g` should be named `.ext`,
and labelled with the `@[ext]` attribute.
Often this type of lemma can be generated automatically by putting the
`@[ext]` attribute on a structure.
kim-em marked this conversation as resolved.
Show resolved Hide resolved
kim-em marked this conversation as resolved.
Show resolved Hide resolved
(However an automatically generated lemma will always be written in terms
of the structure projections, and often there is a better statement,
e.g. using coercions, that should be written by hand then marked with `@[ext]`.)


A lemma of the form `f = g ↔ ∀ x, f x = g x` should be named `.ext_iff`.

### Injectivity ###

Injectivity lemmas should usually be written as bidirectional implications,
e.g. as `f x = f y ↔ x = y`. Such lemmas should be named `f_inj`
(although if they are in an appropriate namespace `.inj` is good too).
Bidirectional injectivity lemmas are often good candidates for `@[simp]`.
There are still many unidirectional implications named `inj` in mathlib,
and it is reasonable to update and replace these as you come across them.

Note however that constructors for inductive types have
automatically generated unidirectional implications, named `.inj`,
and there is no intention to change this.
When such an automatically generated lemma already exists,
and a bidirectional lemma is needed, it may be named `.inj_iff`.

Injectivity lemmas written in terms of an `injective f` conclusion
should instead use the full word `injective`, typically as `f_injective`.
The form `injective_f` still appears often in mathlib.


------
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Expand Down