Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit ef47de4

Browse files
urkudmergify[bot]
authored andcommitted
chore(data/nat/basic): add some docs, drop unused arguments (#1741)
* add a docstring * chore(data/nat/basic): add some docs, drop unused arguments
1 parent 73735ad commit ef47de4

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/data/nat/basic.lean

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22
Copyright (c) 2014 Floris van Doorn. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro
5-
6-
Basic operations on the natural numbers.
75
-/
86
import logic.basic algebra.ordered_ring data.option.basic algebra.order_functions
97

8+
/-!
9+
# Basic operations on the natural numbers
10+
11+
This files has some basic lemmas about natural numbers, definition of the `choice` function,
12+
and extra recursors:
13+
14+
* `le_rec_on`, `le_induction`: recursion and induction principles starting at non-zero numbers.
15+
* `decreasing_induction` : recursion gowing downwards.
16+
* `strong_rec'` : recursion based on strong inequalities.
17+
-/
18+
1019
universes u v
1120

1221
namespace nat
@@ -64,6 +73,8 @@ by simp only [add_comm, nat.lt_succ_iff]
6473
theorem of_le_succ {n m : ℕ} (H : n ≤ m.succ) : n ≤ m ∨ n = m.succ :=
6574
(lt_or_eq_of_le H).imp le_of_lt_succ id
6675

76+
/-- Recursion starting at a non-zero number: given a map `C k → C (k+1)` for each `k`,
77+
there is a map from `C n` to each `C m`, `n ≤ m`. -/
6778
@[elab_as_eliminator]
6879
def le_rec_on {C : ℕ → Sort u} {n : ℕ} : Π {m : ℕ}, n ≤ m → (Π {k}, C k → C (k+1)) → C n → C m
6980
| 0 H next x := eq.rec_on (eq_zero_of_le_zero H) x
@@ -335,6 +346,7 @@ end
335346
theorem two_mul_ne_two_mul_add_one {n m} : 2 * n ≠ 2 * m + 1 :=
336347
mt (congr_arg (%2)) (by rw [add_comm, add_mul_mod_self_left, mul_mod_right]; exact dec_trivial)
337348

349+
/-- Recursion principle based on `<`. -/
338350
@[elab_as_eliminator]
339351
protected def strong_rec' {p : ℕ → Sort u} (H : ∀ n, (∀ m, m < n → p m) → p n) : ∀ (n : ℕ), p n
340352
| n := H n (λ m hm, strong_rec' m)
@@ -811,7 +823,7 @@ strict_mono.le_iff_le (pow_left_strict_mono k)
811823
lemma pow_lt_iff_lt_left {m x y : ℕ} (k : 1 ≤ m) : x^m < y^m ↔ x < y :=
812824
strict_mono.lt_iff_lt (pow_left_strict_mono k)
813825

814-
lemma pow_left_injective {m x y : ℕ} (k : 1 ≤ m) : function.injective (λ (x : ℕ), x^m) :=
826+
lemma pow_left_injective {m : ℕ} (k : 1 ≤ m) : function.injective (λ (x : ℕ), x^m) :=
815827
strict_mono.injective (pow_left_strict_mono k)
816828

817829
lemma not_pos_pow_dvd : ∀ {p k : ℕ} (hp : 1 < p) (hk : 1 < k), ¬ p^k ∣ p
@@ -1045,6 +1057,8 @@ end
10451057

10461058
/- choose -/
10471059

1060+
/-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial
1061+
coefficients. -/
10481062
def choose : ℕ → ℕ → ℕ
10491063
| _ 0 := 1
10501064
| 0 (k + 1) := 0
@@ -1305,10 +1319,13 @@ lemma with_bot.add_eq_one_iff : ∀ {n m : with_bot ℕ}, n + m = 1 ↔ (n = 0
13051319

13061320
-- induction
13071321

1322+
/-- Induction principle starting at a non-zero number. For maps to a `Sort*` see `le_rec_on`. -/
13081323
@[elab_as_eliminator] lemma le_induction {P : nat → Prop} {m} (h0 : P m) (h1 : ∀ n, m ≤ n → P n → P (n + 1)) :
13091324
∀ n, m ≤ n → P n :=
13101325
by apply nat.less_than_or_equal.rec h0; exact h1
13111326

1327+
/-- Decreasing induction: if `P (k+1)` implies `P k`, then `P n` implies `P m` for all `m ≤ n`.
1328+
Also works for functions to `Sort*`. -/
13121329
@[elab_as_eliminator]
13131330
def decreasing_induction {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {m n : ℕ} (mn : m ≤ n)
13141331
(hP : P n) : P m :=

0 commit comments

Comments
 (0)