|
| 1 | +/- |
| 2 | +Copyright (c) 2018 Mario Carneiro. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Mario Carneiro |
| 5 | +
|
| 6 | +Archimedean groups and fields. |
| 7 | +-/ |
| 8 | +import algebra.group_power data.rat data.int.order |
| 9 | + |
| 10 | +local infix ` • `:73 := add_monoid.smul |
| 11 | + |
| 12 | +variables {α : Type*} |
| 13 | + |
| 14 | +class floor_ring (α) extends linear_ordered_ring α := |
| 15 | +(floor : α → ℤ) |
| 16 | +(le_floor : ∀ (z : ℤ) (x : α), z ≤ floor x ↔ (z : α) ≤ x) |
| 17 | + |
| 18 | +instance : floor_ring ℤ := |
| 19 | +{ floor := id, le_floor := by simp, |
| 20 | + ..linear_ordered_comm_ring.to_linear_ordered_ring ℤ } |
| 21 | + |
| 22 | +instance : floor_ring ℚ := |
| 23 | +{ floor := rat.floor, le_floor := @rat.le_floor, |
| 24 | + ..linear_ordered_comm_ring.to_linear_ordered_ring ℚ } |
| 25 | + |
| 26 | +section |
| 27 | +variable [floor_ring α] |
| 28 | + |
| 29 | +def floor : α → ℤ := floor_ring.floor |
| 30 | + |
| 31 | +notation `⌊` x `⌋` := floor x |
| 32 | + |
| 33 | +theorem le_floor : ∀ {z : ℤ} {x : α}, z ≤ ⌊x⌋ ↔ (z : α) ≤ x := |
| 34 | +floor_ring.le_floor |
| 35 | + |
| 36 | +theorem floor_lt {x : α} {z : ℤ} : ⌊x⌋ < z ↔ x < z := |
| 37 | +le_iff_le_iff_lt_iff_lt.1 le_floor |
| 38 | + |
| 39 | +theorem floor_le (x : α) : (⌊x⌋ : α) ≤ x := |
| 40 | +le_floor.1 (le_refl _) |
| 41 | + |
| 42 | +theorem floor_nonneg {x : α} : 0 ≤ ⌊x⌋ ↔ 0 ≤ x := |
| 43 | +by simpa using @le_floor _ _ 0 x |
| 44 | + |
| 45 | +theorem lt_succ_floor (x : α) : x < ⌊x⌋.succ := |
| 46 | +floor_lt.1 $ int.lt_succ_self _ |
| 47 | + |
| 48 | +theorem lt_floor_add_one (x : α) : x < ⌊x⌋ + 1 := |
| 49 | +by simpa [int.succ] using lt_succ_floor x |
| 50 | + |
| 51 | +theorem sub_one_lt_floor (x : α) : x - 1 < ⌊x⌋ := |
| 52 | +sub_lt_iff_lt_add.2 (lt_floor_add_one x) |
| 53 | + |
| 54 | +@[simp] theorem floor_coe (z : ℤ) : ⌊(z:α)⌋ = z := |
| 55 | +eq_of_forall_le_iff $ λ a, by rw [le_floor, int.cast_le] |
| 56 | + |
| 57 | +theorem floor_mono {a b : α} (h : a ≤ b) : ⌊a⌋ ≤ ⌊b⌋ := |
| 58 | +le_floor.2 (le_trans (floor_le _) h) |
| 59 | + |
| 60 | +@[simp] theorem floor_add_int (x : α) (z : ℤ) : ⌊x + z⌋ = ⌊x⌋ + z := |
| 61 | +eq_of_forall_le_iff $ λ a, by rw [le_floor, |
| 62 | + ← sub_le_iff_le_add, ← sub_le_iff_le_add, le_floor, int.cast_sub] |
| 63 | + |
| 64 | +theorem floor_sub_int (x : α) (z : ℤ) : ⌊x - z⌋ = ⌊x⌋ - z := |
| 65 | +eq.trans (by rw [int.cast_neg]; refl) (floor_add_int _ _) |
| 66 | + |
| 67 | +/-- `ceil x` is the smallest integer `z` such that `x ≤ z` -/ |
| 68 | +def ceil (x : α) : ℤ := -⌊-x⌋ |
| 69 | + |
| 70 | +notation `⌈` x `⌉` := ceil x |
| 71 | + |
| 72 | +theorem ceil_le {z : ℤ} {x : α} : ⌈x⌉ ≤ z ↔ x ≤ z := |
| 73 | +by rw [ceil, neg_le, le_floor, int.cast_neg, neg_le_neg_iff] |
| 74 | + |
| 75 | +theorem lt_ceil {x : α} {z : ℤ} : z < ⌈x⌉ ↔ (z:α) < x := |
| 76 | +le_iff_le_iff_lt_iff_lt.1 ceil_le |
| 77 | + |
| 78 | +theorem le_ceil (x : α) : x ≤ ⌈x⌉ := |
| 79 | +ceil_le.1 (le_refl _) |
| 80 | + |
| 81 | +@[simp] theorem ceil_coe (z : ℤ) : ⌈(z:α)⌉ = z := |
| 82 | +by rw [ceil, ← int.cast_neg, floor_coe, neg_neg] |
| 83 | + |
| 84 | +theorem ceil_mono {a b : α} (h : a ≤ b) : ⌈a⌉ ≤ ⌈b⌉ := |
| 85 | +ceil_le.2 (le_trans h (le_ceil _)) |
| 86 | + |
| 87 | +@[simp] theorem ceil_add_int (x : α) (z : ℤ) : ⌈x + z⌉ = ⌈x⌉ + z := |
| 88 | +by rw [ceil, neg_add', floor_sub_int, neg_sub, sub_eq_neg_add]; refl |
| 89 | + |
| 90 | +theorem ceil_sub_int (x : α) (z : ℤ) : ⌈x - z⌉ = ⌈x⌉ - z := |
| 91 | +eq.trans (by rw [int.cast_neg]; refl) (ceil_add_int _ _) |
| 92 | + |
| 93 | +theorem ceil_lt_add_one (x : α) : (⌈x⌉ : α) < x + 1 := |
| 94 | +by rw [← lt_ceil, ← int.cast_one, ceil_add_int]; apply lt_add_one |
| 95 | + |
| 96 | +end |
| 97 | + |
| 98 | +class archimedean (α) [ordered_comm_monoid α] : Prop := |
| 99 | +(arch : ∀ (x : α) {y}, 0 < y → ∃ n, x ≤ y • n) |
| 100 | + |
| 101 | +theorem exists_nat_gt [linear_ordered_semiring α] [archimedean α] |
| 102 | + (x : α) : ∃ n : ℕ, x < n := |
| 103 | +let ⟨n, h⟩ := archimedean.arch x zero_lt_one in |
| 104 | +⟨n+1, lt_of_le_of_lt (by simpa using h) |
| 105 | + (nat.cast_lt.2 (nat.lt_succ_self _))⟩ |
| 106 | + |
| 107 | +section linear_ordered_ring |
| 108 | +variables [linear_ordered_ring α] [archimedean α] |
| 109 | + |
| 110 | +theorem exists_int_gt (x : α) : ∃ n : ℤ, x < n := |
| 111 | +let ⟨n, h⟩ := exists_nat_gt x in ⟨n, by simp [h]⟩ |
| 112 | + |
| 113 | +theorem exists_int_lt (x : α) : ∃ n : ℤ, (n : α) < x := |
| 114 | +let ⟨n, h⟩ := exists_int_gt (-x) in ⟨-n, by simp [neg_lt.1 h]⟩ |
| 115 | + |
| 116 | +theorem exists_floor (x : α) : |
| 117 | + ∃ (fl : ℤ), ∀ (z : ℤ), z ≤ fl ↔ (z : α) ≤ x := |
| 118 | +begin |
| 119 | + have := classical.prop_decidable, |
| 120 | + have : ∃ (ub : ℤ), (ub:α) ≤ x ∧ ∀ (z : ℤ), (z:α) ≤ x → z ≤ ub := |
| 121 | + int.exists_greatest_of_bdd |
| 122 | + (let ⟨n, hn⟩ := exists_int_gt x in ⟨n, λ z h', |
| 123 | + int.cast_le.1 $ le_trans h' $ le_of_lt hn⟩) |
| 124 | + (let ⟨n, hn⟩ := exists_int_lt x in ⟨n, le_of_lt hn⟩), |
| 125 | + refine this.imp (λ fl h z, _), |
| 126 | + cases h with h₁ h₂, |
| 127 | + exact ⟨λ h, le_trans (int.cast_le.2 h) h₁, h₂ z⟩, |
| 128 | +end |
| 129 | + |
| 130 | +end linear_ordered_ring |
| 131 | + |
| 132 | +instance : archimedean ℕ := |
| 133 | +⟨λ n m m0, ⟨n, by simpa using nat.mul_le_mul_right n m0⟩⟩ |
| 134 | + |
| 135 | +instance : archimedean ℤ := |
| 136 | +⟨λ n m m0, ⟨n.to_nat, begin |
| 137 | + simp [add_monoid.smul_eq_mul], |
| 138 | + refine le_trans (int.le_to_nat _) _, |
| 139 | + simpa using mul_le_mul_of_nonneg_right |
| 140 | + (int.add_one_le_iff.2 m0) (int.coe_zero_le n.to_nat), |
| 141 | +end⟩⟩ |
| 142 | + |
| 143 | +noncomputable def archimedean.floor_ring (α) |
| 144 | + [R : linear_ordered_ring α] [archimedean α] : floor_ring α := |
| 145 | +{ floor := λ x, classical.some (exists_floor x), |
| 146 | + le_floor := λ z x, classical.some_spec (exists_floor x) z, |
| 147 | + ..R } |
| 148 | + |
| 149 | +section linear_ordered_field |
| 150 | +variables [linear_ordered_field α] |
| 151 | + |
| 152 | +theorem archimedean_iff_nat_lt : |
| 153 | + archimedean α ↔ ∀ x : α, ∃ n : ℕ, x < n := |
| 154 | +⟨@exists_nat_gt α _, λ H, ⟨λ x y y0, |
| 155 | + (H (x / y)).imp $ λ n h, le_of_lt $ |
| 156 | + by rwa [div_lt_iff y0, ← add_monoid.smul_eq_mul'] at h⟩⟩ |
| 157 | + |
| 158 | +theorem archimedean_iff_nat_le : |
| 159 | + archimedean α ↔ ∀ x : α, ∃ n : ℕ, x ≤ n := |
| 160 | +archimedean_iff_nat_lt.trans |
| 161 | +⟨λ H x, (H x).imp $ λ _, le_of_lt, |
| 162 | + λ H x, let ⟨n, h⟩ := H x in ⟨n+1, |
| 163 | + lt_of_le_of_lt h (nat.cast_lt.2 (lt_add_one _))⟩⟩ |
| 164 | + |
| 165 | +theorem exists_rat_gt [archimedean α] (x : α) : ∃ q : ℚ, x < q := |
| 166 | +let ⟨n, h⟩ := exists_nat_gt x in ⟨n, by simp [h]⟩ |
| 167 | + |
| 168 | +theorem archimedean_iff_rat_lt : |
| 169 | + archimedean α ↔ ∀ x : α, ∃ q : ℚ, x < q := |
| 170 | +⟨@exists_rat_gt α _, |
| 171 | + λ H, archimedean_iff_nat_lt.2 $ λ x, |
| 172 | + let ⟨q, h⟩ := H x in |
| 173 | + ⟨rat.nat_ceil q, lt_of_lt_of_le h $ |
| 174 | + by simpa using (@rat.cast_le α _ _ _).2 (rat.le_nat_ceil _)⟩⟩ |
| 175 | + |
| 176 | +theorem archimedean_iff_rat_le : |
| 177 | + archimedean α ↔ ∀ x : α, ∃ q : ℚ, x ≤ q := |
| 178 | +archimedean_iff_rat_lt.trans |
| 179 | +⟨λ H x, (H x).imp $ λ _, le_of_lt, |
| 180 | + λ H x, let ⟨n, h⟩ := H x in ⟨n+1, |
| 181 | + lt_of_le_of_lt h (rat.cast_lt.2 (lt_add_one _))⟩⟩ |
| 182 | + |
| 183 | +variable [archimedean α] |
| 184 | + |
| 185 | +theorem exists_rat_lt (x : α) : ∃ q : ℚ, (q : α) < x := |
| 186 | +let ⟨n, h⟩ := exists_int_lt x in ⟨n, by simp [h]⟩ |
| 187 | + |
| 188 | +theorem exists_pos_rat_lt {x : α} (x0 : 0 < x) : ∃ q : ℚ, 0 < q ∧ (q : α) < x := |
| 189 | +let ⟨n, h⟩ := exists_nat_gt x⁻¹ in begin |
| 190 | + have n0 := nat.cast_pos.1 (lt_trans (inv_pos x0) h), |
| 191 | + refine ⟨n⁻¹, inv_pos (nat.cast_pos.2 n0), _⟩, |
| 192 | + simpa [rat.cast_inv_of_ne_zero, ne_of_gt n0] using |
| 193 | + (inv_lt x0 (nat.cast_pos.2 n0)).1 h |
| 194 | +end |
| 195 | + |
| 196 | +theorem exists_rat_btwn {x y : α} (h : x < y) : ∃ q : ℚ, x < q ∧ (q:α) < y := |
| 197 | +begin |
| 198 | + cases exists_nat_gt (y - x)⁻¹ with n nh, |
| 199 | + cases exists_floor (x * n) with z zh, |
| 200 | + refine ⟨(z + 1 : ℤ) / n, _⟩, |
| 201 | + have n0 := nat.cast_pos.1 (lt_trans (inv_pos (sub_pos.2 h)) nh), |
| 202 | + simp [rat.cast_div_of_ne_zero, -int.cast_add, ne_of_gt n0], |
| 203 | + have n0' := (@nat.cast_pos α _ _).2 n0, |
| 204 | + refine ⟨(lt_div_iff n0').2 $ |
| 205 | + (le_iff_le_iff_lt_iff_lt.1 (zh _)).1 (lt_add_one _), _⟩, |
| 206 | + simp [div_lt_iff n0', -add_comm], |
| 207 | + refine lt_of_le_of_lt (add_le_add_right ((zh _).1 (le_refl _)) _) _, |
| 208 | + rwa [← lt_sub_iff_add_lt', ← sub_mul, |
| 209 | + ← div_lt_iff' (sub_pos.2 h), one_div_eq_inv] |
| 210 | +end |
| 211 | + |
| 212 | +end linear_ordered_field |
| 213 | + |
| 214 | +section |
| 215 | +variables [discrete_linear_ordered_field α] [archimedean α] |
| 216 | + |
| 217 | +theorem exists_rat_near (x : α) {ε : α} (ε0 : ε > 0) : |
| 218 | + ∃ q : ℚ, abs (x - q) < ε := |
| 219 | +let ⟨q, h₁, h₂⟩ := exists_rat_btwn $ |
| 220 | + lt_trans ((sub_lt_self_iff x).2 ε0) ((lt_add_iff_pos_left x).2 ε0) in |
| 221 | +⟨q, abs_sub_lt_iff.2 ⟨sub_lt.1 h₁, sub_lt_iff_lt_add.2 h₂⟩⟩ |
| 222 | + |
| 223 | +end |
| 224 | + |
| 225 | +instance : archimedean ℚ := |
| 226 | +archimedean_iff_rat_le.2 $ λ q, ⟨q, by simp⟩ |
0 commit comments