Skip to content

Commit 9efa3a0

Browse files
authored
doc(naming): Update code snippets to Lean 3, adjust section on injectivity (#163)
1 parent d2d800a commit 9efa3a0

File tree

1 file changed

+54
-47
lines changed

1 file changed

+54
-47
lines changed

templates/contribute/naming.md

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -229,51 +229,58 @@ as `Group`. In that case, use CamelCase for compound names, such as
229229
We adopt the following naming guidelines to make it easier for users
230230
to guess the name of a theorem or find it using tab completion. Common
231231
"axiomatic" properties of an operation like conjunction or
232-
multiplication are put in a namespace that begins with the name of the
232+
disjunction are put in a namespace that begins with the name of the
233233
operation:
234234
```lean
235-
import standard algebra.ordered_ring
235+
import logic.basic
236236
237-
check and.comm
238-
check mul.comm
239-
check and.assoc
240-
check mul.assoc
241-
check @mul.left_cancel -- multiplication is left cancelative
237+
#check and.comm
238+
#check or.comm
239+
#check and.assoc
240+
#check or.assoc
242241
```
243242
In particular, this includes `intro` and `elim` operations for logical
244243
connectives, and properties of relations:
245244
```lean
246-
import standard algebra.ordered_ring
245+
import logic.basic
247246
248-
check and.intro
249-
check and.elim
250-
check or.intro_left
251-
check or.intro_right
252-
check or.elim
247+
#check and.intro
248+
#check and.elim
249+
#check or.intro_left
250+
#check or.intro_right
251+
#check or.elim
253252
254-
check eq.refl
255-
check eq.symm
256-
check eq.trans
253+
#check eq.refl
254+
#check eq.symm
255+
#check eq.trans
256+
```
257+
Note however we do not do this for axiomatic arithmetic operations
258+
```lean
259+
import algebra.group.basic
260+
261+
#check mul_comm
262+
#check mul_assoc
263+
#check @mul_left_cancel -- multiplication is left cancelative
257264
```
258265

259266
For the most part, however, we rely on descriptive names. Often the
260267
name of theorem simply describes the conclusion:
261268
```lean
262-
import standard algebra.ordered_ring
269+
import algebra.ring.basic
263270
open nat
264-
check succ_ne_zero
265-
check mul_zero
266-
check mul_one
267-
check @sub_add_eq_add_sub
268-
check @le_iff_lt_or_eq
271+
#check succ_ne_zero
272+
#check mul_zero
273+
#check mul_one
274+
#check @sub_add_eq_add_sub
275+
#check @le_iff_lt_or_eq
269276
```
270277
If only a prefix of the description is enough to convey the meaning,
271278
the name may be made even shorter:
272279
```lean
273-
import standard algebra.ordered_ring
280+
import algebra.ordered_ring
274281
275-
check @neg_neg
276-
check nat.pred_succ
282+
#check @neg_neg
283+
#check nat.pred_succ
277284
```
278285
When an operation is written as infix, the theorem names follow
279286
suit. For example, we write `neg_mul_neg` rather than `mul_neg_neg` to
@@ -283,12 +290,12 @@ Sometimes, to disambiguate the name of theorem or better convey the
283290
intended reference, it is necessary to describe some of the
284291
hypotheses. The word "of" is used to separate these hypotheses:
285292
```lean
286-
import standard algebra.ordered_ring
293+
import algebra.ordered_ring
287294
open nat
288-
check lt_of_succ_le
289-
check lt_of_not_ge
290-
check lt_of_le_of_ne
291-
check add_lt_add_of_lt_of_le
295+
#check lt_of_succ_le
296+
#check lt_of_not_ge
297+
#check lt_of_le_of_ne
298+
#check add_lt_add_of_lt_of_le
292299
```
293300
The hypotheses are listed in the order they appear, _not_ reverse
294301
order. For example, the theorem `A → B → C` would be named
@@ -298,12 +305,12 @@ Sometimes abbreviations or alternative descriptions are easier to work
298305
with. For example, we use `pos`, `neg`, `nonpos`, `nonneg` rather than
299306
`zero_lt`, `lt_zero`, `le_zero`, and `zero_le`.
300307
```lean
301-
import standard algebra.ordered_ring
308+
import algebra.ordered_ring
302309
open nat
303-
check mul_pos
304-
check mul_nonpos_of_nonneg_of_nonpos
305-
check add_lt_of_lt_of_nonpos
306-
check add_lt_of_nonpos_of_lt
310+
#check mul_pos
311+
#check mul_nonpos_of_nonneg_of_nonpos
312+
#check add_lt_of_lt_of_nonpos
313+
#check add_lt_of_nonpos_of_lt
307314
```
308315

309316
These conventions are not perfect. They cannot distinguish compound
@@ -314,12 +321,12 @@ could be named either `add_sub_self` or `add_sub_cancel`.
314321
Sometimes the word "left" or "right" is helpful to describe variants
315322
of a theorem.
316323
```lean
317-
import standard algebra.ordered_ring
324+
import algebra.ordered_ring
318325
319-
check add_le_add_left
320-
check add_le_add_right
321-
check le_of_mul_le_mul_left
322-
check le_of_mul_le_mul_right
326+
#check add_le_add_left
327+
#check add_le_add_right
328+
#check le_of_mul_le_mul_left
329+
#check le_of_mul_le_mul_right
323330
```
324331

325332
## Naming of structural lemmas ##
@@ -342,8 +349,13 @@ A lemma of the form `f = g ↔ ∀ x, f x = g x` should be named `.ext_iff`.
342349

343350
### Injectivity ###
344351

345-
Injectivity lemmas should usually be written as bidirectional implications,
346-
e.g. as `f x = f y ↔ x = y`. Such lemmas should be named `f_inj`
352+
Where possible, injectivity lemmas should be written in terms of an
353+
`injective f` conclusion which use the full word `injective`, typically as `f_injective`.
354+
The form `injective_f` still appears often in mathlib.
355+
356+
In addition to these, a variant should usually be provided as a bidirectional implication,
357+
e.g. as `f x = f y ↔ x = y`, which can be obtained from `function.injective.eq_iff`.
358+
Such lemmas should be named `f_inj`
347359
(although if they are in an appropriate namespace `.inj` is good too).
348360
Bidirectional injectivity lemmas are often good candidates for `@[simp]`.
349361
There are still many unidirectional implications named `inj` in mathlib,
@@ -355,11 +367,6 @@ and there is no intention to change this.
355367
When such an automatically generated lemma already exists,
356368
and a bidirectional lemma is needed, it may be named `.inj_iff`.
357369

358-
Injectivity lemmas written in terms of an `injective f` conclusion
359-
should instead use the full word `injective`, typically as `f_injective`.
360-
The form `injective_f` still appears often in mathlib.
361-
362-
363370
------
364371
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
365372
Released under Apache 2.0 license as described in the file LICENSE.

0 commit comments

Comments
 (0)