|
| 1 | +/- |
| 2 | +Copyright (c) 2021 Anne Baanen. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Mario Carneiro, Anne Baanen |
| 5 | +-/ |
| 6 | +import algebra.ordered_field |
| 7 | + |
| 8 | +/-! |
| 9 | +# Absolute values |
| 10 | +
|
| 11 | +This file defines a bundled type of absolute values `absolute_value R S`. |
| 12 | +
|
| 13 | +## Main definitions |
| 14 | +
|
| 15 | + * `absolute_value R S` is the type of absolute values on `R` mapping to `S`. |
| 16 | + * `absolute_value.abs` is the "standard" absolute value on `S`, mapping negative `x` to `-x`. |
| 17 | + * `absolute_value.to_monoid_with_zero_hom`: absolute values mapping to a |
| 18 | + linear ordered field preserve `0`, `*` and `1` |
| 19 | + * `is_absolute_value`: a type class stating that `f : β → α` satisfies the axioms of an abs val |
| 20 | +-/ |
| 21 | + |
| 22 | +set_option old_structure_cmd true |
| 23 | + |
| 24 | +/-- `absolute_value R S` is the type of absolute values on `R` mapping to `S`: |
| 25 | +the maps that preserve `*`, are nonnegative, positive definite and satisfy the triangle equality. -/ |
| 26 | +structure absolute_value (R S : Type*) [semiring R] [ordered_semiring S] |
| 27 | + extends mul_hom R S := |
| 28 | +(nonneg' : ∀ x, 0 ≤ to_fun x) |
| 29 | +(eq_zero' : ∀ x, to_fun x = 0 ↔ x = 0) |
| 30 | +(add_le' : ∀ x y, to_fun (x + y) ≤ to_fun x + to_fun y) |
| 31 | + |
| 32 | +namespace absolute_value |
| 33 | + |
| 34 | +attribute [nolint doc_blame] absolute_value.to_mul_hom |
| 35 | + |
| 36 | +initialize_simps_projections absolute_value (to_fun → apply) |
| 37 | + |
| 38 | +section ordered_semiring |
| 39 | + |
| 40 | +variables {R S : Type*} [semiring R] [ordered_semiring S] (abv : absolute_value R S) |
| 41 | + |
| 42 | +instance : has_coe_to_fun (absolute_value R S) := ⟨λ f, R → S, λ f, f.to_fun⟩ |
| 43 | + |
| 44 | +@[simp] lemma coe_to_mul_hom : ⇑abv.to_mul_hom = abv := rfl |
| 45 | + |
| 46 | +protected theorem nonneg (x : R) : 0 ≤ abv x := abv.nonneg' x |
| 47 | +@[simp] protected theorem eq_zero {x : R} : abv x = 0 ↔ x = 0 := abv.eq_zero' x |
| 48 | +protected theorem add_le (x y : R) : abv (x + y) ≤ abv x + abv y := abv.add_le' x y |
| 49 | +@[simp] protected theorem map_mul (x y : R) : abv (x * y) = abv x * abv y := abv.map_mul' x y |
| 50 | + |
| 51 | +protected theorem pos {x : R} (hx : x ≠ 0) : 0 < abv x := |
| 52 | +lt_of_le_of_ne (abv.nonneg x) (ne.symm $ mt abv.eq_zero.mp hx) |
| 53 | + |
| 54 | +@[simp] protected theorem pos_iff {x : R} : 0 < abv x ↔ x ≠ 0 := |
| 55 | +⟨λ h₁, mt abv.eq_zero.mpr h₁.ne', abv.pos⟩ |
| 56 | + |
| 57 | +protected theorem ne_zero {x : R} (hx : x ≠ 0) : abv x ≠ 0 := (abv.pos hx).ne' |
| 58 | + |
| 59 | +@[simp] protected theorem map_zero : abv 0 = 0 := abv.eq_zero.2 rfl |
| 60 | + |
| 61 | +end ordered_semiring |
| 62 | + |
| 63 | +section ordered_ring |
| 64 | + |
| 65 | +variables {R S : Type*} [ring R] [ordered_ring S] (abv : absolute_value R S) |
| 66 | + |
| 67 | +protected lemma sub_le (a b c : R) : abv (a - c) ≤ abv (a - b) + abv (b - c) := |
| 68 | +by simpa [sub_eq_add_neg, add_assoc] using abv.add_le (a - b) (b - c) |
| 69 | + |
| 70 | +protected lemma le_sub (a b : R) : abv a - abv b ≤ abv (a - b) := |
| 71 | +sub_le_iff_le_add.2 $ by simpa using abv.add_le (a - b) b |
| 72 | + |
| 73 | +end ordered_ring |
| 74 | + |
| 75 | +section linear_ordered_ring |
| 76 | + |
| 77 | +variables {R S : Type*} [semiring R] [linear_ordered_ring S] (abv : absolute_value R S) |
| 78 | + |
| 79 | +/-- `absolute_value.abs` is `abs` as a bundled `absolute_value`. -/ |
| 80 | +@[simps] |
| 81 | +protected def abs : absolute_value S S := |
| 82 | +{ to_fun := abs, |
| 83 | + nonneg' := abs_nonneg, |
| 84 | + eq_zero' := λ _, abs_eq_zero, |
| 85 | + add_le' := abs_add, |
| 86 | + map_mul' := abs_mul } |
| 87 | + |
| 88 | +instance : inhabited (absolute_value S S) := ⟨absolute_value.abs⟩ |
| 89 | + |
| 90 | +end linear_ordered_ring |
| 91 | + |
| 92 | +section linear_ordered_field |
| 93 | + |
| 94 | +section semiring |
| 95 | + |
| 96 | +variables {R S : Type*} [semiring R] [linear_ordered_field S] (abv : absolute_value R S) |
| 97 | + |
| 98 | +variables [nontrivial R] |
| 99 | + |
| 100 | +@[simp] protected theorem map_one : abv 1 = 1 := |
| 101 | +(mul_right_inj' $ mt abv.eq_zero.1 one_ne_zero).1 $ |
| 102 | +by rw [← abv.map_mul, mul_one, mul_one] |
| 103 | + |
| 104 | +/-- Absolute values from a nontrivial `R` to a linear ordered field preserve `*`, `0` and `1`. -/ |
| 105 | +def to_monoid_with_zero_hom : monoid_with_zero_hom R S := |
| 106 | +{ to_fun := abv, |
| 107 | + map_zero' := abv.map_zero, |
| 108 | + map_one' := abv.map_one, |
| 109 | + .. abv } |
| 110 | + |
| 111 | +@[simp] lemma coe_to_monoid_with_zero_hom : ⇑abv.to_monoid_with_zero_hom = abv := rfl |
| 112 | + |
| 113 | +/-- Absolute values from a nontrivial `R` to a linear ordered field preserve `*` and `1`. -/ |
| 114 | +def to_monoid_hom : monoid_hom R S := |
| 115 | +{ to_fun := abv, |
| 116 | + map_one' := abv.map_one, |
| 117 | + .. abv } |
| 118 | + |
| 119 | +@[simp] lemma coe_to_monoid_hom : ⇑abv.to_monoid_hom = abv := rfl |
| 120 | + |
| 121 | +@[simp] protected lemma map_pow (a : R) (n : ℕ) : abv (a ^ n) = abv a ^ n := |
| 122 | +abv.to_monoid_hom.map_pow a n |
| 123 | + |
| 124 | +end semiring |
| 125 | + |
| 126 | +section ring |
| 127 | + |
| 128 | +variables {R S : Type*} [ring R] [linear_ordered_field S] (abv : absolute_value R S) |
| 129 | + |
| 130 | +@[simp] protected theorem map_neg (a : R) : abv (-a) = abv a := |
| 131 | +by rw [← mul_self_inj_of_nonneg (abv.nonneg _) (abv.nonneg _), |
| 132 | + ← abv.map_mul]; simp |
| 133 | + |
| 134 | +protected theorem map_sub (a b : R) : abv (a - b) = abv (b - a) := |
| 135 | +by rw [← neg_sub, abv.map_neg] |
| 136 | + |
| 137 | +lemma abs_abv_sub_le_abv_sub (a b : R) : |
| 138 | + abs (abv a - abv b) ≤ abv (a - b) := |
| 139 | +abs_sub_le_iff.2 ⟨abv.le_sub _ _, by rw abv.map_sub; apply abv.le_sub⟩ |
| 140 | + |
| 141 | +end ring |
| 142 | + |
| 143 | +section field |
| 144 | + |
| 145 | +variables {R S : Type*} [field R] [linear_ordered_field S] (abv : absolute_value R S) |
| 146 | + |
| 147 | +@[simp] protected theorem map_inv (a : R) : abv a⁻¹ = (abv a)⁻¹ := |
| 148 | +abv.to_monoid_with_zero_hom.map_inv' a |
| 149 | + |
| 150 | +@[simp] protected theorem map_div (a b : R) : abv (a / b) = abv a / abv b := |
| 151 | +abv.to_monoid_with_zero_hom.map_div a b |
| 152 | + |
| 153 | +end field |
| 154 | + |
| 155 | +end linear_ordered_field |
| 156 | + |
| 157 | +end absolute_value |
| 158 | + |
| 159 | +section is_absolute_value |
| 160 | + |
| 161 | +/-- A function `f` is an absolute value if it is nonnegative, zero only at 0, additive, and |
| 162 | +multiplicative. |
| 163 | +
|
| 164 | +See also the type `absolute_value` which represents a bundled version of absolute values. |
| 165 | +-/ |
| 166 | +class is_absolute_value {S} [ordered_semiring S] |
| 167 | + {R} [semiring R] (f : R → S) : Prop := |
| 168 | +(abv_nonneg [] : ∀ x, 0 ≤ f x) |
| 169 | +(abv_eq_zero [] : ∀ {x}, f x = 0 ↔ x = 0) |
| 170 | +(abv_add [] : ∀ x y, f (x + y) ≤ f x + f y) |
| 171 | +(abv_mul [] : ∀ x y, f (x * y) = f x * f y) |
| 172 | + |
| 173 | +namespace is_absolute_value |
| 174 | + |
| 175 | +section ordered_semiring |
| 176 | + |
| 177 | +variables {S : Type*} [ordered_semiring S] |
| 178 | +variables {R : Type*} [semiring R] (abv : R → S) [is_absolute_value abv] |
| 179 | + |
| 180 | +/-- A bundled absolute value is an absolute value. -/ |
| 181 | +instance absolute_value.is_absolute_value |
| 182 | + (abv : absolute_value R S) : is_absolute_value abv := |
| 183 | +{ abv_nonneg := abv.nonneg, |
| 184 | + abv_eq_zero := λ _, abv.eq_zero, |
| 185 | + abv_add := abv.add_le, |
| 186 | + abv_mul := abv.map_mul } |
| 187 | + |
| 188 | +/-- Convert an unbundled `is_absolute_value` to a bundled `absolute_value`. -/ |
| 189 | +@[simps] |
| 190 | +def to_absolute_value : absolute_value R S := |
| 191 | +{ to_fun := abv, |
| 192 | + add_le' := abv_add abv, |
| 193 | + eq_zero' := λ _, abv_eq_zero abv, |
| 194 | + nonneg' := abv_nonneg abv, |
| 195 | + map_mul' := abv_mul abv } |
| 196 | + |
| 197 | +theorem abv_zero : abv 0 = 0 := (abv_eq_zero abv).2 rfl |
| 198 | + |
| 199 | +theorem abv_pos {a : R} : 0 < abv a ↔ a ≠ 0 := |
| 200 | +by rw [lt_iff_le_and_ne, ne, eq_comm]; simp [abv_eq_zero abv, abv_nonneg abv] |
| 201 | + |
| 202 | +end ordered_semiring |
| 203 | + |
| 204 | +section linear_ordered_ring |
| 205 | + |
| 206 | +variables {S : Type*} [linear_ordered_ring S] |
| 207 | +variables {R : Type*} [semiring R] (abv : R → S) [is_absolute_value abv] |
| 208 | + |
| 209 | +instance abs_is_absolute_value {S} [linear_ordered_ring S] : |
| 210 | + is_absolute_value (abs : S → S) := |
| 211 | +{ abv_nonneg := abs_nonneg, |
| 212 | + abv_eq_zero := λ _, abs_eq_zero, |
| 213 | + abv_add := abs_add, |
| 214 | + abv_mul := abs_mul } |
| 215 | + |
| 216 | +end linear_ordered_ring |
| 217 | + |
| 218 | +section linear_ordered_field |
| 219 | + |
| 220 | +variables {S : Type*} [linear_ordered_field S] |
| 221 | + |
| 222 | +section semiring |
| 223 | +variables {R : Type*} [semiring R] (abv : R → S) [is_absolute_value abv] |
| 224 | + |
| 225 | +theorem abv_one [nontrivial R] : abv 1 = 1 := |
| 226 | +(mul_right_inj' $ mt (abv_eq_zero abv).1 one_ne_zero).1 $ |
| 227 | +by rw [← abv_mul abv, mul_one, mul_one] |
| 228 | + |
| 229 | +/-- `abv` as a `monoid_with_zero_hom`. -/ |
| 230 | +def abv_hom [nontrivial R] : monoid_with_zero_hom R S := |
| 231 | +⟨abv, abv_zero abv, abv_one abv, abv_mul abv⟩ |
| 232 | + |
| 233 | +lemma abv_pow [nontrivial R] (abv : R → S) [is_absolute_value abv] |
| 234 | + (a : R) (n : ℕ) : abv (a ^ n) = abv a ^ n := |
| 235 | +(abv_hom abv).to_monoid_hom.map_pow a n |
| 236 | + |
| 237 | +end semiring |
| 238 | + |
| 239 | +section ring |
| 240 | +variables {R : Type*} [ring R] (abv : R → S) [is_absolute_value abv] |
| 241 | + |
| 242 | +theorem abv_neg (a : R) : abv (-a) = abv a := |
| 243 | +by rw [← mul_self_inj_of_nonneg (abv_nonneg abv _) (abv_nonneg abv _), |
| 244 | +← abv_mul abv, ← abv_mul abv]; simp |
| 245 | + |
| 246 | +theorem abv_sub (a b : R) : abv (a - b) = abv (b - a) := |
| 247 | +by rw [← neg_sub, abv_neg abv] |
| 248 | + |
| 249 | +lemma abv_sub_le (a b c : R) : abv (a - c) ≤ abv (a - b) + abv (b - c) := |
| 250 | +by simpa [sub_eq_add_neg, add_assoc] using abv_add abv (a - b) (b - c) |
| 251 | + |
| 252 | +lemma sub_abv_le_abv_sub (a b : R) : abv a - abv b ≤ abv (a - b) := |
| 253 | +sub_le_iff_le_add.2 $ by simpa using abv_add abv (a - b) b |
| 254 | + |
| 255 | +lemma abs_abv_sub_le_abv_sub (a b : R) : |
| 256 | + abs (abv a - abv b) ≤ abv (a - b) := |
| 257 | +abs_sub_le_iff.2 ⟨sub_abv_le_abv_sub abv _ _, |
| 258 | + by rw abv_sub abv; apply sub_abv_le_abv_sub abv⟩ |
| 259 | +end ring |
| 260 | + |
| 261 | +section field |
| 262 | +variables {R : Type*} [field R] (abv : R → S) [is_absolute_value abv] |
| 263 | + |
| 264 | +theorem abv_inv (a : R) : abv a⁻¹ = (abv a)⁻¹ := |
| 265 | +(abv_hom abv).map_inv' a |
| 266 | + |
| 267 | +theorem abv_div (a b : R) : abv (a / b) = abv a / abv b := |
| 268 | +(abv_hom abv).map_div a b |
| 269 | + |
| 270 | +end field |
| 271 | + |
| 272 | +end linear_ordered_field |
| 273 | + |
| 274 | +end is_absolute_value |
| 275 | + |
| 276 | +end is_absolute_value |
0 commit comments