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

Commit 023a816

Browse files
committed
feat(algebra): define a bundled type of absolute values (#8881)
The type `absolute_value R S` is a bundled version of the typeclass `is_absolute_value R S` defined in `data/real/cau_seq.lean` (why was it defined there?), putting both in one file `algebra/absolute_value.lean`. The lemmas from `is_abs_val` have been copied mostly literally, with weakened assumptions when possible. Maps between the bundled and unbundled versions are also available. We also define `absolute_value.abs` that represents the "standard" absolute value `abs`. The point of this PR is both to modernize absolute values into bundled structures, and to make it easier to extend absolute values to represent "absolute values respecting the Euclidean domain structure", and from there "absolute values that show the class group is finite". Co-authored-by: Anne Baanen <Vierkantor@users.noreply.github.com> Co-authored-by: Vierkantor <vierkantor@vierkantor.com>
1 parent a327851 commit 023a816

File tree

2 files changed

+277
-68
lines changed

2 files changed

+277
-68
lines changed

src/algebra/absolute_value.lean

Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
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

src/data/real/cau_seq.lean

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Copyright (c) 2018 Mario Carneiro. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Mario Carneiro
55
-/
6+
import algebra.absolute_value
67
import algebra.big_operators.order
78

89
/-!
@@ -16,7 +17,6 @@ This is a concrete implementation that is useful for simplicity and computabilit
1617
1718
## Important definitions
1819
19-
* `is_absolute_value`: a type class stating that `f : β → α` satisfies the axioms of an abs val
2020
* `is_cau_seq`: a predicate that says `f : ℕ → β` is Cauchy.
2121
* `cau_seq`: the type of Cauchy sequences valued in type `β` with respect to an absolute value
2222
function `abv`.
@@ -28,73 +28,6 @@ sequence, cauchy, abs val, absolute value
2828

2929
open_locale big_operators
3030

31-
/-- A function `f` is an absolute value if it is nonnegative, zero only at 0, additive, and
32-
multiplicative. -/
33-
class is_absolute_value {α} [linear_ordered_field α]
34-
{β} [ring β] (f : β → α) : Prop :=
35-
(abv_nonneg [] : ∀ x, 0 ≤ f x)
36-
(abv_eq_zero [] : ∀ {x}, f x = 0 ↔ x = 0)
37-
(abv_add [] : ∀ x y, f (x + y) ≤ f x + f y)
38-
(abv_mul [] : ∀ x y, f (x * y) = f x * f y)
39-
40-
namespace is_absolute_value
41-
variables {α : Type*} [linear_ordered_field α]
42-
{β : Type*} [ring β] (abv : β → α) [is_absolute_value abv]
43-
44-
theorem abv_zero : abv 0 = 0 := (abv_eq_zero abv).2 rfl
45-
46-
theorem abv_one [nontrivial β] : abv 1 = 1 :=
47-
(mul_right_inj' $ mt (abv_eq_zero abv).1 one_ne_zero).1 $
48-
by rw [← abv_mul abv, mul_one, mul_one]
49-
50-
theorem abv_pos {a : β} : 0 < abv a ↔ a ≠ 0 :=
51-
by rw [lt_iff_le_and_ne, ne, eq_comm]; simp [abv_eq_zero abv, abv_nonneg abv]
52-
53-
theorem abv_neg (a : β) : abv (-a) = abv a :=
54-
by rw [← mul_self_inj_of_nonneg (abv_nonneg abv _) (abv_nonneg abv _),
55-
← abv_mul abv, ← abv_mul abv]; simp
56-
57-
theorem abv_sub (a b : β) : abv (a - b) = abv (b - a) :=
58-
by rw [← neg_sub, abv_neg abv]
59-
60-
/-- `abv` as a `monoid_with_zero_hom`. -/
61-
def abv_hom [nontrivial β] : monoid_with_zero_hom β α :=
62-
⟨abv, abv_zero abv, abv_one abv, abv_mul abv⟩
63-
64-
theorem abv_inv
65-
{β : Type*} [field β] (abv : β → α) [is_absolute_value abv]
66-
(a : β) : abv a⁻¹ = (abv a)⁻¹ :=
67-
(abv_hom abv).map_inv' a
68-
69-
theorem abv_div
70-
{β : Type*} [field β] (abv : β → α) [is_absolute_value abv]
71-
(a b : β) : abv (a / b) = abv a / abv b :=
72-
(abv_hom abv).map_div a b
73-
74-
lemma abv_sub_le (a b c : β) : abv (a - c) ≤ abv (a - b) + abv (b - c) :=
75-
by simpa [sub_eq_add_neg, add_assoc] using abv_add abv (a - b) (b - c)
76-
77-
lemma sub_abv_le_abv_sub (a b : β) : abv a - abv b ≤ abv (a - b) :=
78-
sub_le_iff_le_add.2 $ by simpa using abv_add abv (a - b) b
79-
80-
lemma abs_abv_sub_le_abv_sub (a b : β) :
81-
abs (abv a - abv b) ≤ abv (a - b) :=
82-
abs_sub_le_iff.2 ⟨sub_abv_le_abv_sub abv _ _,
83-
by rw abv_sub abv; apply sub_abv_le_abv_sub abv⟩
84-
85-
lemma abv_pow [nontrivial β] (abv : β → α) [is_absolute_value abv]
86-
(a : β) (n : ℕ) : abv (a ^ n) = abv a ^ n :=
87-
(abv_hom abv).to_monoid_hom.map_pow a n
88-
89-
end is_absolute_value
90-
91-
instance abs_is_absolute_value {α} [linear_ordered_field α] :
92-
is_absolute_value (abs : α → α) :=
93-
{ abv_nonneg := abs_nonneg,
94-
abv_eq_zero := λ _, abs_eq_zero,
95-
abv_add := abs_add,
96-
abv_mul := abs_mul }
97-
9831
open is_absolute_value
9932

10033
theorem exists_forall_ge_and {α} [linear_order α] {P Q : α → Prop} :

0 commit comments

Comments
 (0)