|
2 | 2 | Copyright (c) 2014 Floris van Doorn. All rights reserved.
|
3 | 3 | Released under Apache 2.0 license as described in the file LICENSE.
|
4 | 4 | Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro
|
5 |
| -
|
6 |
| -Basic operations on the natural numbers. |
7 | 5 | -/
|
8 | 6 | import logic.basic algebra.ordered_ring data.option.basic algebra.order_functions
|
9 | 7 |
|
| 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 | + |
10 | 19 | universes u v
|
11 | 20 |
|
12 | 21 | namespace nat
|
@@ -64,6 +73,8 @@ by simp only [add_comm, nat.lt_succ_iff]
|
64 | 73 | theorem of_le_succ {n m : ℕ} (H : n ≤ m.succ) : n ≤ m ∨ n = m.succ :=
|
65 | 74 | (lt_or_eq_of_le H).imp le_of_lt_succ id
|
66 | 75 |
|
| 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`. -/ |
67 | 78 | @[elab_as_eliminator]
|
68 | 79 | def le_rec_on {C : ℕ → Sort u} {n : ℕ} : Π {m : ℕ}, n ≤ m → (Π {k}, C k → C (k+1)) → C n → C m
|
69 | 80 | | 0 H next x := eq.rec_on (eq_zero_of_le_zero H) x
|
|
335 | 346 | theorem two_mul_ne_two_mul_add_one {n m} : 2 * n ≠ 2 * m + 1 :=
|
336 | 347 | mt (congr_arg (%2)) (by rw [add_comm, add_mul_mod_self_left, mul_mod_right]; exact dec_trivial)
|
337 | 348 |
|
| 349 | +/-- Recursion principle based on `<`. -/ |
338 | 350 | @[elab_as_eliminator]
|
339 | 351 | protected def strong_rec' {p : ℕ → Sort u} (H : ∀ n, (∀ m, m < n → p m) → p n) : ∀ (n : ℕ), p n
|
340 | 352 | | n := H n (λ m hm, strong_rec' m)
|
@@ -811,7 +823,7 @@ strict_mono.le_iff_le (pow_left_strict_mono k)
|
811 | 823 | lemma pow_lt_iff_lt_left {m x y : ℕ} (k : 1 ≤ m) : x^m < y^m ↔ x < y :=
|
812 | 824 | strict_mono.lt_iff_lt (pow_left_strict_mono k)
|
813 | 825 |
|
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) := |
815 | 827 | strict_mono.injective (pow_left_strict_mono k)
|
816 | 828 |
|
817 | 829 | lemma not_pos_pow_dvd : ∀ {p k : ℕ} (hp : 1 < p) (hk : 1 < k), ¬ p^k ∣ p
|
@@ -1045,6 +1057,8 @@ end
|
1045 | 1057 |
|
1046 | 1058 | /- choose -/
|
1047 | 1059 |
|
| 1060 | +/-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial |
| 1061 | +coefficients. -/ |
1048 | 1062 | def choose : ℕ → ℕ → ℕ
|
1049 | 1063 | | _ 0 := 1
|
1050 | 1064 | | 0 (k + 1) := 0
|
@@ -1305,10 +1319,13 @@ lemma with_bot.add_eq_one_iff : ∀ {n m : with_bot ℕ}, n + m = 1 ↔ (n = 0
|
1305 | 1319 |
|
1306 | 1320 | -- induction
|
1307 | 1321 |
|
| 1322 | +/-- Induction principle starting at a non-zero number. For maps to a `Sort*` see `le_rec_on`. -/ |
1308 | 1323 | @[elab_as_eliminator] lemma le_induction {P : nat → Prop} {m} (h0 : P m) (h1 : ∀ n, m ≤ n → P n → P (n + 1)) :
|
1309 | 1324 | ∀ n, m ≤ n → P n :=
|
1310 | 1325 | by apply nat.less_than_or_equal.rec h0; exact h1
|
1311 | 1326 |
|
| 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*`. -/ |
1312 | 1329 | @[elab_as_eliminator]
|
1313 | 1330 | def decreasing_induction {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {m n : ℕ} (mn : m ≤ n)
|
1314 | 1331 | (hP : P n) : P m :=
|
|
0 commit comments