Skip to content

Commit 0701372

Browse files
author
Salvatore Mercuri
committed
feat: WithAbs type synonym (#17998)
This PR contains the type synonym `WithAbs`. This is a type synonym for a semiring `R` that depends on an absolute value `v : AbsoluteValue R S`, where `S` is an `OrderedSemiring`. This is used in order to handle ambiguities arising from multiple sources of instances. For example, each infinite place on a number field defines distinct uniform structures via their associated real absolute values. The `WithAbs` type synonym allows the type class inferencing system to automatically infer such dependent instances, making it simpler to define the Archimedean completions of a number field. See #16483 for this application along with prior feedback.
1 parent d50eac5 commit 0701372

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ import Mathlib.Algebra.Ring.Subsemiring.Pointwise
817817
import Mathlib.Algebra.Ring.SumsOfSquares
818818
import Mathlib.Algebra.Ring.ULift
819819
import Mathlib.Algebra.Ring.Units
820+
import Mathlib.Algebra.Ring.WithAbs
820821
import Mathlib.Algebra.Ring.WithZero
821822
import Mathlib.Algebra.RingQuot
822823
import Mathlib.Algebra.SMulWithZero

Mathlib/Algebra/Ring/WithAbs.lean

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/-
2+
Copyright (c) 2024 Salvatore Mercuri. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Salvatore Mercuri
5+
-/
6+
import Mathlib.Algebra.Group.Basic
7+
import Mathlib.Algebra.Order.AbsoluteValue
8+
import Mathlib.Analysis.Normed.Field.Basic
9+
10+
/-!
11+
# WithAbs
12+
13+
`WithAbs v` is a type synonym for a semiring `R` which depends on an absolute value. The point of
14+
this is to allow the type class inference system to handle multiple sources of instances that
15+
arise from absolute values. See `NumberTheory.NumberField.Completion` for an example of this
16+
being used to define Archimedean completions of a number field.
17+
18+
## Main definitions
19+
- `WithAbs` : type synonym for a semiring which depends on an absolute value. This is
20+
a function that takes an absolute value on a semiring and returns the semiring. This can be used
21+
to assign and infer instances on a semiring that depend on absolute values.
22+
- `WithAbs.equiv v` : the canonical (type) equivalence between `WithAbs v` and `R`.
23+
- `WithAbs.ringEquiv v` : The canonical ring equivalence between `WithAbs v` and `R`.
24+
-/
25+
noncomputable section
26+
27+
variable {R S K : Type*} [Semiring R] [OrderedSemiring S] [Field K]
28+
29+
/-- Type synonym for a semiring which depends on an absolute value. This is a function that takes
30+
an absolute value on a semiring and returns the semiring. We use this to assign and infer instances
31+
on a semiring that depend on absolute values. -/
32+
@[nolint unusedArguments]
33+
def WithAbs : AbsoluteValue R S → Type _ := fun _ => R
34+
35+
namespace WithAbs
36+
37+
variable (v : AbsoluteValue R ℝ)
38+
39+
/-- Canonical equivalence between `WithAbs v` and `R`. -/
40+
def equiv : WithAbs v ≃ R := Equiv.refl (WithAbs v)
41+
42+
instance instNonTrivial [Nontrivial R] : Nontrivial (WithAbs v) := inferInstanceAs (Nontrivial R)
43+
44+
instance instUnique [Unique R] : Unique (WithAbs v) := inferInstanceAs (Unique R)
45+
46+
instance instSemiring : Semiring (WithAbs v) := inferInstanceAs (Semiring R)
47+
48+
instance instRing [Ring R] : Ring (WithAbs v) := inferInstanceAs (Ring R)
49+
50+
instance instInhabited : Inhabited (WithAbs v) := ⟨0
51+
52+
instance normedRing {R : Type*} [Ring R] (v : AbsoluteValue R ℝ) : NormedRing (WithAbs v) :=
53+
v.toNormedRing
54+
55+
instance normedField (v : AbsoluteValue K ℝ) : NormedField (WithAbs v) :=
56+
v.toNormedField
57+
58+
/-! `WithAbs.equiv` preserves the ring structure. -/
59+
60+
variable (x y : WithAbs v) (r s : R)
61+
@[simp]
62+
theorem equiv_zero : WithAbs.equiv v 0 = 0 := rfl
63+
64+
@[simp]
65+
theorem equiv_symm_zero : (WithAbs.equiv v).symm 0 = 0 := rfl
66+
67+
@[simp]
68+
theorem equiv_add : WithAbs.equiv v (x + y) = WithAbs.equiv v x + WithAbs.equiv v y := rfl
69+
70+
@[simp]
71+
theorem equiv_symm_add :
72+
(WithAbs.equiv v).symm (r + s) = (WithAbs.equiv v).symm r + (WithAbs.equiv v).symm s :=
73+
rfl
74+
75+
@[simp]
76+
theorem equiv_sub [Ring R] : WithAbs.equiv v (x - y) = WithAbs.equiv v x - WithAbs.equiv v y := rfl
77+
78+
@[simp]
79+
theorem equiv_symm_sub [Ring R] :
80+
(WithAbs.equiv v).symm (r - s) = (WithAbs.equiv v).symm r - (WithAbs.equiv v).symm s :=
81+
rfl
82+
83+
@[simp]
84+
theorem equiv_neg [Ring R] : WithAbs.equiv v (-x) = - WithAbs.equiv v x := rfl
85+
86+
@[simp]
87+
theorem equiv_symm_neg [Ring R] : (WithAbs.equiv v).symm (-r) = - (WithAbs.equiv v).symm r := rfl
88+
89+
@[simp]
90+
theorem equiv_mul : WithAbs.equiv v (x * y) = WithAbs.equiv v x * WithAbs.equiv v y := rfl
91+
92+
@[simp]
93+
theorem equiv_symm_mul :
94+
(WithAbs.equiv v).symm (x * y) = (WithAbs.equiv v).symm x * (WithAbs.equiv v).symm y :=
95+
rfl
96+
97+
/-- `WithAbs.equiv` as a ring equivalence. -/
98+
def ringEquiv : WithAbs v ≃+* R := RingEquiv.refl _
99+
100+
end WithAbs

Mathlib/Analysis/Normed/Field/Basic.lean

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ definitions.
1717
1818
Some useful results that relate the topology of the normed field to the discrete topology include:
1919
* `norm_eq_one_iff_ne_zero_of_discrete`
20+
21+
Methods for constructing a normed ring/field instance from a given real absolute value on a
22+
ring/field are given in:
23+
* AbsoluteValue.toNormedRing
24+
* AbsoluteValue.toNormedField
2025
-/
2126

2227
-- Guard against import creep.
@@ -1090,3 +1095,25 @@ instance toNormedCommRing [NormedCommRing R] [SubringClass S R] (s : S) : Normed
10901095
{ SubringClass.toNormedRing s with mul_comm := mul_comm }
10911096

10921097
end SubringClass
1098+
1099+
namespace AbsoluteValue
1100+
1101+
/-- A real absolute value on a ring determines a `NormedRing` structure. -/
1102+
noncomputable def toNormedRing {R : Type*} [Ring R] (v : AbsoluteValue R ℝ) : NormedRing R where
1103+
norm := v
1104+
dist_eq _ _ := rfl
1105+
dist_self x := by simp only [sub_self, MulHom.toFun_eq_coe, AbsoluteValue.coe_toMulHom, map_zero]
1106+
dist_comm := v.map_sub
1107+
dist_triangle := v.sub_le
1108+
edist_dist x y := rfl
1109+
norm_mul x y := (v.map_mul x y).le
1110+
eq_of_dist_eq_zero := by simp only [MulHom.toFun_eq_coe, AbsoluteValue.coe_toMulHom,
1111+
AbsoluteValue.map_sub_eq_zero_iff, imp_self, implies_true]
1112+
1113+
/-- A real absolute value on a field determines a `NormedField` structure. -/
1114+
noncomputable def toNormedField {K : Type*} [Field K] (v : AbsoluteValue K ℝ) : NormedField K where
1115+
toField := inferInstanceAs (Field K)
1116+
__ := v.toNormedRing
1117+
norm_mul' := v.map_mul
1118+
1119+
end AbsoluteValue

0 commit comments

Comments
 (0)