-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathBasic.lean
More file actions
446 lines (326 loc) Β· 17.1 KB
/
Basic.lean
File metadata and controls
446 lines (326 loc) Β· 17.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
/-
Copyright (c) 2021 Ashvni Narayanan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ashvni Narayanan, Anne Baanen
-/
module
public import Mathlib.Algebra.Algebra.Rat
public import Mathlib.Algebra.CharZero.AddMonoidHom
public import Mathlib.Algebra.Ring.Int.Parity
public import Mathlib.Algebra.Ring.Int.Units
public import Mathlib.RingTheory.DedekindDomain.IntegralClosure
/-!
# Number fields
This file defines a number field and the ring of integers corresponding to it.
## Main definitions
- `NumberField` defines a number field as a field which has characteristic zero and is finite
dimensional over β.
- `RingOfIntegers` defines the ring of integers (or number ring) corresponding to a number field
as the integral closure of β€ in the number field.
## Implementation notes
The definitions that involve a field of fractions choose a canonical field of fractions,
but are independent of that choice.
## References
* [D. Marcus, *Number Fields*][marcus1977number]
* [J.W.S. Cassels, A. FrΓΆhlich, *Algebraic Number Theory*][cassels1967algebraic]
* [P. Samuel, *Algebraic Theory of Numbers*][samuel1967]
## Tags
number field, ring of integers
-/
@[expose] public section
/-- A number field is a field which has characteristic zero and is finite
dimensional over β. -/
@[stacks 09GA]
class NumberField (K : Type*) [Field K] : Prop where
[to_charZero : CharZero K]
[to_finiteDimensional : FiniteDimensional β K]
open Function Module
open scoped nonZeroDivisors
/-- `β€` with its usual ring structure is not a field. -/
theorem Int.not_isField : Β¬IsField β€ := fun h =>
Int.not_even_one <|
(h.mul_inv_cancel two_ne_zero).imp fun a => by rw [β two_mul]; exact Eq.symm
namespace NumberField
variable (K L : Type*) [Field K] [Field L]
-- See note [lower instance priority]
attribute [instance] NumberField.to_charZero NumberField.to_finiteDimensional
protected theorem isAlgebraic [NumberField K] : Algebra.IsAlgebraic β K :=
Algebra.IsAlgebraic.of_finite _ _
instance [NumberField K] [NumberField L] [Algebra K L] : FiniteDimensional K L :=
Module.Finite.of_restrictScalars_finite β K L
/-- A finite extension of a number field is a number field. -/
theorem of_module_finite [NumberField K] [Algebra K L] [Module.Finite K L] : NumberField L where
to_charZero := charZero_of_injective_algebraMap (algebraMap K L).injective
to_finiteDimensional :=
letI := charZero_of_injective_algebraMap (algebraMap K L).injective
Module.Finite.trans K L
variable {K} {L} in
instance of_intermediateField [NumberField K] [NumberField L] [Algebra K L]
(E : IntermediateField K L) : NumberField E :=
of_module_finite K E
variable {K} in
instance of_subfield [NumberField K] (E : Subfield K) : NumberField E where
to_finiteDimensional := FiniteDimensional.left β E K
theorem of_tower [NumberField K] [NumberField L] [Algebra K L] (E : Type*) [Field E]
[Algebra K E] [Algebra E L] [IsScalarTower K E L] : NumberField E :=
letI := Module.Finite.left K E L
of_module_finite K E
theorem of_ringEquiv (e : K β+* L) [NumberField K] : NumberField L :=
letI := CharZero.of_addMonoidHom e.toAddMonoidHom (by simp) e.injective
{
to_charZero := inferInstance
to_finiteDimensional := (e : K ββ[β] L).finiteDimensional
}
/-- The ring of integers (or number ring) corresponding to a number field
is the integral closure of β€ in the number field.
This is defined as its own type, rather than a `Subalgebra`, for performance reasons:
looking for instances of the form `SMul (RingOfIntegers _) (RingOfIntegers _)` makes
much more effective use of the discrimination tree than instances of the form
`SMul (Subtype _) (Subtype _)`.
The drawback is we have to copy over instances manually.
-/
def RingOfIntegers : Type _ :=
integralClosure β€ K
deriving CommRing, IsDomain, Nontrivial
@[inherit_doc] scoped notation "π" => NumberField.RingOfIntegers
namespace RingOfIntegers
instance [NumberField K] : CharZero (π K) :=
inferInstanceAs (CharZero (integralClosure _ _))
instance {L : Type*} [Ring L] [Algebra K L] : Algebra (π K) L :=
inferInstanceAs (Algebra (integralClosure _ _) L)
instance : Algebra (π K) K := inferInstanceAs _
instance : IsTorsionFree (π K) K :=
inferInstanceAs (IsTorsionFree (integralClosure _ _) _)
instance {L : Type*} [Ring L] [Algebra K L] : IsScalarTower (π K) K L :=
inferInstanceAs (IsScalarTower (integralClosure _ _) K L)
instance {G : Type*} [Group G] [MulSemiringAction G K] : MulSemiringAction G (π K) :=
inferInstanceAs (MulSemiringAction G (integralClosure β€ K))
instance {G : Type*} [Group G] [MulSemiringAction G K] : SMulDistribClass G (π K) K :=
inferInstanceAs (SMulDistribClass G (integralClosure β€ K) K)
-- verify that the two algebra instances agree
example : instAlgebra (L := K) (K := K) = instAlgebra_1 (K := K) := by
with_reducible_and_instances rfl
variable {K}
/-- The canonical coercion from `π K` to `K`. -/
@[coe]
abbrev val (x : π K) : K := algebraMap _ _ x
/-- This instance has to be `CoeHead` because we only want to apply it from `π K` to `K`. -/
instance : CoeHead (π K) K := β¨valβ©
lemma coe_eq_algebraMap (x : π K) : (x : K) = algebraMap _ _ x := rfl
@[ext] theorem ext {x y : π K} (h : (x : K) = (y : K)) : x = y :=
Subtype.ext h
@[norm_cast]
theorem eq_iff {x y : π K} : (x : K) = (y : K) β x = y :=
NumberField.RingOfIntegers.ext_iff.symm
@[simp] lemma map_mk (x : K) (hx) : algebraMap (π K) K β¨x, hxβ© = x := rfl
lemma coe_mk {x : K} (hx) : ((β¨x, hxβ© : π K) : K) = x := rfl
lemma mk_eq_mk (x y : K) (hx hy) : (β¨x, hxβ© : π K) = β¨y, hyβ© β x = y := by simp
@[simp] lemma mk_one : (β¨1, one_mem _β© : π K) = 1 :=
rfl
@[simp] lemma mk_zero : (β¨0, zero_mem _β© : π K) = 0 :=
rfl
-- TODO: these lemmas don't seem to fire?
@[simp] lemma mk_add_mk (x y : K) (hx hy) : (β¨x, hxβ© : π K) + β¨y, hyβ© = β¨x + y, add_mem hx hyβ© :=
rfl
@[simp] lemma mk_mul_mk (x y : K) (hx hy) : (β¨x, hxβ© : π K) * β¨y, hyβ© = β¨x * y, mul_mem hx hyβ© :=
rfl
@[simp] lemma mk_sub_mk (x y : K) (hx hy) : (β¨x, hxβ© : π K) - β¨y, hyβ© = β¨x - y, sub_mem hx hyβ© :=
rfl
@[simp] lemma neg_mk (x : K) (hx) : (-β¨x, hxβ© : π K) = β¨-x, neg_mem hxβ© :=
rfl
/-- The ring homomorphism `(π K) β+* (π L)` given by restricting a ring homomorphism
`f : K β+* L` to `π K`. -/
def mapRingHom {K L : Type*} [Field K] [Field L] (f : K β+* L) : (π K) β+* (π L) :=
f.toIntAlgHom.mapIntegralClosure.toRingHom
@[simp]
theorem mapRingHom_apply {K L : Type*} [Field K] [Field L] (f : K β+* L) (x : π K) :
(mapRingHom f x : L) = f (x : K) := rfl
/-- The ring isomorphism `(π K) β+* (π L)` given by restricting
a ring isomorphism `e : K β+* L` to `π K`. -/
def mapRingEquiv {K L : Type*} [Field K] [Field L] (e : K β+* L) : (π K) β+* (π L) :=
RingEquiv.ofRingHom (mapRingHom e) (mapRingHom e.symm)
(RingHom.ext fun x => ext (EquivLike.right_inv e x.1))
(RingHom.ext fun x => ext (EquivLike.left_inv e x.1))
@[simp]
theorem mapRingEquiv_apply {K L : Type*} [Field K] [Field L] (e : K β+* L) (x : π K) :
(mapRingEquiv e x : L) = e (x : K) := rfl
@[simp]
theorem mapRingEquiv_symm_apply {K L : Type*} [Field K] [Field L] (e : K β+* L) (x : π L) :
((mapRingEquiv e).symm x : K) = e.symm (x : L) := rfl
end RingOfIntegers
/-- Given an algebra structure between two fields, this instance creates an algebra structure
between their two rings of integers. -/
instance inst_ringOfIntegersAlgebra [Algebra K L] : Algebra (π K) (π L) :=
(RingOfIntegers.mapRingHom (algebraMap K L)).toAlgebra
-- diamond at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906
example : Algebra.id (π K) = inst_ringOfIntegersAlgebra K K := rfl
namespace RingOfIntegers
/-- The algebra homomorphism `(π K) ββ[π k] (π L)` given by restricting an algebra homomorphism
`f : K ββ[k] L` to `π K`. -/
def mapAlgHom {k K L F : Type*} [Field k] [Field K] [Field L] [Algebra k K]
[Algebra k L] [FunLike F K L] [AlgHomClass F k K L] (f : F) : (π K) ββ[π k] (π L) where
toRingHom := mapRingHom f
commutes' x := SetCoe.ext (AlgHomClass.commutes ((f : K ββ[k] L).restrictScalars (π k)) x)
/-- The isomorphism of algebras `(π K) ββ[π k] (π L)` given by restricting
an isomorphism of algebras `e : K ββ[k] L` to `π K`. -/
def mapAlgEquiv {k K L E : Type*} [Field k] [Field K] [Field L] [Algebra k K]
[Algebra k L] [EquivLike E K L] [AlgEquivClass E k K L] (e : E) : (π K) ββ[π k] (π L) :=
AlgEquiv.ofAlgHom (mapAlgHom e) (mapAlgHom (AlgEquivClass.toAlgEquiv e : K ββ[k] L).symm)
(AlgHom.ext fun x => ext (EquivLike.right_inv e x.1))
(AlgHom.ext fun x => ext (EquivLike.left_inv e x.1))
instance inst_isScalarTower (k K L : Type*) [Field k] [Field K] [Field L]
[Algebra k K] [Algebra k L] [Algebra K L] [IsScalarTower k K L] :
IsScalarTower (π k) (π K) (π L) :=
IsScalarTower.of_algHom (mapAlgHom (IsScalarTower.toAlgHom k K L))
variable {K}
/-- The canonical map from `π K` to `K` is injective.
This is a convenient abbreviation for `FaithfulSMul.algebraMap_injective`.
-/
lemma coe_injective : Function.Injective (algebraMap (π K) K) :=
FaithfulSMul.algebraMap_injective _ _
/-- The canonical map from `π K` to `K` is injective.
This is a convenient abbreviation for `map_eq_zero_iff` applied to
`FaithfulSMul.algebraMap_injective`.
-/
lemma coe_eq_zero_iff {x : π K} : algebraMap _ K x = 0 β x = 0 :=
map_eq_zero_iff _ coe_injective
/-- The canonical map from `π K` to `K` is injective.
This is a convenient abbreviation for `map_ne_zero_iff` applied to
`FaithfulSMul.algebraMap_injective`.
-/
lemma coe_ne_zero_iff {x : π K} : algebraMap _ K x β 0 β x β 0 :=
map_ne_zero_iff _ coe_injective
theorem minpoly_coe (x : π K) :
minpoly β€ (x : K) = minpoly β€ x :=
minpoly.algebraMap_eq RingOfIntegers.coe_injective x
theorem isIntegral_coe (x : π K) : IsIntegral β€ (algebraMap _ K x) :=
x.2
theorem isIntegral (x : π K) : IsIntegral β€ x := by
obtain β¨P, hPm, hPβ© := x.isIntegral_coe
refine β¨P, hPm, ?_β©
rwa [IsScalarTower.algebraMap_eq (S := π K), β Polynomial.hom_evalβ, coe_eq_zero_iff] at hP
instance [NumberField K] : IsFractionRing (π K) K :=
integralClosure.isFractionRing_of_finite_extension β _
instance : IsIntegralClosure (π K) β€ K :=
integralClosure.isIntegralClosure _ _
instance : Algebra.IsIntegral β€ (π K) :=
IsIntegralClosure.isIntegral_algebra β€ K
instance [NumberField K] : IsIntegrallyClosed (π K) :=
integralClosure.isIntegrallyClosedOfFiniteExtension β
/-- The ring of integers of `K` are equivalent to any integral closure of `β€` in `K` -/
protected noncomputable def equiv (R : Type*) [CommRing R] [Algebra R K]
[IsIntegralClosure R β€ K] : π K β+* R :=
(IsIntegralClosure.equiv β€ R K _).symm.toRingEquiv
variable (K)
instance [CharZero K] : CharZero (π K) := .of_module K
variable [NumberField K]
instance : IsNoetherian β€ (π K) :=
IsIntegralClosure.isNoetherian _ β K _
instance : AddGroup.FG (π K) :=
Finite.iff_addGroup_fg.mp <| IsNoetherian.finite β€ (π K)
/-- The ring of integers of a number field is not a field. -/
theorem not_isField : Β¬IsField (π K) := by
have h_inj : Function.Injective (algebraMap β€ (π K)) := RingHom.injective_int (algebraMap β€ (π K))
intro hf
exact Int.not_isField
(((IsIntegralClosure.isIntegral_algebra β€ K).isField_iff_isField h_inj).mpr hf)
instance {I : Ideal (π K)} [hI : I.IsMaximal] : NeZero I :=
β¨Ring.ne_bot_of_isMaximal_of_not_isField hI <| RingOfIntegers.not_isField Kβ©
instance : IsDedekindDomain (π K) :=
IsIntegralClosure.isDedekindDomain β€ β K _
instance : Free β€ (π K) :=
IsIntegralClosure.module_free β€ β K (π K)
instance : IsLocalization (Algebra.algebraMapSubmonoid (π K) β€β°) K :=
IsIntegralClosure.isLocalization_of_isSeparable β€ β K (π K)
/-- A β€-basis of the ring of integers of `K`. -/
noncomputable def basis : Basis (Free.ChooseBasisIndex β€ (π K)) β€ (π K) :=
Free.chooseBasis β€ (π K)
variable {K} {M : Type*}
/-- Given `f : M β K` such that `β x, IsIntegral β€ (f x)`, the corresponding function
`M β π K`. -/
def restrict (f : M β K) (h : β x, IsIntegral β€ (f x)) (x : M) : π K :=
β¨f x, h xβ©
/-- Given `f : M β+ K` such that `β x, IsIntegral β€ (f x)`, the corresponding function
`M β+ π K`. -/
def restrict_addMonoidHom [AddZeroClass M] (f : M β+ K) (h : β x, IsIntegral β€ (f x)) :
M β+ π K where
toFun := restrict f h
map_zero' := by simp only [restrict, map_zero]; rfl
map_add' x y := by simp only [restrict, map_add]; rfl
/-- Given `f : M β* K` such that `β x, IsIntegral β€ (f x)`, the corresponding function
`M β* π K`. -/
def restrict_monoidHom [MulOneClass M] (f : M β* K) (h : β x, IsIntegral β€ (f x)) : M β* π K where
toFun := restrict f h
map_one' := by simp only [restrict, map_one]; rfl
map_mul' x y := by simp only [restrict, map_mul]; rfl
section extension
variable (K L : Type*) [Field K] [Field L] [Algebra K L]
instance : IsScalarTower (π K) (π L) L :=
IsScalarTower.of_algebraMap_eq' rfl
instance : IsIntegralClosure (π L) (π K) L :=
IsIntegralClosure.tower_top (R := β€)
/-- The ring of integers of `L` is isomorphic to any integral closure of `π K` in `L` -/
protected noncomputable def algEquiv (R : Type*) [CommRing R] [Algebra (π K) R] [Algebra R L]
[IsScalarTower (π K) R L] [IsIntegralClosure R (π K) L] : π L ββ[π K] R :=
(IsIntegralClosure.equiv (π K) R L _).symm
/-- Any extension between ring of integers is integral. -/
instance extension_algebra_isIntegral : Algebra.IsIntegral (π K) (π L) :=
IsIntegralClosure.isIntegral_algebra (π K) L
/-- Any extension between ring of integers of number fields is Noetherian. -/
instance extension_isNoetherian [NumberField K] [NumberField L] : IsNoetherian (π K) (π L) :=
IsIntegralClosure.isNoetherian (π K) K L (π L)
/-- The kernel of the algebraMap between ring of integers is `β₯`. -/
theorem ker_algebraMap_eq_bot : RingHom.ker (algebraMap (π K) (π L)) = β₯ :=
(RingHom.ker_eq_bot_iff_eq_zero (algebraMap (π K) (π L))).mpr <| fun x hx => by
have h : (algebraMap K L) x = (algebraMap (π K) (π L)) x := rfl
simp only [hx, map_zero, map_eq_zero, RingOfIntegers.coe_eq_zero_iff] at h
exact h
/-- The algebraMap between ring of integers is injective. -/
theorem algebraMap.injective : Function.Injective (algebraMap (π K) (π L)) :=
(RingHom.injective_iff_ker_eq_bot (algebraMap (π K) (π L))).mpr (ker_algebraMap_eq_bot K L)
instance : IsTorsionFree (π K) (π L) :=
isTorsionFree_iff_algebraMap_injective.mpr <| algebraMap.injective K L
instance : IsTorsionFree (π K) L := .trans_faithfulSMul (π K) (π L) L
end extension
end RingOfIntegers
variable [NumberField K]
/-- A basis of `K` over `β` that is also a basis of `π K` over `β€`. -/
noncomputable def integralBasis : Basis (Free.ChooseBasisIndex β€ (π K)) β K :=
Basis.localizationLocalization β (nonZeroDivisors β€) K (RingOfIntegers.basis K)
@[simp]
theorem integralBasis_apply (i : Free.ChooseBasisIndex β€ (π K)) :
integralBasis K i = algebraMap (π K) K (RingOfIntegers.basis K i) :=
Basis.localizationLocalization_apply β (nonZeroDivisors β€) K (RingOfIntegers.basis K) i
@[simp]
theorem integralBasis_repr_apply (x : (π K)) (i : Free.ChooseBasisIndex β€ (π K)) :
(integralBasis K).repr (algebraMap _ _ x) i =
(algebraMap β€ β) ((RingOfIntegers.basis K).repr x i) :=
Basis.localizationLocalization_repr_algebraMap β (nonZeroDivisors β€) K _ x i
theorem mem_span_integralBasis {x : K} :
x β Submodule.span β€ (Set.range (integralBasis K)) β x β (algebraMap (π K) K).range := by
simp [integralBasis, Basis.localizationLocalization_span]
theorem RingOfIntegers.rank : Module.finrank β€ (π K) = Module.finrank β K :=
IsIntegralClosure.rank β€ β K (π K)
end NumberField
namespace Rat
open NumberField
instance numberField : NumberField β where
/-- The ring of integers of `β` as a number field is just `β€`. -/
noncomputable def ringOfIntegersEquiv : π β β+* β€ :=
RingOfIntegers.equiv β€
@[simp]
theorem ringOfIntegersEquiv_apply_coe (z : π β) :
(Rat.ringOfIntegersEquiv z : β) = algebraMap (π β) β z := by
obtain β¨z, rflβ© := Rat.ringOfIntegersEquiv.symm.surjective z
simp
theorem ringOfIntegersEquiv_symm_apply_coe (x : β€) :
(ringOfIntegersEquiv.symm x : β) = βx :=
eq_intCast ringOfIntegersEquiv.symm _ βΈ rfl
end Rat
namespace AdjoinRoot
/-- The quotient of `β[X]` by the ideal generated by an irreducible polynomial of `β[X]`
is a number field. -/
instance {f : Polynomial β} [hf : Fact (Irreducible f)] : NumberField (AdjoinRoot f) where
to_charZero := charZero_of_injective_algebraMap (algebraMap β _).injective
to_finiteDimensional := by convert (AdjoinRoot.powerBasis hf.out.ne_zero).finite
end AdjoinRoot