/
localization.lean
2595 lines (2120 loc) · 104 KB
/
localization.lean
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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston
-/
import data.equiv.ring
import group_theory.monoid_localization
import ring_theory.algebraic
import ring_theory.ideal.local_ring
import ring_theory.ideal.quotient
import ring_theory.integral_closure
import ring_theory.non_zero_divisors
import group_theory.submonoid.inverses
import tactic.ring_exp
/-!
# Localizations of commutative rings
We characterize the localization of a commutative ring `R` at a submonoid `M` up to
isomorphism; that is, a commutative ring `S` is the localization of `R` at `M` iff we can find a
ring homomorphism `f : R →+* S` satisfying 3 properties:
1. For all `y ∈ M`, `f y` is a unit;
2. For all `z : S`, there exists `(x, y) : R × M` such that `z * f y = f x`;
3. For all `x, y : R`, `f x = f y` iff there exists `c ∈ M` such that `x * c = y * c`.
In the following, let `R, P` be commutative rings, `S, Q` be `R`- and `P`-algebras
and `M, T` be submonoids of `R` and `P` respectively, e.g.:
```
variables (R S P Q : Type*) [comm_ring R] [comm_ring S] [comm_ring P] [comm_ring Q]
variables [algebra R S] [algebra P Q] (M : submonoid R) (T : submonoid P)
```
## Main definitions
* `is_localization (M : submonoid R) (S : Type*)` is a typeclass expressing that `S` is a
localization of `R` at `M`, i.e. the canonical map `algebra_map R S : R →+* S` is a
localization map (satisfying the above properties).
* `is_localization.mk' S` is a surjection sending `(x, y) : R × M` to `f x * (f y)⁻¹`
* `is_localization.lift` is the ring homomorphism from `S` induced by a homomorphism from `R`
which maps elements of `M` to invertible elements of the codomain.
* `is_localization.map S Q` is the ring homomorphism from `S` to `Q` which maps elements
of `M` to elements of `T`
* `is_localization.ring_equiv_of_ring_equiv`: if `R` and `P` are isomorphic by an isomorphism
sending `M` to `T`, then `S` and `Q` are isomorphic
* `is_localization.alg_equiv`: if `Q` is another localization of `R` at `M`, then `S` and `Q`
are isomorphic as `R`-algebras
* `is_localization.is_integer` is a predicate stating that `x : S` is in the image of `R`
* `is_localization.away (x : R) S` expresses that `S` is a localization away from `x`, as an
abbreviation of `is_localization (submonoid.powers x) S`
* `is_localization.at_prime (I : ideal R) [is_prime I] (S : Type*)` expresses that `S` is a
localization at (the complement of) a prime ideal `I`, as an abbreviation of
`is_localization I.prime_compl S`
* `is_fraction_ring R K` expresses that `K` is a field of fractions of `R`, as an abbreviation of
`is_localization (non_zero_divisors R) K`
## Main results
* `localization M S`, a construction of the localization as a quotient type, defined in
`group_theory.monoid_localization`, has `comm_ring`, `algebra R` and `is_localization M`
instances if `R` is a ring. `localization.away`, `localization.at_prime` and `fraction_ring`
are abbreviations for `localization`s and have their corresponding `is_localization` instances
* `is_localization.at_prime.local_ring`: a theorem (not an instance) stating a localization at the
complement of a prime ideal is a local ring
* `is_fraction_ring.field`: a definition (not an instance) stating the localization of an integral
domain `R` at `R \ {0}` is a field
* `rat.is_fraction_ring` is an instance stating `ℚ` is the field of fractions of `ℤ`
## Implementation notes
In maths it is natural to reason up to isomorphism, but in Lean we cannot naturally `rewrite` one
structure with an isomorphic one; one way around this is to isolate a predicate characterizing
a structure up to isomorphism, and reason about things that satisfy the predicate.
A previous version of this file used a fully bundled type of ring localization maps,
then used a type synonym `f.codomain` for `f : localization_map M S` to instantiate the
`R`-algebra structure on `S`. This results in defining ad-hoc copies for everything already
defined on `S`. By making `is_localization` a predicate on the `algebra_map R S`,
we can ensure the localization map commutes nicely with other `algebra_map`s.
To prove most lemmas about a localization map `algebra_map R S` in this file we invoke the
corresponding proof for the underlying `comm_monoid` localization map
`is_localization.to_localization_map M S`, which can be found in `group_theory.monoid_localization`
and the namespace `submonoid.localization_map`.
To reason about the localization as a quotient type, use `mk_eq_of_mk'` and associated lemmas.
These show the quotient map `mk : R → M → localization M` equals the surjection
`localization_map.mk'` induced by the map `algebra_map : R →+* localization M`.
The lemma `mk_eq_of_mk'` hence gives you access to the results in the rest of the file,
which are about the `localization_map.mk'` induced by any localization map.
The proof that "a `comm_ring` `K` which is the localization of an integral domain `R` at `R \ {0}`
is a field" is a `def` rather than an `instance`, so if you want to reason about a field of
fractions `K`, assume `[field K]` instead of just `[comm_ring K]`.
## Tags
localization, ring localization, commutative ring localization, characteristic predicate,
commutative ring, field of fractions
-/
variables {R : Type*} [comm_ring R] (M : submonoid R) (S : Type*) [comm_ring S]
variables [algebra R S] {P : Type*} [comm_ring P]
open function
open_locale big_operators
/-- The typeclass `is_localization (M : submodule R) S` where `S` is an `R`-algebra
expresses that `S` is isomorphic to the localization of `R` at `M`. -/
class is_localization : Prop :=
(map_units [] : ∀ y : M, is_unit (algebra_map R S y))
(surj [] : ∀ z : S, ∃ x : R × M, z * algebra_map R S x.2 = algebra_map R S x.1)
(eq_iff_exists [] : ∀ {x y}, algebra_map R S x = algebra_map R S y ↔ ∃ c : M, x * c = y * c)
variables {M S}
namespace is_localization
section is_localization
variables [is_localization M S]
section
variables (M)
lemma of_le (N : submonoid R) (h₁ : M ≤ N)
(h₂ : ∀ r ∈ N, is_unit (algebra_map R S r)) : is_localization N S :=
{ map_units := λ r, h₂ r r.2,
surj := λ s, by { obtain ⟨⟨x, y, hy⟩, H⟩ := is_localization.surj M s, exact ⟨⟨x, y, h₁ hy⟩, H⟩ },
eq_iff_exists := λ x y, begin
split,
{ rw is_localization.eq_iff_exists M,
rintro ⟨c, hc⟩,
exact ⟨⟨c, h₁ c.2⟩, hc⟩ },
{ rintro ⟨c, h⟩,
simpa only [set_like.coe_mk, map_mul, (h₂ c c.2).mul_left_inj] using
congr_arg (algebra_map R S) h }
end }
variables (S)
/-- `is_localization.to_localization_map M S` shows `S` is the monoid localization of `R` at `M`. -/
@[simps]
def to_localization_map : submonoid.localization_map M S :=
{ to_fun := algebra_map R S,
map_units' := is_localization.map_units _,
surj' := is_localization.surj _,
eq_iff_exists' := λ _ _, is_localization.eq_iff_exists _ _,
.. algebra_map R S }
@[simp]
lemma to_localization_map_to_map :
(to_localization_map M S).to_map = (algebra_map R S : R →* S) := rfl
lemma to_localization_map_to_map_apply (x) :
(to_localization_map M S).to_map x = algebra_map R S x := rfl
end
section
variables (R)
-- TODO: define a subalgebra of `is_integer`s
/-- Given `a : S`, `S` a localization of `R`, `is_integer R a` iff `a` is in the image of
the localization map from `R` to `S`. -/
def is_integer (a : S) : Prop := a ∈ (algebra_map R S).range
end
lemma is_integer_zero : is_integer R (0 : S) := subring.zero_mem _
lemma is_integer_one : is_integer R (1 : S) := subring.one_mem _
lemma is_integer_add {a b : S} (ha : is_integer R a) (hb : is_integer R b) :
is_integer R (a + b) :=
subring.add_mem _ ha hb
lemma is_integer_mul {a b : S} (ha : is_integer R a) (hb : is_integer R b) :
is_integer R (a * b) :=
subring.mul_mem _ ha hb
lemma is_integer_smul {a : R} {b : S} (hb : is_integer R b) :
is_integer R (a • b) :=
begin
rcases hb with ⟨b', hb⟩,
use a * b',
rw [←hb, (algebra_map R S).map_mul, algebra.smul_def]
end
variables (M)
/-- Each element `a : S` has an `M`-multiple which is an integer.
This version multiplies `a` on the right, matching the argument order in `localization_map.surj`.
-/
lemma exists_integer_multiple' (a : S) :
∃ (b : M), is_integer R (a * algebra_map R S b) :=
let ⟨⟨num, denom⟩, h⟩ := is_localization.surj _ a in ⟨denom, set.mem_range.mpr ⟨num, h.symm⟩⟩
/-- Each element `a : S` has an `M`-multiple which is an integer.
This version multiplies `a` on the left, matching the argument order in the `has_scalar` instance.
-/
lemma exists_integer_multiple (a : S) :
∃ (b : M), is_integer R ((b : R) • a) :=
by { simp_rw [algebra.smul_def, mul_comm _ a], apply exists_integer_multiple' }
/-- Given a localization map `f : M →* N`, a section function sending `z : N` to some
`(x, y) : M × S` such that `f x * (f y)⁻¹ = z`. -/
noncomputable def sec (z : S) : R × M :=
classical.some $ is_localization.surj _ z
@[simp] lemma to_localization_map_sec : (to_localization_map M S).sec = sec M := rfl
/-- Given `z : S`, `is_localization.sec M z` is defined to be a pair `(x, y) : R × M` such
that `z * f y = f x` (so this lemma is true by definition). -/
lemma sec_spec (z : S) :
z * algebra_map R S (is_localization.sec M z).2 =
algebra_map R S (is_localization.sec M z).1 :=
classical.some_spec $ is_localization.surj _ z
/-- Given `z : S`, `is_localization.sec M z` is defined to be a pair `(x, y) : R × M` such
that `z * f y = f x`, so this lemma is just an application of `S`'s commutativity. -/
lemma sec_spec' (z : S) :
algebra_map R S (is_localization.sec M z).1 =
algebra_map R S (is_localization.sec M z).2 * z :=
by rw [mul_comm, sec_spec]
open_locale big_operators
/-- We can clear the denominators of a `finset`-indexed family of fractions. -/
lemma exist_integer_multiples {ι : Type*} (s : finset ι) (f : ι → S) :
∃ (b : M), ∀ i ∈ s, is_localization.is_integer R ((b : R) • f i) :=
begin
haveI := classical.prop_decidable,
refine ⟨∏ i in s, (sec M (f i)).2, λ i hi, ⟨_, _⟩⟩,
{ exact (∏ j in s.erase i, (sec M (f j)).2) * (sec M (f i)).1 },
rw [ring_hom.map_mul, sec_spec', ←mul_assoc, ←(algebra_map R S).map_mul, ← algebra.smul_def],
congr' 2,
refine trans _ ((submonoid.subtype M).map_prod _ _).symm,
rw [mul_comm, ←finset.prod_insert (s.not_mem_erase i), finset.insert_erase hi],
refl
end
/-- We can clear the denominators of a `fintype`-indexed family of fractions. -/
lemma exist_integer_multiples_of_fintype {ι : Type*} [fintype ι] (f : ι → S) :
∃ (b : M), ∀ i, is_localization.is_integer R ((b : R) • f i) :=
begin
obtain ⟨b, hb⟩ := exist_integer_multiples M finset.univ f,
exact ⟨b, λ i, hb i (finset.mem_univ _)⟩
end
/-- We can clear the denominators of a finite set of fractions. -/
lemma exist_integer_multiples_of_finset (s : finset S) :
∃ (b : M), ∀ a ∈ s, is_integer R ((b : R) • a) :=
exist_integer_multiples M s id
/-- A choice of a common multiple of the denominators of a `finset`-indexed family of fractions. -/
noncomputable
def common_denom {ι : Type*} (s : finset ι) (f : ι → S) : M :=
(exist_integer_multiples M s f).some
/-- The numerator of a fraction after clearing the denominators
of a `finset`-indexed family of fractions. -/
noncomputable
def integer_multiple {ι : Type*} (s : finset ι) (f : ι → S) (i : s) : R :=
((exist_integer_multiples M s f).some_spec i i.prop).some
@[simp]
lemma map_integer_multiple {ι : Type*} (s : finset ι) (f : ι → S) (i : s) :
algebra_map R S (integer_multiple M s f i) = common_denom M s f • f i :=
((exist_integer_multiples M s f).some_spec _ i.prop).some_spec
/-- A choice of a common multiple of the denominators of a finite set of fractions. -/
noncomputable
def common_denom_of_finset (s : finset S) : M :=
common_denom M s id
/-- The finset of numerators after clearing the denominators of a finite set of fractions. -/
noncomputable
def finset_integer_multiple [decidable_eq R] (s : finset S) : finset R :=
s.attach.image (λ t, integer_multiple M s id t)
open_locale pointwise
lemma finset_integer_multiple_image [decidable_eq R] (s : finset S) :
algebra_map R S '' (finset_integer_multiple M s) =
common_denom_of_finset M s • s :=
begin
delta finset_integer_multiple common_denom,
rw finset.coe_image,
ext,
split,
{ rintro ⟨_, ⟨x, -, rfl⟩, rfl⟩,
rw map_integer_multiple,
exact set.mem_image_of_mem _ x.prop },
{ rintro ⟨x, hx, rfl⟩,
exact ⟨_, ⟨⟨x, hx⟩, s.mem_attach _, rfl⟩, map_integer_multiple M s id _⟩ }
end
variables {R M}
lemma map_right_cancel {x y} {c : M} (h : algebra_map R S (c * x) = algebra_map R S (c * y)) :
algebra_map R S x = algebra_map R S y :=
(to_localization_map M S).map_right_cancel h
lemma map_left_cancel {x y} {c : M} (h : algebra_map R S (x * c) = algebra_map R S (y * c)) :
algebra_map R S x = algebra_map R S y :=
(to_localization_map M S).map_left_cancel h
lemma eq_zero_of_fst_eq_zero {z x} {y : M}
(h : z * algebra_map R S y = algebra_map R S x) (hx : x = 0) : z = 0 :=
by { rw [hx, (algebra_map R S).map_zero] at h,
exact (is_unit.mul_left_eq_zero (is_localization.map_units S y)).1 h}
variables (M S)
lemma map_eq_zero_iff (r : R) :
algebra_map R S r = 0 ↔ ∃ m : M, r * m = 0 :=
begin
split,
intro h,
{ obtain ⟨m, hm⟩ := (is_localization.eq_iff_exists M S).mp
((algebra_map R S).map_zero.trans h.symm),
exact ⟨m, by simpa using hm.symm⟩ },
{ rintro ⟨m, hm⟩,
rw [← (is_localization.map_units S m).mul_left_inj, zero_mul, ← ring_hom.map_mul, hm,
ring_hom.map_zero] }
end
variables {M}
/-- `is_localization.mk' S` is the surjection sending `(x, y) : R × M` to
`f x * (f y)⁻¹`. -/
noncomputable def mk' (x : R) (y : M) : S :=
(to_localization_map M S).mk' x y
@[simp] lemma mk'_sec (z : S) :
mk' S (is_localization.sec M z).1 (is_localization.sec M z).2 = z :=
(to_localization_map M S).mk'_sec _
lemma mk'_mul (x₁ x₂ : R) (y₁ y₂ : M) :
mk' S (x₁ * x₂) (y₁ * y₂) = mk' S x₁ y₁ * mk' S x₂ y₂ :=
(to_localization_map M S).mk'_mul _ _ _ _
lemma mk'_one (x) : mk' S x (1 : M) = algebra_map R S x :=
(to_localization_map M S).mk'_one _
@[simp]
lemma mk'_spec (x) (y : M) :
mk' S x y * algebra_map R S y = algebra_map R S x :=
(to_localization_map M S).mk'_spec _ _
@[simp]
lemma mk'_spec' (x) (y : M) :
algebra_map R S y * mk' S x y = algebra_map R S x :=
(to_localization_map M S).mk'_spec' _ _
@[simp]
lemma mk'_spec_mk (x) (y : R) (hy : y ∈ M) :
mk' S x ⟨y, hy⟩ * algebra_map R S y = algebra_map R S x :=
mk'_spec S x ⟨y, hy⟩
@[simp]
lemma mk'_spec'_mk (x) (y : R) (hy : y ∈ M) :
algebra_map R S y * mk' S x ⟨y, hy⟩ = algebra_map R S x :=
mk'_spec' S x ⟨y, hy⟩
variables {S}
theorem eq_mk'_iff_mul_eq {x} {y : M} {z} :
z = mk' S x y ↔ z * algebra_map R S y = algebra_map R S x :=
(to_localization_map M S).eq_mk'_iff_mul_eq
theorem mk'_eq_iff_eq_mul {x} {y : M} {z} :
mk' S x y = z ↔ algebra_map R S x = z * algebra_map R S y :=
(to_localization_map M S).mk'_eq_iff_eq_mul
variables (M)
lemma mk'_surjective (z : S) : ∃ x (y : M), mk' S x y = z :=
let ⟨r, hr⟩ := is_localization.surj _ z in ⟨r.1, r.2, (eq_mk'_iff_mul_eq.2 hr).symm⟩
variables {M}
lemma mk'_eq_iff_eq {x₁ x₂} {y₁ y₂ : M} :
mk' S x₁ y₁ = mk' S x₂ y₂ ↔ algebra_map R S (x₁ * y₂) = algebra_map R S (x₂ * y₁) :=
(to_localization_map M S).mk'_eq_iff_eq
lemma mk'_mem_iff {x} {y : M} {I : ideal S} : mk' S x y ∈ I ↔ algebra_map R S x ∈ I :=
begin
split;
intro h,
{ rw [← mk'_spec S x y, mul_comm],
exact I.mul_mem_left ((algebra_map R S) y) h },
{ rw ← mk'_spec S x y at h,
obtain ⟨b, hb⟩ := is_unit_iff_exists_inv.1 (map_units S y),
have := I.mul_mem_left b h,
rwa [mul_comm, mul_assoc, hb, mul_one] at this }
end
protected lemma eq {a₁ b₁} {a₂ b₂ : M} :
mk' S a₁ a₂ = mk' S b₁ b₂ ↔ ∃ c : M, a₁ * b₂ * c = b₁ * a₂ * c :=
(to_localization_map M S).eq
section ext
variables [algebra R P] [is_localization M P]
lemma eq_iff_eq {x y} :
algebra_map R S x = algebra_map R S y ↔ algebra_map R P x = algebra_map R P y :=
(to_localization_map M S).eq_iff_eq (to_localization_map M P)
lemma mk'_eq_iff_mk'_eq {x₁ x₂}
{y₁ y₂ : M} : mk' S x₁ y₁ = mk' S x₂ y₂ ↔ mk' P x₁ y₁ = mk' P x₂ y₂ :=
(to_localization_map M S).mk'_eq_iff_mk'_eq (to_localization_map M P)
lemma mk'_eq_of_eq {a₁ b₁ : R} {a₂ b₂ : M} (H : b₁ * a₂ = a₁ * b₂) :
mk' S a₁ a₂ = mk' S b₁ b₂ :=
(to_localization_map M S).mk'_eq_of_eq H
variables (S)
@[simp] lemma mk'_self {x : R} (hx : x ∈ M) : mk' S x ⟨x, hx⟩ = 1 :=
(to_localization_map M S).mk'_self _ hx
@[simp] lemma mk'_self' {x : M} : mk' S (x : R) x = 1 :=
(to_localization_map M S).mk'_self' _
lemma mk'_self'' {x : M} : mk' S x.1 x = 1 :=
mk'_self' _
end ext
lemma mul_mk'_eq_mk'_of_mul (x y : R) (z : M) :
(algebra_map R S) x * mk' S y z = mk' S (x * y) z :=
(to_localization_map M S).mul_mk'_eq_mk'_of_mul _ _ _
lemma mk'_eq_mul_mk'_one (x : R) (y : M) :
mk' S x y = (algebra_map R S) x * mk' S 1 y :=
((to_localization_map M S).mul_mk'_one_eq_mk' _ _).symm
@[simp] lemma mk'_mul_cancel_left (x : R) (y : M) :
mk' S (y * x : R) y = (algebra_map R S) x :=
(to_localization_map M S).mk'_mul_cancel_left _ _
lemma mk'_mul_cancel_right (x : R) (y : M) :
mk' S (x * y) y = (algebra_map R S) x :=
(to_localization_map M S).mk'_mul_cancel_right _ _
@[simp] lemma mk'_mul_mk'_eq_one (x y : M) :
mk' S (x : R) y * mk' S (y : R) x = 1 :=
by rw [←mk'_mul, mul_comm]; exact mk'_self _ _
lemma mk'_mul_mk'_eq_one' (x : R) (y : M) (h : x ∈ M) :
mk' S x y * mk' S (y : R) ⟨x, h⟩ = 1 :=
mk'_mul_mk'_eq_one ⟨x, h⟩ _
section
variables (M)
lemma is_unit_comp (j : S →+* P) (y : M) :
is_unit (j.comp (algebra_map R S) y) :=
(to_localization_map M S).is_unit_comp j.to_monoid_hom _
end
/-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `comm_ring`s
`g : R →+* P` such that `g(M) ⊆ units P`, `f x = f y → g x = g y` for all `x y : R`. -/
lemma eq_of_eq {g : R →+* P} (hg : ∀ y : M, is_unit (g y)) {x y}
(h : (algebra_map R S) x = (algebra_map R S) y) :
g x = g y :=
@submonoid.localization_map.eq_of_eq _ _ _ _ _ _ _
(to_localization_map M S) g.to_monoid_hom hg _ _ h
lemma mk'_add (x₁ x₂ : R) (y₁ y₂ : M) :
mk' S (x₁ * y₂ + x₂ * y₁) (y₁ * y₂) = mk' S x₁ y₁ + mk' S x₂ y₂ :=
mk'_eq_iff_eq_mul.2 $ eq.symm
begin
rw [mul_comm (_ + _), mul_add, mul_mk'_eq_mk'_of_mul, ←eq_sub_iff_add_eq, mk'_eq_iff_eq_mul,
mul_comm _ ((algebra_map R S) _), mul_sub, eq_sub_iff_add_eq, ←eq_sub_iff_add_eq', ←mul_assoc,
←(algebra_map R S).map_mul, mul_mk'_eq_mk'_of_mul, mk'_eq_iff_eq_mul],
simp only [(algebra_map R S).map_add, submonoid.coe_mul, (algebra_map R S).map_mul],
ring_exp,
end
/-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `comm_ring`s
`g : R →+* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from
`S` to `P` sending `z : S` to `g x * (g y)⁻¹`, where `(x, y) : R × M` are such that
`z = f x * (f y)⁻¹`. -/
noncomputable def lift {g : R →+* P} (hg : ∀ y : M, is_unit (g y)) : S →+* P :=
ring_hom.mk' (@submonoid.localization_map.lift _ _ _ _ _ _ _
(to_localization_map M S) g.to_monoid_hom hg) $
begin
intros x y,
rw [(to_localization_map M S).lift_spec, mul_comm, add_mul, ←sub_eq_iff_eq_add, eq_comm,
(to_localization_map M S).lift_spec_mul, mul_comm _ (_ - _), sub_mul, eq_sub_iff_add_eq',
←eq_sub_iff_add_eq, mul_assoc, (to_localization_map M S).lift_spec_mul],
show g _ * (g _ * g _) = g _ * (g _ * g _ - g _ * g _),
simp only [← g.map_sub, ← g.map_mul, to_localization_map_sec],
apply eq_of_eq hg,
rw [(algebra_map R S).map_mul, sec_spec', mul_sub, (algebra_map R S).map_sub],
simp only [ring_hom.map_mul, sec_spec'],
ring,
assumption
end
variables {g : R →+* P} (hg : ∀ y : M, is_unit (g y))
/-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `comm_ring`s
`g : R →* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from
`S` to `P` maps `f x * (f y)⁻¹` to `g x * (g y)⁻¹` for all `x : R, y ∈ M`. -/
lemma lift_mk' (x y) :
lift hg (mk' S x y) = g x * ↑(is_unit.lift_right (g.to_monoid_hom.mrestrict M) hg y)⁻¹ :=
(to_localization_map M S).lift_mk' _ _ _
lemma lift_mk'_spec (x v) (y : M) :
lift hg (mk' S x y) = v ↔ g x = g y * v :=
(to_localization_map M S).lift_mk'_spec _ _ _ _
@[simp] lemma lift_eq (x : R) :
lift hg ((algebra_map R S) x) = g x :=
(to_localization_map M S).lift_eq _ _
lemma lift_eq_iff {x y : R × M} :
lift hg (mk' S x.1 x.2) = lift hg (mk' S y.1 y.2) ↔ g (x.1 * y.2) = g (y.1 * x.2) :=
(to_localization_map M S).lift_eq_iff _
@[simp] lemma lift_comp : (lift hg).comp (algebra_map R S) = g :=
ring_hom.ext $ monoid_hom.ext_iff.1 $ (to_localization_map M S).lift_comp _
@[simp] lemma lift_of_comp (j : S →+* P) :
lift (is_unit_comp M j) = j :=
ring_hom.ext $ monoid_hom.ext_iff.1 $ (to_localization_map M S).lift_of_comp j.to_monoid_hom
variables (M)
/-- See note [partially-applied ext lemmas] -/
lemma monoid_hom_ext ⦃j k : S →* P⦄
(h : j.comp (algebra_map R S : R →* S) = k.comp (algebra_map R S)) : j = k :=
submonoid.localization_map.epic_of_localization_map (to_localization_map M S) $
monoid_hom.congr_fun h
/-- See note [partially-applied ext lemmas] -/
lemma ring_hom_ext ⦃j k : S →+* P⦄
(h : j.comp (algebra_map R S) = k.comp (algebra_map R S)) : j = k :=
ring_hom.coe_monoid_hom_injective $ monoid_hom_ext M $ monoid_hom.ext $ ring_hom.congr_fun h
/-- To show `j` and `k` agree on the whole localization, it suffices to show they agree
on the image of the base ring, if they preserve `1` and `*`. -/
protected lemma ext (j k : S → P) (hj1 : j 1 = 1) (hk1 : k 1 = 1)
(hjm : ∀ a b, j (a * b) = j a * j b) (hkm : ∀ a b, k (a * b) = k a * k b)
(h : ∀ a, j (algebra_map R S a) = k (algebra_map R S a)) : j = k :=
monoid_hom.mk.inj (monoid_hom_ext M $ monoid_hom.ext h : (⟨j, hj1, hjm⟩ : S →* P) = ⟨k, hk1, hkm⟩)
variables {M}
lemma lift_unique {j : S →+* P}
(hj : ∀ x, j ((algebra_map R S) x) = g x) : lift hg = j :=
ring_hom.ext $ monoid_hom.ext_iff.1 $ @submonoid.localization_map.lift_unique
_ _ _ _ _ _ _ (to_localization_map M S) g.to_monoid_hom hg j.to_monoid_hom hj
@[simp] lemma lift_id (x) : lift (map_units S : ∀ y : M, is_unit _) x = x :=
(to_localization_map M S).lift_id _
lemma lift_surjective_iff :
surjective (lift hg : S → P) ↔ ∀ v : P, ∃ x : R × M, v * g x.2 = g x.1 :=
(to_localization_map M S).lift_surjective_iff hg
lemma lift_injective_iff :
injective (lift hg : S → P) ↔ ∀ x y, algebra_map R S x = algebra_map R S y ↔ g x = g y :=
(to_localization_map M S).lift_injective_iff hg
section map
variables {T : submonoid P} {Q : Type*} [comm_ring Q] (hy : M ≤ T.comap g)
variables [algebra P Q] [is_localization T Q]
section
variables (Q)
/-- Map a homomorphism `g : R →+* P` to `S →+* Q`, where `S` and `Q` are
localizations of `R` and `P` at `M` and `T` respectively,
such that `g(M) ⊆ T`.
We send `z : S` to `algebra_map P Q (g x) * (algebra_map P Q (g y))⁻¹`, where
`(x, y) : R × M` are such that `z = f x * (f y)⁻¹`. -/
noncomputable def map (g : R →+* P) (hy : M ≤ T.comap g) : S →+* Q :=
@lift R _ M _ _ _ _ _ _ ((algebra_map P Q).comp g) (λ y, map_units _ ⟨g y, hy y.2⟩)
end
lemma map_eq (x) :
map Q g hy ((algebra_map R S) x) = algebra_map P Q (g x) :=
lift_eq (λ y, map_units _ ⟨g y, hy y.2⟩) x
@[simp] lemma map_comp :
(map Q g hy).comp (algebra_map R S) = (algebra_map P Q).comp g :=
lift_comp $ λ y, map_units _ ⟨g y, hy y.2⟩
lemma map_mk' (x) (y : M) :
map Q g hy (mk' S x y) = mk' Q (g x) ⟨g y, hy y.2⟩ :=
@submonoid.localization_map.map_mk' _ _ _ _ _ _ _ (to_localization_map M S)
g.to_monoid_hom _ (λ y, hy y.2) _ _ (to_localization_map T Q) _ _
@[simp] lemma map_id (z : S) (h : M ≤ M.comap (ring_hom.id R) := le_refl M) :
map S (ring_hom.id _) h z = z :=
lift_id _
lemma map_unique (j : S →+* Q)
(hj : ∀ x : R, j (algebra_map R S x) = algebra_map P Q (g x)) : map Q g hy = j :=
lift_unique (λ y, map_units _ ⟨g y, hy y.2⟩) hj
/-- If `comm_ring` homs `g : R →+* P, l : P →+* A` induce maps of localizations, the composition
of the induced maps equals the map of localizations induced by `l ∘ g`. -/
lemma map_comp_map {A : Type*} [comm_ring A] {U : submonoid A} {W} [comm_ring W]
[algebra A W] [is_localization U W] {l : P →+* A} (hl : T ≤ U.comap l) :
(map W l hl).comp (map Q g hy : S →+* _) = map W (l.comp g) (λ x hx, hl (hy hx)) :=
ring_hom.ext $ λ x, @submonoid.localization_map.map_map _ _ _ _ _ P _ (to_localization_map M S) g _
_ _ _ _ _ _ _ _ _ (to_localization_map U W) l _ x
/-- If `comm_ring` homs `g : R →+* P, l : P →+* A` induce maps of localizations, the composition
of the induced maps equals the map of localizations induced by `l ∘ g`. -/
lemma map_map {A : Type*} [comm_ring A] {U : submonoid A} {W} [comm_ring W]
[algebra A W] [is_localization U W] {l : P →+* A} (hl : T ≤ U.comap l) (x : S) :
map W l hl (map Q g hy x) = map W (l.comp g) (λ x hx, hl (hy hx)) x :=
by rw ←map_comp_map hy hl; refl
section
variables (S Q)
/-- If `S`, `Q` are localizations of `R` and `P` at submonoids `M, T` respectively, an
isomorphism `j : R ≃+* P` such that `j(M) = T` induces an isomorphism of localizations
`S ≃+* Q`. -/
@[simps]
noncomputable def ring_equiv_of_ring_equiv (h : R ≃+* P) (H : M.map h.to_monoid_hom = T) :
S ≃+* Q :=
have H' : T.map h.symm.to_monoid_hom = M,
by { rw [← M.map_id, ← H, submonoid.map_map], congr, ext, apply h.symm_apply_apply },
{ to_fun := map Q (h : R →+* P) (M.le_comap_of_map_le (le_of_eq H)),
inv_fun := map S (h.symm : P →+* R) (T.le_comap_of_map_le (le_of_eq H')),
left_inv := λ x, by { rw [map_map, map_unique _ (ring_hom.id _), ring_hom.id_apply],
intro x, convert congr_arg (algebra_map R S) (h.symm_apply_apply x).symm },
right_inv := λ x, by { rw [map_map, map_unique _ (ring_hom.id _), ring_hom.id_apply],
intro x, convert congr_arg (algebra_map P Q) (h.apply_symm_apply x).symm },
.. map Q (h : R →+* P) _ }
end
lemma ring_equiv_of_ring_equiv_eq_map {j : R ≃+* P} (H : M.map j.to_monoid_hom = T) :
(ring_equiv_of_ring_equiv S Q j H : S →+* Q) =
map Q (j : R →+* P) (M.le_comap_of_map_le (le_of_eq H)) := rfl
@[simp] lemma ring_equiv_of_ring_equiv_eq {j : R ≃+* P} (H : M.map j.to_monoid_hom = T) (x) :
ring_equiv_of_ring_equiv S Q j H ((algebra_map R S) x) = algebra_map P Q (j x) :=
map_eq _ _
lemma ring_equiv_of_ring_equiv_mk' {j : R ≃+* P} (H : M.map j.to_monoid_hom = T) (x : R) (y : M) :
ring_equiv_of_ring_equiv S Q j H (mk' S x y) =
mk' Q (j x) ⟨j y, show j y ∈ T, from H ▸ set.mem_image_of_mem j y.2⟩ :=
map_mk' _ _ _
end map
section alg_equiv
variables {Q : Type*} [comm_ring Q] [algebra R Q] [is_localization M Q]
section
variables (M S Q)
/-- If `S`, `Q` are localizations of `R` at the submonoid `M` respectively,
there is an isomorphism of localizations `S ≃ₐ[R] Q`. -/
@[simps]
noncomputable def alg_equiv : S ≃ₐ[R] Q :=
{ commutes' := ring_equiv_of_ring_equiv_eq _,
.. ring_equiv_of_ring_equiv S Q (ring_equiv.refl R) M.map_id }
end
@[simp]
lemma alg_equiv_mk' (x : R) (y : M) : alg_equiv M S Q (mk' S x y) = mk' Q x y:=
map_mk' _ _ _
@[simp]
lemma alg_equiv_symm_mk' (x : R) (y : M) : (alg_equiv M S Q).symm (mk' Q x y) = mk' S x y:=
map_mk' _ _ _
end alg_equiv
end is_localization
section
variables (M)
lemma is_localization_of_alg_equiv [algebra R P] [is_localization M S] (h : S ≃ₐ[R] P) :
is_localization M P :=
begin
constructor,
{ intro y,
convert (is_localization.map_units S y).map h.to_alg_hom.to_ring_hom.to_monoid_hom,
exact (h.commutes y).symm },
{ intro y,
obtain ⟨⟨x, s⟩, e⟩ := is_localization.surj M (h.symm y),
apply_fun h at e,
simp only [h.map_mul, h.apply_symm_apply, h.commutes] at e,
exact ⟨⟨x, s⟩, e⟩ },
{ intros x y,
rw [← h.symm.to_equiv.injective.eq_iff, ← is_localization.eq_iff_exists M S,
← h.symm.commutes, ← h.symm.commutes],
refl }
end
lemma is_localization_iff_of_alg_equiv [algebra R P] (h : S ≃ₐ[R] P) :
is_localization M S ↔ is_localization M P :=
⟨λ _, by exactI is_localization_of_alg_equiv M h,
λ _, by exactI is_localization_of_alg_equiv M h.symm⟩
lemma is_localization_iff_of_ring_equiv (h : S ≃+* P) :
is_localization M S ↔
@@is_localization _ M P _ (h.to_ring_hom.comp $ algebra_map R S).to_algebra :=
begin
letI := (h.to_ring_hom.comp $ algebra_map R S).to_algebra,
exact is_localization_iff_of_alg_equiv M { commutes' := λ _, rfl, ..h },
end
variable (S)
lemma is_localization_of_base_ring_equiv [is_localization M S] (h : R ≃+* P) :
@@is_localization _ (M.map h.to_monoid_hom) S _
((algebra_map R S).comp h.symm.to_ring_hom).to_algebra :=
begin
constructor,
{ rintros ⟨_, ⟨y, hy, rfl⟩⟩,
convert is_localization.map_units S ⟨y, hy⟩,
dsimp only [ring_hom.algebra_map_to_algebra, ring_hom.comp_apply],
exact congr_arg _ (h.symm_apply_apply _) },
{ intro y,
obtain ⟨⟨x, s⟩, e⟩ := is_localization.surj M y,
refine ⟨⟨h x, _, _, s.prop, rfl⟩, _⟩,
dsimp only [ring_hom.algebra_map_to_algebra, ring_hom.comp_apply] at ⊢ e,
convert e; exact h.symm_apply_apply _ },
{ intros x y,
rw [ring_hom.algebra_map_to_algebra, ring_hom.comp_apply, ring_hom.comp_apply,
is_localization.eq_iff_exists M S],
simp_rw ← h.to_equiv.apply_eq_iff_eq,
change (∃ (c : M), h (h.symm x * c) = h (h.symm y * c)) ↔ _,
simp only [ring_equiv.apply_symm_apply, ring_equiv.map_mul],
exact ⟨λ ⟨c, e⟩, ⟨⟨_, _, c.prop, rfl⟩, e⟩, λ ⟨⟨_, c, h, e₁⟩, e₂⟩, ⟨⟨_, h⟩, e₁.symm ▸ e₂⟩⟩ }
end
lemma is_localization_iff_of_base_ring_equiv (h : R ≃+* P) :
is_localization M S ↔ @@is_localization _ (M.map h.to_monoid_hom) S _
((algebra_map R S).comp h.symm.to_ring_hom).to_algebra :=
begin
refine ⟨λ _, by exactI is_localization_of_base_ring_equiv _ _ h, _⟩,
letI := ((algebra_map R S).comp h.symm.to_ring_hom).to_algebra,
intro H,
convert @@is_localization_of_base_ring_equiv _ _ _ _ _ _ H h.symm,
{ erw [submonoid.map_equiv_eq_comap_symm, submonoid.comap_map_eq_of_injective],
exact h.to_equiv.injective },
rw [ring_hom.algebra_map_to_algebra, ring_hom.comp_assoc],
simp only [ring_hom.comp_id, ring_equiv.symm_symm, ring_equiv.symm_to_ring_hom_comp_to_ring_hom],
apply algebra.algebra_ext,
intro r,
rw ring_hom.algebra_map_to_algebra
end
end
section away
variables (x : R)
/-- Given `x : R`, the typeclass `is_localization.away x S` states that `S` is
isomorphic to the localization of `R` at the submonoid generated by `x`. -/
abbreviation away (S : Type*) [comm_ring S] [algebra R S] :=
is_localization (submonoid.powers x) S
namespace away
variables [is_localization.away x S]
/-- Given `x : R` and a localization map `F : R →+* S` away from `x`, `inv_self` is `(F x)⁻¹`. -/
noncomputable def inv_self : S :=
mk' S (1 : R) ⟨x, submonoid.mem_powers _⟩
variables {g : R →+* P}
/-- Given `x : R`, a localization map `F : R →+* S` away from `x`, and a map of `comm_ring`s
`g : R →+* P` such that `g x` is invertible, the homomorphism induced from `S` to `P` sending
`z : S` to `g y * (g x)⁻ⁿ`, where `y : R, n : ℕ` are such that `z = F y * (F x)⁻ⁿ`. -/
noncomputable def lift (hg : is_unit (g x)) : S →+* P :=
is_localization.lift $ λ (y : submonoid.powers x), show is_unit (g y.1),
begin
obtain ⟨n, hn⟩ := y.2,
rw [←hn, g.map_pow],
exact is_unit.map (pow_monoid_hom n) hg,
end
@[simp] lemma away_map.lift_eq (hg : is_unit (g x)) (a : R) :
lift x hg ((algebra_map R S) a) = g a := lift_eq _ _
@[simp] lemma away_map.lift_comp (hg : is_unit (g x)) :
(lift x hg).comp (algebra_map R S) = g := lift_comp _
/-- Given `x y : R` and localizations `S`, `P` away from `x` and `x * y`
respectively, the homomorphism induced from `S` to `P`. -/
noncomputable def away_to_away_right (y : R) [algebra R P] [is_localization.away (x * y) P] :
S →+* P :=
lift x $ show is_unit ((algebra_map R P) x), from
is_unit_of_mul_eq_one ((algebra_map R P) x) (mk' P y ⟨x * y, submonoid.mem_powers _⟩) $
by rw [mul_mk'_eq_mk'_of_mul, mk'_self]
variables (S) (Q : Type*) [comm_ring Q] [algebra P Q]
/-- Given a map `f : R →+* S` and an element `r : R`, we may construct a map `Rᵣ →+* Sᵣ`. -/
noncomputable
def map (f : R →+* P) (r : R) [is_localization.away r S]
[is_localization.away (f r) Q] : S →+* Q :=
is_localization.map Q f
(show submonoid.powers r ≤ (submonoid.powers (f r)).comap f,
by { rintros x ⟨n, rfl⟩, use n, simp })
end away
end away
section inv_submonoid
variables (M S)
/-- The submonoid of `S = M⁻¹R` consisting of `{ 1 / x | x ∈ M }`. -/
def inv_submonoid : submonoid S := (M.map (algebra_map R S : R →* S)).left_inv
variable [is_localization M S]
lemma submonoid_map_le_is_unit : M.map (algebra_map R S : R →* S) ≤ is_unit.submonoid S :=
by { rintros _ ⟨a, ha, rfl⟩, exact is_localization.map_units S ⟨_, ha⟩ }
/-- There is an equivalence of monoids between the image of `M` and `inv_submonoid`. -/
noncomputable
abbreviation equiv_inv_submonoid : M.map (algebra_map R S : R →* S) ≃* inv_submonoid M S :=
((M.map (algebra_map R S : R →* S)).left_inv_equiv (submonoid_map_le_is_unit M S)).symm
/-- There is a canonical map from `M` to `inv_submonoid` sending `x` to `1 / x`. -/
noncomputable
def to_inv_submonoid : M →* inv_submonoid M S :=
(equiv_inv_submonoid M S).to_monoid_hom.comp ((algebra_map R S : R →* S).submonoid_map M)
lemma to_inv_submonoid_surjective : function.surjective (to_inv_submonoid M S) :=
function.surjective.comp (equiv.surjective _) (monoid_hom.submonoid_map_surjective _ _)
@[simp]
lemma to_inv_submonoid_mul (m : M) : (to_inv_submonoid M S m : S) * (algebra_map R S m) = 1 :=
submonoid.left_inv_equiv_symm_mul _ _ _
@[simp]
lemma mul_to_inv_submonoid (m : M) : (algebra_map R S m) * (to_inv_submonoid M S m : S) = 1 :=
submonoid.mul_left_inv_equiv_symm _ _ ⟨_, _⟩
@[simp]
lemma smul_to_inv_submonoid (m : M) : m • (to_inv_submonoid M S m : S) = 1 :=
by { convert mul_to_inv_submonoid M S m, rw ← algebra.smul_def, refl }
variables {S}
lemma surj' (z : S) : ∃ (r : R) (m : M), z = r • to_inv_submonoid M S m :=
begin
rcases is_localization.surj M z with ⟨⟨r, m⟩, e : z * _ = algebra_map R S r⟩,
refine ⟨r, m, _⟩,
rw [algebra.smul_def, ← e, mul_assoc],
simp,
end
lemma to_inv_submonoid_eq_mk' (x : M) :
(to_inv_submonoid M S x : S) = mk' S 1 x :=
by { rw ← (is_localization.map_units S x).mul_left_inj, simp }
lemma mem_inv_submonoid_iff_exists_mk' (x : S) :
x ∈ inv_submonoid M S ↔ ∃ m : M, mk' S 1 m = x :=
begin
simp_rw ← to_inv_submonoid_eq_mk',
exact ⟨λ h, ⟨_, congr_arg subtype.val (to_inv_submonoid_surjective M S ⟨x, h⟩).some_spec⟩,
λ h, h.some_spec ▸ (to_inv_submonoid M S h.some).prop⟩
end
variables (S)
lemma span_inv_submonoid : submodule.span R (inv_submonoid M S : set S) = ⊤ :=
begin
rw eq_top_iff,
rintros x -,
rcases is_localization.surj' M x with ⟨r, m, rfl⟩,
exact submodule.smul_mem _ _ (submodule.subset_span (to_inv_submonoid M S m).prop),
end
lemma finite_type_of_monoid_fg [monoid.fg M] : algebra.finite_type R S :=
begin
have := monoid.fg_of_surjective _ (to_inv_submonoid_surjective M S),
rw monoid.fg_iff_submonoid_fg at this,
rcases this with ⟨s, hs⟩,
refine ⟨⟨s, _⟩⟩,
rw eq_top_iff,
rintro x -,
change x ∈ ((algebra.adjoin R _ : subalgebra R S).to_submodule : set S),
rw [algebra.adjoin_eq_span, hs, span_inv_submonoid],
trivial
end
end inv_submonoid
end is_localization
namespace localization
open is_localization
/-! ### Constructing a localization at a given submonoid -/
variables {M}
section
instance [subsingleton R] : subsingleton (localization M) :=
⟨λ a b, by { induction a, induction b, congr, refl, refl }⟩
/-- Addition in a ring localization is defined as `⟨a, b⟩ + ⟨c, d⟩ = ⟨b * c + d * a, b * d⟩`.
Should not be confused with `add_localization.add`, which is defined as
`⟨a, b⟩ + ⟨c, d⟩ = ⟨a + c, b + d⟩`.
-/
@[irreducible] protected def add (z w : localization M) : localization M :=
localization.lift_on₂ z w
(λ a b c d, mk ((b : R) * c + d * a) (b * d)) $
λ a a' b b' c c' d d' h1 h2, mk_eq_mk_iff.2
begin
rw r_eq_r' at h1 h2 ⊢,
cases h1 with t₅ ht₅,
cases h2 with t₆ ht₆,
use t₆ * t₅,
calc ((b : R) * c + d * a) * (b' * d') * (t₆ * t₅) =
(c * d' * t₆) * (b * b' * t₅) + (a * b' * t₅) * (d * d' * t₆) : by ring
... = (b' * c' + d' * a') * (b * d) * (t₆ * t₅) : by rw [ht₆, ht₅]; ring
end
instance : has_add (localization M) := ⟨localization.add⟩
lemma add_mk (a b c d) : (mk a b : localization M) + mk c d = mk (b * c + d * a) (b * d) :=
by { unfold has_add.add localization.add, apply lift_on₂_mk }
lemma add_mk_self (a b c) : (mk a b : localization M) + mk c b = mk (a + c) b :=
begin
rw [add_mk, mk_eq_mk_iff, r_eq_r'],
refine (r' M).symm ⟨1, _⟩,
simp only [submonoid.coe_one, submonoid.coe_mul],
ring
end
/-- Negation in a ring localization is defined as `-⟨a, b⟩ = ⟨-a, b⟩`. -/
@[irreducible] protected def neg (z : localization M) : localization M :=
localization.lift_on z (λ a b, mk (-a) b) $
λ a b c d h, mk_eq_mk_iff.2
begin
rw r_eq_r' at h ⊢,
cases h with t ht,
use t,
rw [neg_mul_eq_neg_mul_symm, neg_mul_eq_neg_mul_symm, ht],
ring_nf,
end
instance : has_neg (localization M) := ⟨localization.neg⟩
lemma neg_mk (a b) : -(mk a b : localization M) = mk (-a) b :=
by { unfold has_neg.neg localization.neg, apply lift_on_mk }
/-- The zero element in a ring localization is defined as `⟨0, 1⟩`.
Should not be confused with `add_localization.zero` which is `⟨0, 0⟩`. -/
@[irreducible] protected def zero : localization M :=
mk 0 1
instance : has_zero (localization M) := ⟨localization.zero⟩
lemma mk_zero (b) : (mk 0 b : localization M) = 0 :=
calc mk 0 b = mk 0 1 : mk_eq_mk_iff.mpr (r_of_eq (by simp))
... = 0 : by unfold has_zero.zero localization.zero
lemma lift_on_zero {p : Type*} (f : ∀ (a : R) (b : M), p) (H) : lift_on 0 f H = f 0 1 :=
by rw [← mk_zero 1, lift_on_mk]
private meta def tac := `[
{ intros,
simp only [add_mk, localization.mk_mul, neg_mk, ← mk_zero 1],
refine mk_eq_mk_iff.mpr (r_of_eq _),
simp only [submonoid.coe_mul, prod.fst_mul, prod.snd_mul],
ring }]