|
| 1 | +/- |
| 2 | +Copyright (c) 2014 Mario Carneiro. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Mario Carneiro, Yaël Dillies, Patrick Stevens |
| 5 | +
|
| 6 | +! This file was ported from Lean 3 source module data.nat.cast.field |
| 7 | +! leanprover-community/mathlib commit 9116dd6709f303dcf781632e15fdef382b0fc579 |
| 8 | +! Please do not edit these lines, except to modify the commit id |
| 9 | +! if you have ported upstream changes. |
| 10 | +-/ |
| 11 | +import Mathlib.Algebra.Order.Field.Basic |
| 12 | +import Mathlib.Algebra.Order.Ring.CharZero |
| 13 | +import Mathlib.Data.Nat.Cast.Basic |
| 14 | + |
| 15 | +/-! |
| 16 | +# Cast of naturals into fields |
| 17 | +
|
| 18 | +This file concerns the canonical homomorphism `ℕ → F`, where `F` is a field. |
| 19 | +
|
| 20 | +## Main results |
| 21 | +
|
| 22 | + * `Nat.cast_div`: if `n` divides `m`, then `↑(m / n) = ↑m / ↑n` |
| 23 | + * `Nat.cast_div_le`: in all cases, `↑(m / n) ≤ ↑m / ↑ n` |
| 24 | +-/ |
| 25 | + |
| 26 | + |
| 27 | +namespace Nat |
| 28 | + |
| 29 | +variable {α : Type _} |
| 30 | + |
| 31 | +@[simp] |
| 32 | +theorem cast_div [Field α] {m n : ℕ} (n_dvd : n ∣ m) (n_nonzero : (n : α) ≠ 0) : |
| 33 | + ((m / n : ℕ) : α) = m / n := by |
| 34 | + rcases n_dvd with ⟨k, rfl⟩ |
| 35 | + have : n ≠ 0 := by |
| 36 | + rintro rfl |
| 37 | + simp at n_nonzero |
| 38 | + rw [Nat.mul_div_cancel_left _ this.bot_lt, cast_mul, mul_div_cancel_left _ n_nonzero] |
| 39 | +#align nat.cast_div Nat.cast_div |
| 40 | + |
| 41 | +theorem cast_div_div_div_cancel_right [Field α] [CharZero α] {m n d : ℕ} (hn : d ∣ n) (hm : d ∣ m) : |
| 42 | + (↑(m / d) : α) / (↑(n / d) : α) = (m : α) / n := by |
| 43 | + rcases eq_or_ne d 0 with (rfl | hd); · simp [zero_dvd_iff.mp hm] |
| 44 | + replace hd : (d : α) ≠ 0; |
| 45 | + · norm_cast |
| 46 | + rw [cast_div hm, cast_div hn, div_div_div_cancel_right _ hd] <;> exact hd |
| 47 | + |
| 48 | +#align nat.cast_div_div_div_cancel_right Nat.cast_div_div_div_cancel_right |
| 49 | + |
| 50 | +section LinearOrderedSemifield |
| 51 | + |
| 52 | +variable [LinearOrderedSemifield α] |
| 53 | + |
| 54 | +/-- Natural division is always less than division in the field. -/ |
| 55 | +theorem cast_div_le {m n : ℕ} : ((m / n : ℕ) : α) ≤ m / n := by |
| 56 | + cases n |
| 57 | + · rw [cast_zero, div_zero, Nat.div_zero, cast_zero] |
| 58 | + rw [le_div_iff, ← Nat.cast_mul, @Nat.cast_le] |
| 59 | + exact (Nat.div_mul_le_self m _) |
| 60 | + · exact Nat.cast_pos.2 (Nat.succ_pos _) |
| 61 | +#align nat.cast_div_le Nat.cast_div_le |
| 62 | + |
| 63 | +theorem inv_pos_of_nat {n : ℕ} : 0 < ((n : α) + 1)⁻¹ := |
| 64 | + inv_pos.2 <| add_pos_of_nonneg_of_pos n.cast_nonneg zero_lt_one |
| 65 | +#align nat.inv_pos_of_nat Nat.inv_pos_of_nat |
| 66 | + |
| 67 | +theorem one_div_pos_of_nat {n : ℕ} : 0 < 1 / ((n : α) + 1) := by |
| 68 | + rw [one_div] |
| 69 | + exact inv_pos_of_nat |
| 70 | +#align nat.one_div_pos_of_nat Nat.one_div_pos_of_nat |
| 71 | + |
| 72 | +theorem one_div_le_one_div {n m : ℕ} (h : n ≤ m) : 1 / ((m : α) + 1) ≤ 1 / ((n : α) + 1) := by |
| 73 | + refine' one_div_le_one_div_of_le _ _ |
| 74 | + exact Nat.cast_add_one_pos _ |
| 75 | + simpa |
| 76 | +#align nat.one_div_le_one_div Nat.one_div_le_one_div |
| 77 | + |
| 78 | +theorem one_div_lt_one_div {n m : ℕ} (h : n < m) : 1 / ((m : α) + 1) < 1 / ((n : α) + 1) := by |
| 79 | + refine' one_div_lt_one_div_of_lt _ _ |
| 80 | + exact Nat.cast_add_one_pos _ |
| 81 | + simpa |
| 82 | +#align nat.one_div_lt_one_div Nat.one_div_lt_one_div |
| 83 | + |
| 84 | +end LinearOrderedSemifield |
| 85 | + |
| 86 | +end Nat |
0 commit comments