-
Notifications
You must be signed in to change notification settings - Fork 257
/
Basic.lean
1055 lines (799 loc) · 40 KB
/
Basic.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) 2023 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.GroupTheory.Subgroup.Basic
import Mathlib.RingTheory.NonUnitalSubsemiring.Basic
/-!
# `NonUnitalSubring`s
Let `R` be a non-unital ring. This file defines the "bundled" non-unital subring type
`NonUnitalSubring R`, a type whose terms correspond to non-unital subrings of `R`.
This is the preferred way to talk about non-unital subrings in mathlib.
We prove that non-unital subrings are a complete lattice, and that you can `map` (pushforward) and
`comap` (pull back) them along ring homomorphisms.
We define the `closure` construction from `Set R` to `NonUnitalSubring R`, sending a subset of
`R` to the non-unital subring it generates, and prove that it is a Galois insertion.
## Main definitions
Notation used here:
`(R : Type u) [NonUnitalRing R] (S : Type u) [NonUnitalRing S] (f g : R →ₙ+* S)`
`(A : NonUnitalSubring R) (B : NonUnitalSubring S) (s : Set R)`
* `NonUnitalSubring R` : the type of non-unital subrings of a ring `R`.
* `instance : CompleteLattice (NonUnitalSubring R)` : the complete lattice structure on the
non-unital subrings.
* `NonUnitalSubring.center` : the center of a non-unital ring `R`.
* `NonUnitalSubring.closure` : non-unital subring closure of a set, i.e., the smallest
non-unital subring that includes the set.
* `NonUnitalSubring.gi` : `closure : Set M → NonUnitalSubring M` and coercion
`coe : NonUnitalSubring M → Set M`
form a `GaloisInsertion`.
* `comap f B : NonUnitalSubring A` : the preimage of a non-unital subring `B` along the
non-unital ring homomorphism `f`
* `map f A : NonUnitalSubring B` : the image of a non-unital subring `A` along the
non-unital ring homomorphism `f`.
* `Prod A B : NonUnitalSubring (R × S)` : the product of non-unital subrings
* `f.range : NonUnitalSubring B` : the range of the non-unital ring homomorphism `f`.
* `eq_locus f g : NonUnitalSubring R` : given non-unital ring homomorphisms `f g : R →ₙ+* S`,
the non-unital subring of `R` where `f x = g x`
## Implementation notes
A non-unital subring is implemented as a `NonUnitalSubsemiring` which is also an
additive subgroup.
Lattice inclusion (e.g. `≤` and `⊓`) is used rather than set notation (`⊆` and `∩`), although
`∈` is defined as membership of a non-unital subring's underlying set.
## Tags
non-unital subring
-/
open scoped BigOperators
universe u v w
section Basic
variable {R : Type u} {S : Type v} {T : Type w} [NonUnitalNonAssocRing R]
section NonUnitalSubringClass
/-- `NonUnitalSubringClass S R` states that `S` is a type of subsets `s ⊆ R` that
are both a multiplicative submonoid and an additive subgroup. -/
class NonUnitalSubringClass (S : Type*) (R : Type u) [NonUnitalNonAssocRing R]
[SetLike S R] extends NonUnitalSubsemiringClass S R, NegMemClass S R : Prop where
-- See note [lower instance priority]
instance (priority := 100) NonUnitalSubringClass.addSubgroupClass (S : Type*) (R : Type u)
[SetLike S R] [NonUnitalNonAssocRing R] [h : NonUnitalSubringClass S R] :
AddSubgroupClass S R :=
{ h with }
variable [SetLike S R] [hSR : NonUnitalSubringClass S R] (s : S)
namespace NonUnitalSubringClass
-- Prefer subclasses of `NonUnitalRing` over subclasses of `NonUnitalSubringClass`.
/-- A non-unital subring of a non-unital ring inherits a non-unital ring structure -/
instance (priority := 75) toNonUnitalNonAssocRing : NonUnitalNonAssocRing s :=
Subtype.val_injective.nonUnitalNonAssocRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl)
(fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl
-- Prefer subclasses of `NonUnitalRing` over subclasses of `NonUnitalSubringClass`.
/-- A non-unital subring of a non-unital ring inherits a non-unital ring structure -/
instance (priority := 75) toNonUnitalRing {R : Type*} [NonUnitalRing R] [SetLike S R]
[NonUnitalSubringClass S R] (s : S) : NonUnitalRing s :=
Subtype.val_injective.nonUnitalRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl)
(fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl
-- Prefer subclasses of `NonUnitalRing` over subclasses of `NonUnitalSubringClass`.
/-- A non-unital subring of a `NonUnitalCommRing` is a `NonUnitalCommRing`. -/
instance (priority := 75) toNonUnitalCommRing {R} [NonUnitalCommRing R] [SetLike S R]
[NonUnitalSubringClass S R] : NonUnitalCommRing s :=
Subtype.val_injective.nonUnitalCommRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl)
(fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl
/-- The natural non-unital ring hom from a non-unital subring of a non-unital ring `R` to `R`. -/
def subtype (s : S) : s →ₙ+* R :=
{ NonUnitalSubsemiringClass.subtype s,
AddSubgroupClass.subtype s with
toFun := Subtype.val }
@[simp]
theorem coe_subtype : (subtype s : s → R) = Subtype.val :=
rfl
end NonUnitalSubringClass
end NonUnitalSubringClass
variable [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T]
/-- `NonUnitalSubring R` is the type of non-unital subrings of `R`. A non-unital subring of `R`
is a subset `s` that is a multiplicative subsemigroup and an additive subgroup. Note in particular
that it shares the same 0 as R. -/
structure NonUnitalSubring (R : Type u) [NonUnitalNonAssocRing R] extends
NonUnitalSubsemiring R, AddSubgroup R
/-- Reinterpret a `NonUnitalSubring` as a `NonUnitalSubsemiring`. -/
add_decl_doc NonUnitalSubring.toNonUnitalSubsemiring
/-- Reinterpret a `NonUnitalSubring` as an `AddSubgroup`. -/
add_decl_doc NonUnitalSubring.toAddSubgroup
namespace NonUnitalSubring
/-- The underlying submonoid of a `NonUnitalSubring`. -/
def toSubsemigroup (s : NonUnitalSubring R) : Subsemigroup R :=
{ s.toNonUnitalSubsemiring.toSubsemigroup with carrier := s.carrier }
instance : SetLike (NonUnitalSubring R) R
where
coe s := s.carrier
coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective h
instance : NonUnitalSubringClass (NonUnitalSubring R) R
where
zero_mem s := s.zero_mem'
add_mem {s} := s.add_mem'
mul_mem {s} := s.mul_mem'
neg_mem {s} := s.neg_mem'
theorem mem_carrier {s : NonUnitalSubring R} {x : R} : x ∈ s.toNonUnitalSubsemiring ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem mem_mk {S : NonUnitalSubsemiring R} {x : R} (h) :
x ∈ (⟨S, h⟩ : NonUnitalSubring R) ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem coe_set_mk (S : NonUnitalSubsemiring R) (h) :
((⟨S, h⟩ : NonUnitalSubring R) : Set R) = S :=
rfl
@[simp]
theorem mk_le_mk {S S' : NonUnitalSubsemiring R} (h h') :
(⟨S, h⟩ : NonUnitalSubring R) ≤ (⟨S', h'⟩ : NonUnitalSubring R) ↔ S ≤ S' :=
Iff.rfl
/-- Two non-unital subrings are equal if they have the same elements. -/
@[ext]
theorem ext {S T : NonUnitalSubring R} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T :=
SetLike.ext h
/-- Copy of a non-unital subring with a new `carrier` equal to the old one. Useful to fix
definitional equalities. -/
protected def copy (S : NonUnitalSubring R) (s : Set R) (hs : s = ↑S) : NonUnitalSubring R :=
{ S.toNonUnitalSubsemiring.copy s hs with
carrier := s
neg_mem' := hs.symm ▸ S.neg_mem' }
@[simp]
theorem coe_copy (S : NonUnitalSubring R) (s : Set R) (hs : s = ↑S) : (S.copy s hs : Set R) = s :=
rfl
theorem copy_eq (S : NonUnitalSubring R) (s : Set R) (hs : s = ↑S) : S.copy s hs = S :=
SetLike.coe_injective hs
theorem toNonUnitalSubsemiring_injective :
Function.Injective (toNonUnitalSubsemiring : NonUnitalSubring R → NonUnitalSubsemiring R)
| _r, _s, h => ext (SetLike.ext_iff.mp h : _)
@[mono]
theorem toNonUnitalSubsemiring_strictMono :
StrictMono (toNonUnitalSubsemiring : NonUnitalSubring R → NonUnitalSubsemiring R) := fun _ _ =>
id
@[mono]
theorem toNonUnitalSubsemiring_mono :
Monotone (toNonUnitalSubsemiring : NonUnitalSubring R → NonUnitalSubsemiring R) :=
toNonUnitalSubsemiring_strictMono.monotone
theorem toAddSubgroup_injective :
Function.Injective (toAddSubgroup : NonUnitalSubring R → AddSubgroup R)
| _r, _s, h => ext (SetLike.ext_iff.mp h : _)
@[mono]
theorem toAddSubgroup_strictMono :
StrictMono (toAddSubgroup : NonUnitalSubring R → AddSubgroup R) := fun _ _ => id
@[mono]
theorem toAddSubgroup_mono : Monotone (toAddSubgroup : NonUnitalSubring R → AddSubgroup R) :=
toAddSubgroup_strictMono.monotone
theorem toSubsemigroup_injective :
Function.Injective (toSubsemigroup : NonUnitalSubring R → Subsemigroup R)
| _r, _s, h => ext (SetLike.ext_iff.mp h : _)
@[mono]
theorem toSubsemigroup_strictMono :
StrictMono (toSubsemigroup : NonUnitalSubring R → Subsemigroup R) := fun _ _ => id
@[mono]
theorem toSubsemigroup_mono : Monotone (toSubsemigroup : NonUnitalSubring R → Subsemigroup R) :=
toSubsemigroup_strictMono.monotone
/-- Construct a `NonUnitalSubring R` from a set `s`, a subsemigroup `sm`, and an additive
subgroup `sa` such that `x ∈ s ↔ x ∈ sm ↔ x ∈ sa`. -/
protected def mk' (s : Set R) (sm : Subsemigroup R) (sa : AddSubgroup R) (hm : ↑sm = s)
(ha : ↑sa = s) : NonUnitalSubring R :=
{ sm.copy s hm.symm, sa.copy s ha.symm with }
@[simp]
theorem coe_mk' {s : Set R} {sm : Subsemigroup R} (hm : ↑sm = s) {sa : AddSubgroup R}
(ha : ↑sa = s) : (NonUnitalSubring.mk' s sm sa hm ha : Set R) = s :=
rfl
@[simp]
theorem mem_mk' {s : Set R} {sm : Subsemigroup R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s)
{x : R} : x ∈ NonUnitalSubring.mk' s sm sa hm ha ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem mk'_toSubsemigroup {s : Set R} {sm : Subsemigroup R} (hm : ↑sm = s) {sa : AddSubgroup R}
(ha : ↑sa = s) : (NonUnitalSubring.mk' s sm sa hm ha).toSubsemigroup = sm :=
SetLike.coe_injective hm.symm
@[simp]
theorem mk'_toAddSubgroup {s : Set R} {sm : Subsemigroup R} (hm : ↑sm = s) {sa : AddSubgroup R}
(ha : ↑sa = s) : (NonUnitalSubring.mk' s sm sa hm ha).toAddSubgroup = sa :=
SetLike.coe_injective ha.symm
end NonUnitalSubring
namespace NonUnitalSubring
variable (s : NonUnitalSubring R)
/-- A non-unital subring contains the ring's 0. -/
protected theorem zero_mem : (0 : R) ∈ s :=
zero_mem _
/-- A non-unital subring is closed under multiplication. -/
protected theorem mul_mem {x y : R} : x ∈ s → y ∈ s → x * y ∈ s :=
mul_mem
/-- A non-unital subring is closed under addition. -/
protected theorem add_mem {x y : R} : x ∈ s → y ∈ s → x + y ∈ s :=
add_mem
/-- A non-unital subring is closed under negation. -/
protected theorem neg_mem {x : R} : x ∈ s → -x ∈ s :=
neg_mem
/-- A non-unital subring is closed under subtraction -/
protected theorem sub_mem {x y : R} (hx : x ∈ s) (hy : y ∈ s) : x - y ∈ s :=
sub_mem hx hy
/-- Sum of a list of elements in a non-unital subring is in the non-unital subring. -/
protected theorem list_sum_mem {l : List R} : (∀ x ∈ l, x ∈ s) → l.sum ∈ s :=
list_sum_mem
/-- Sum of a multiset of elements in a `NonUnitalSubring` of a `NonUnitalRing` is
in the `NonUnitalSubring`. -/
protected theorem multiset_sum_mem {R} [NonUnitalNonAssocRing R] (s : NonUnitalSubring R)
(m : Multiset R) : (∀ a ∈ m, a ∈ s) → m.sum ∈ s :=
multiset_sum_mem _
/-- Sum of elements in a `NonUnitalSubring` of a `NonUnitalRing` indexed by a `Finset`
is in the `NonUnitalSubring`. -/
protected theorem sum_mem {R : Type*} [NonUnitalNonAssocRing R] (s : NonUnitalSubring R)
{ι : Type*} {t : Finset ι} {f : ι → R} (h : ∀ c ∈ t, f c ∈ s) : (∑ i in t, f i) ∈ s :=
sum_mem h
/-- A non-unital subring of a non-unital ring inherits a non-unital ring structure -/
instance toNonUnitalRing {R : Type*} [NonUnitalRing R] (s : NonUnitalSubring R) :
NonUnitalRing s :=
Subtype.coe_injective.nonUnitalRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl)
(fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl
protected theorem zsmul_mem {x : R} (hx : x ∈ s) (n : ℤ) : n • x ∈ s :=
zsmul_mem hx n
@[simp, norm_cast]
theorem val_add (x y : s) : (↑(x + y) : R) = ↑x + ↑y :=
rfl
@[simp, norm_cast]
theorem val_neg (x : s) : (↑(-x) : R) = -↑x :=
rfl
@[simp, norm_cast]
theorem val_mul (x y : s) : (↑(x * y) : R) = ↑x * ↑y :=
rfl
@[simp, norm_cast]
theorem val_zero : ((0 : s) : R) = 0 :=
rfl
theorem coe_eq_zero_iff {x : s} : (x : R) = 0 ↔ x = 0 := by
simp
/-- A non-unital subring of a `NonUnitalCommRing` is a `NonUnitalCommRing`. -/
instance toNonUnitalCommRing {R} [NonUnitalCommRing R] (s : NonUnitalSubring R) :
NonUnitalCommRing s :=
Subtype.coe_injective.nonUnitalCommRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl)
(fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl
/-! ## Partial order -/
@[simp]
theorem mem_toSubsemigroup {s : NonUnitalSubring R} {x : R} : x ∈ s.toSubsemigroup ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem coe_toSubsemigroup (s : NonUnitalSubring R) : (s.toSubsemigroup : Set R) = s :=
rfl
@[simp]
theorem mem_toAddSubgroup {s : NonUnitalSubring R} {x : R} : x ∈ s.toAddSubgroup ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem coe_toAddSubgroup (s : NonUnitalSubring R) : (s.toAddSubgroup : Set R) = s :=
rfl
@[simp]
theorem mem_toNonUnitalSubsemiring {s : NonUnitalSubring R} {x : R} :
x ∈ s.toNonUnitalSubsemiring ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem coe_toNonUnitalSubsemiring (s : NonUnitalSubring R) :
(s.toNonUnitalSubsemiring : Set R) = s :=
rfl
/-! ## top -/
/-- The non-unital subring `R` of the ring `R`. -/
instance : Top (NonUnitalSubring R) :=
⟨{ (⊤ : Subsemigroup R), (⊤ : AddSubgroup R) with }⟩
@[simp]
theorem mem_top (x : R) : x ∈ (⊤ : NonUnitalSubring R) :=
Set.mem_univ x
@[simp]
theorem coe_top : ((⊤ : NonUnitalSubring R) : Set R) = Set.univ :=
rfl
/-- The ring equiv between the top element of `NonUnitalSubring R` and `R`. -/
@[simps!]
def topEquiv : (⊤ : NonUnitalSubring R) ≃+* R := NonUnitalSubsemiring.topEquiv
end NonUnitalSubring
end Basic
section Hom
namespace NonUnitalSubring
variable {F : Type w} {R : Type u} {S : Type v} {T : Type*} {SR : Type*}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T]
[FunLike F R S] [NonUnitalRingHomClass F R S] (s : NonUnitalSubring R)
/-! ## comap -/
/-- The preimage of a `NonUnitalSubring` along a ring homomorphism is a `NonUnitalSubring`. -/
def comap {F : Type w} {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
[FunLike F R S] [NonUnitalRingHomClass F R S] (f : F) (s : NonUnitalSubring S) :
NonUnitalSubring R :=
{ s.toSubsemigroup.comap (f : R →ₙ* S), s.toAddSubgroup.comap (f : R →+ S) with
carrier := f ⁻¹' s.carrier }
@[simp]
theorem coe_comap (s : NonUnitalSubring S) (f : F) : (s.comap f : Set R) = f ⁻¹' s :=
rfl
@[simp]
theorem mem_comap {s : NonUnitalSubring S} {f : F} {x : R} : x ∈ s.comap f ↔ f x ∈ s :=
Iff.rfl
theorem comap_comap (s : NonUnitalSubring T) (g : S →ₙ+* T) (f : R →ₙ+* S) :
(s.comap g).comap f = s.comap (g.comp f) :=
rfl
/-! ## map -/
/-- The image of a `NonUnitalSubring` along a ring homomorphism is a `NonUnitalSubring`. -/
def map {F : Type w} {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
[FunLike F R S] [NonUnitalRingHomClass F R S] (f : F) (s : NonUnitalSubring R) :
NonUnitalSubring S :=
{ s.toSubsemigroup.map (f : R →ₙ* S), s.toAddSubgroup.map (f : R →+ S) with
carrier := f '' s.carrier }
@[simp]
theorem coe_map (f : F) (s : NonUnitalSubring R) : (s.map f : Set S) = f '' s :=
rfl
@[simp]
theorem mem_map {f : F} {s : NonUnitalSubring R} {y : S} : y ∈ s.map f ↔ ∃ x ∈ s, f x = y :=
Set.mem_image _ _ _
@[simp]
theorem map_id : s.map (NonUnitalRingHom.id R) = s :=
SetLike.coe_injective <| Set.image_id _
theorem map_map (g : S →ₙ+* T) (f : R →ₙ+* S) : (s.map f).map g = s.map (g.comp f) :=
SetLike.coe_injective <| Set.image_image _ _ _
theorem map_le_iff_le_comap {f : F} {s : NonUnitalSubring R} {t : NonUnitalSubring S} :
s.map f ≤ t ↔ s ≤ t.comap f :=
Set.image_subset_iff
theorem gc_map_comap (f : F) :
GaloisConnection (map f : NonUnitalSubring R → NonUnitalSubring S) (comap f) := fun _S _T =>
map_le_iff_le_comap
/-- A `NonUnitalSubring` is isomorphic to its image under an injective function -/
noncomputable def equivMapOfInjective (f : F) (hf : Function.Injective (f : R → S)) :
s ≃+* s.map f :=
{
Equiv.Set.image f s
hf with
map_mul' := fun _ _ => Subtype.ext (map_mul f _ _)
map_add' := fun _ _ => Subtype.ext (map_add f _ _) }
@[simp]
theorem coe_equivMapOfInjective_apply (f : F) (hf : Function.Injective f) (x : s) :
(equivMapOfInjective s f hf x : S) = f x :=
rfl
end NonUnitalSubring
namespace NonUnitalRingHom
variable {R : Type u} {S : Type v} {T : Type*}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T]
(g : S →ₙ+* T) (f : R →ₙ+* S)
/-! ## range -/
/-- The range of a ring homomorphism, as a `NonUnitalSubring` of the target.
See Note [range copy pattern]. -/
def range {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
(f : R →ₙ+* S) : NonUnitalSubring S :=
((⊤ : NonUnitalSubring R).map f).copy (Set.range f) Set.image_univ.symm
@[simp]
theorem coe_range : (f.range : Set S) = Set.range f :=
rfl
@[simp]
theorem mem_range {f : R →ₙ+* S} {y : S} : y ∈ f.range ↔ ∃ x, f x = y :=
Iff.rfl
theorem range_eq_map (f : R →ₙ+* S) : f.range = NonUnitalSubring.map f ⊤ := by ext; simp
theorem mem_range_self (f : R →ₙ+* S) (x : R) : f x ∈ f.range :=
mem_range.mpr ⟨x, rfl⟩
theorem map_range : f.range.map g = (g.comp f).range := by
simpa only [range_eq_map] using (⊤ : NonUnitalSubring R).map_map g f
/-- The range of a ring homomorphism is a fintype, if the domain is a fintype.
Note: this instance can form a diamond with `Subtype.fintype` in the
presence of `Fintype S`. -/
instance fintypeRange [Fintype R] [DecidableEq S] (f : R →ₙ+* S) : Fintype (range f) :=
Set.fintypeRange f
end NonUnitalRingHom
namespace NonUnitalSubring
section Order
variable {F : Type w} {R : Type u} {S : Type v} {T : Type*}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T]
[FunLike F R S] [NonUnitalRingHomClass F R S]
(g : S →ₙ+* T) (f : R →ₙ+* S)
/-! ## bot -/
instance : Bot (NonUnitalSubring R) :=
⟨(0 : R →ₙ+* R).range⟩
instance : Inhabited (NonUnitalSubring R) :=
⟨⊥⟩
theorem coe_bot : ((⊥ : NonUnitalSubring R) : Set R) = {0} :=
(NonUnitalRingHom.coe_range (0 : R →ₙ+* R)).trans (@Set.range_const R R _ 0)
theorem mem_bot {x : R} : x ∈ (⊥ : NonUnitalSubring R) ↔ x = 0 :=
show x ∈ ((⊥ : NonUnitalSubring R) : Set R) ↔ x = 0 by rw [coe_bot, Set.mem_singleton_iff]
/-! ## inf -/
/-- The inf of two `NonUnitalSubring`s is their intersection. -/
instance : Inf (NonUnitalSubring R) :=
⟨fun s t =>
{ s.toSubsemigroup ⊓ t.toSubsemigroup, s.toAddSubgroup ⊓ t.toAddSubgroup with
carrier := s ∩ t }⟩
@[simp]
theorem coe_inf (p p' : NonUnitalSubring R) :
((p ⊓ p' : NonUnitalSubring R) : Set R) = (p : Set R) ∩ p' :=
rfl
@[simp]
theorem mem_inf {p p' : NonUnitalSubring R} {x : R} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' :=
Iff.rfl
instance : InfSet (NonUnitalSubring R) :=
⟨fun s =>
NonUnitalSubring.mk' (⋂ t ∈ s, ↑t) (⨅ t ∈ s, NonUnitalSubring.toSubsemigroup t)
(⨅ t ∈ s, NonUnitalSubring.toAddSubgroup t) (by simp) (by simp)⟩
@[simp, norm_cast]
theorem coe_sInf (S : Set (NonUnitalSubring R)) :
((sInf S : NonUnitalSubring R) : Set R) = ⋂ s ∈ S, ↑s :=
rfl
theorem mem_sInf {S : Set (NonUnitalSubring R)} {x : R} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p :=
Set.mem_iInter₂
@[simp, norm_cast]
theorem coe_iInf {ι : Sort*} {S : ι → NonUnitalSubring R} : (↑(⨅ i, S i) : Set R) = ⋂ i, S i := by
simp only [iInf, coe_sInf, Set.biInter_range]
theorem mem_iInf {ι : Sort*} {S : ι → NonUnitalSubring R} {x : R} :
(x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range]
@[simp]
theorem sInf_toSubsemigroup (s : Set (NonUnitalSubring R)) :
(sInf s).toSubsemigroup = ⨅ t ∈ s, NonUnitalSubring.toSubsemigroup t :=
mk'_toSubsemigroup _ _
@[simp]
theorem sInf_toAddSubgroup (s : Set (NonUnitalSubring R)) :
(sInf s).toAddSubgroup = ⨅ t ∈ s, NonUnitalSubring.toAddSubgroup t :=
mk'_toAddSubgroup _ _
/-- `NonUnitalSubring`s of a ring form a complete lattice. -/
instance : CompleteLattice (NonUnitalSubring R) :=
{ completeLatticeOfInf (NonUnitalSubring R) fun _s =>
IsGLB.of_image (@fun _ _ : NonUnitalSubring R => SetLike.coe_subset_coe)
isGLB_biInf with
bot := ⊥
bot_le := fun s _x hx => (mem_bot.mp hx).symm ▸ zero_mem s
top := ⊤
le_top := fun _ _ _ => trivial
inf := (· ⊓ ·)
inf_le_left := fun _ _ _ => And.left
inf_le_right := fun _ _ _ => And.right
le_inf := fun _s _t₁ _t₂ h₁ h₂ _x hx => ⟨h₁ hx, h₂ hx⟩ }
theorem eq_top_iff' (A : NonUnitalSubring R) : A = ⊤ ↔ ∀ x : R, x ∈ A :=
eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩
end Order
/-! ## Center of a ring -/
section Center
variable {R : Type u}
section NonUnitalNonAssocRing
variable (R) [NonUnitalNonAssocRing R]
/-- The center of a ring `R` is the set of elements that commute with everything in `R` -/
def center : NonUnitalSubring R :=
{ NonUnitalSubsemiring.center R with
neg_mem' := Set.neg_mem_center }
theorem coe_center : ↑(center R) = Set.center R :=
rfl
@[simp]
theorem center_toNonUnitalSubsemiring :
(center R).toNonUnitalSubsemiring = NonUnitalSubsemiring.center R :=
rfl
/-- The center is commutative and associative. -/
instance center.instNonUnitalCommRing : NonUnitalCommRing (center R) :=
{ NonUnitalSubsemiring.center.instNonUnitalCommSemiring R,
inferInstanceAs <| NonUnitalNonAssocRing (center R) with }
end NonUnitalNonAssocRing
section NonUnitalRing
variable [NonUnitalRing R]
-- no instance diamond, unlike the unital version
example : (center.instNonUnitalCommRing _).toNonUnitalRing =
NonUnitalSubringClass.toNonUnitalRing (center R) := by
with_reducible_and_instances rfl
theorem mem_center_iff {z : R} : z ∈ center R ↔ ∀ g, g * z = z * g := Subsemigroup.mem_center_iff
instance decidableMemCenter [DecidableEq R] [Fintype R] : DecidablePred (· ∈ center R) := fun _ =>
decidable_of_iff' _ mem_center_iff
@[simp]
theorem center_eq_top (R) [NonUnitalCommRing R] : center R = ⊤ :=
SetLike.coe_injective (Set.center_eq_univ R)
end NonUnitalRing
end Center
/-! ## `NonUnitalSubring` closure of a subset -/
variable {F : Type w} {R : Type u} {S : Type v} {T : Type*}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T]
[FunLike F R S] [NonUnitalRingHomClass F R S]
(g : S →ₙ+* T) (f : R →ₙ+* S)
/-- The `NonUnitalSubring` generated by a set. -/
def closure (s : Set R) : NonUnitalSubring R :=
sInf {S | s ⊆ S}
theorem mem_closure {x : R} {s : Set R} : x ∈ closure s ↔ ∀ S : NonUnitalSubring R, s ⊆ S → x ∈ S :=
mem_sInf
/-- The `NonUnitalSubring` generated by a set includes the set. -/
@[simp, aesop safe 20 apply (rule_sets := [SetLike])]
theorem subset_closure {s : Set R} : s ⊆ closure s := fun _x hx => mem_closure.2 fun _S hS => hS hx
theorem not_mem_of_not_mem_closure {s : Set R} {P : R} (hP : P ∉ closure s) : P ∉ s := fun h =>
hP (subset_closure h)
/-- A `NonUnitalSubring` `t` includes `closure s` if and only if it includes `s`. -/
@[simp]
theorem closure_le {s : Set R} {t : NonUnitalSubring R} : closure s ≤ t ↔ s ⊆ t :=
⟨Set.Subset.trans subset_closure, fun h => sInf_le h⟩
/-- `NonUnitalSubring` closure of a set is monotone in its argument: if `s ⊆ t`,
then `closure s ≤ closure t`. -/
theorem closure_mono ⦃s t : Set R⦄ (h : s ⊆ t) : closure s ≤ closure t :=
closure_le.2 <| Set.Subset.trans h subset_closure
theorem closure_eq_of_le {s : Set R} {t : NonUnitalSubring R} (h₁ : s ⊆ t) (h₂ : t ≤ closure s) :
closure s = t :=
le_antisymm (closure_le.2 h₁) h₂
/-- An induction principle for closure membership. If `p` holds for `0`, `1`, and all elements
of `s`, and is preserved under addition, negation, and multiplication, then `p` holds for all
elements of the closure of `s`. -/
@[elab_as_elim]
theorem closure_induction {s : Set R} {p : R → Prop} {x} (h : x ∈ closure s) (mem : ∀ x ∈ s, p x)
(zero : p 0) (add : ∀ x y, p x → p y → p (x + y)) (neg : ∀ x : R, p x → p (-x))
(mul : ∀ x y, p x → p y → p (x * y)) : p x :=
(@closure_le _ _ _ ⟨⟨⟨⟨p, add _ _⟩, zero⟩, mul _ _⟩, neg _⟩).2 mem h
/-- The difference with `NonUnitalSubring.closure_induction` is that this acts on the
subtype. -/
@[elab_as_elim]
theorem closure_induction' {s : Set R} {p : closure s → Prop} (a : closure s)
(mem : ∀ (x) (hx : x ∈ s), p ⟨x, subset_closure hx⟩) (zero : p 0)
(add : ∀ x y, p x → p y → p (x + y)) (neg : ∀ x, p x → p (-x))
(mul : ∀ x y, p x → p y → p (x * y)) : p a :=
Subtype.recOn a fun b hb => by
refine' Exists.elim _ fun (hb : b ∈ closure s) (hc : p ⟨b, hb⟩) => hc
refine'
closure_induction hb (fun x hx => ⟨subset_closure hx, mem x hx⟩)
⟨zero_mem (closure s), zero⟩ _ _ _
· rintro x y ⟨hx, hpx⟩ ⟨hy, hpy⟩
exact ⟨add_mem hx hy, add _ _ hpx hpy⟩
· rintro x ⟨hx, hpx⟩
exact ⟨neg_mem hx, neg _ hpx⟩
· rintro x y ⟨hx, hpx⟩ ⟨hy, hpy⟩
exact ⟨mul_mem hx hy, mul _ _ hpx hpy⟩
/-- An induction principle for closure membership, for predicates with two arguments. -/
@[elab_as_elim]
theorem closure_induction₂ {s : Set R} {p : R → R → Prop} {a b : R} (ha : a ∈ closure s)
(hb : b ∈ closure s) (Hs : ∀ x ∈ s, ∀ y ∈ s, p x y) (H0_left : ∀ x, p 0 x)
(H0_right : ∀ x, p x 0) (Hneg_left : ∀ x y, p x y → p (-x) y)
(Hneg_right : ∀ x y, p x y → p x (-y)) (Hadd_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ + x₂) y)
(Hadd_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ + y₂))
(Hmul_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ * x₂) y)
(Hmul_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ * y₂)) : p a b := by
refine' closure_induction hb _ (H0_right _) (Hadd_right a) (Hneg_right a) (Hmul_right a)
refine' closure_induction ha Hs (fun x _ => H0_left x) _ _ _
· exact fun x y H₁ H₂ z zs => Hadd_left x y z (H₁ z zs) (H₂ z zs)
· exact fun x hx z zs => Hneg_left x z (hx z zs)
· exact fun x y H₁ H₂ z zs => Hmul_left x y z (H₁ z zs) (H₂ z zs)
theorem mem_closure_iff {s : Set R} {x} :
x ∈ closure s ↔ x ∈ AddSubgroup.closure (Subsemigroup.closure s : Set R) :=
⟨fun h =>
closure_induction h (fun x hx => AddSubgroup.subset_closure <| Subsemigroup.subset_closure hx)
(AddSubgroup.zero_mem _) (fun x y hx hy => AddSubgroup.add_mem _ hx hy)
(fun x hx => AddSubgroup.neg_mem _ hx) fun x y hx hy =>
AddSubgroup.closure_induction hy
(fun q hq =>
AddSubgroup.closure_induction hx
(fun p hp => AddSubgroup.subset_closure ((Subsemigroup.closure s).mul_mem hp hq))
(by rw [zero_mul q]; apply AddSubgroup.zero_mem _)
(fun p₁ p₂ ihp₁ ihp₂ => by rw [add_mul p₁ p₂ q]; apply AddSubgroup.add_mem _ ihp₁ ihp₂)
fun x hx => by
have f : -x * q = -(x * q) := by simp
rw [f]; apply AddSubgroup.neg_mem _ hx)
(by rw [mul_zero x]; apply AddSubgroup.zero_mem _)
(fun q₁ q₂ ihq₁ ihq₂ => by rw [mul_add x q₁ q₂]; apply AddSubgroup.add_mem _ ihq₁ ihq₂)
fun z hz => by
have f : x * -z = -(x * z) := by simp
rw [f]; apply AddSubgroup.neg_mem _ hz,
fun h =>
AddSubgroup.closure_induction h
(fun x hx =>
Subsemigroup.closure_induction hx (fun x hx => subset_closure hx) fun x y hx hy =>
mul_mem hx hy)
(zero_mem _) (fun x y hx hy => add_mem hx hy) fun x hx => neg_mem hx⟩
/-- If all elements of `s : Set A` commute pairwise, then `closure s` is a commutative ring. -/
def closureNonUnitalCommRingOfComm {R : Type u} [NonUnitalRing R] {s : Set R}
(hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) : NonUnitalCommRing (closure s) :=
{ (closure s).toNonUnitalRing with
mul_comm := fun x y => by
ext
simp only [NonUnitalSubring.val_mul]
refine'
closure_induction₂ x.prop y.prop hcomm
(fun x => by simp only [mul_zero, zero_mul])
(fun x => by simp only [mul_zero, zero_mul])
(fun x y hxy => by simp only [mul_neg, neg_mul, hxy])
(fun x y hxy => by simp only [mul_neg, neg_mul, hxy])
(fun x₁ x₂ y h₁ h₂ => by simp only [add_mul, mul_add, h₁, h₂])
(fun x₁ x₂ y h₁ h₂ => by simp only [add_mul, mul_add, h₁, h₂])
(fun x₁ x₂ y h₁ h₂ => by rw [← mul_assoc, ← h₁, mul_assoc x₁ y x₂, ← h₂, mul_assoc])
fun x₁ x₂ y h₁ h₂ => by rw [← mul_assoc, h₁, mul_assoc, h₂, ← mul_assoc] }
variable (R)
/-- `closure` forms a Galois insertion with the coercion to set. -/
protected def gi : GaloisInsertion (@closure R _) SetLike.coe
where
choice s _ := closure s
gc _s _t := closure_le
le_l_u _s := subset_closure
choice_eq _s _h := rfl
variable {R}
/-- Closure of a `NonUnitalSubring` `S` equals `S`. -/
theorem closure_eq (s : NonUnitalSubring R) : closure (s : Set R) = s :=
(NonUnitalSubring.gi R).l_u_eq s
@[simp]
theorem closure_empty : closure (∅ : Set R) = ⊥ :=
(NonUnitalSubring.gi R).gc.l_bot
@[simp]
theorem closure_univ : closure (Set.univ : Set R) = ⊤ :=
@coe_top R _ ▸ closure_eq ⊤
theorem closure_union (s t : Set R) : closure (s ∪ t) = closure s ⊔ closure t :=
(NonUnitalSubring.gi R).gc.l_sup
theorem closure_iUnion {ι} (s : ι → Set R) : closure (⋃ i, s i) = ⨆ i, closure (s i) :=
(NonUnitalSubring.gi R).gc.l_iSup
theorem closure_sUnion (s : Set (Set R)) : closure (⋃₀ s) = ⨆ t ∈ s, closure t :=
(NonUnitalSubring.gi R).gc.l_sSup
theorem map_sup (s t : NonUnitalSubring R) (f : F) : (s ⊔ t).map f = s.map f ⊔ t.map f :=
(gc_map_comap f).l_sup
theorem map_iSup {ι : Sort*} (f : F) (s : ι → NonUnitalSubring R) :
(iSup s).map f = ⨆ i, (s i).map f :=
(gc_map_comap f).l_iSup
theorem comap_inf (s t : NonUnitalSubring S) (f : F) : (s ⊓ t).comap f = s.comap f ⊓ t.comap f :=
(gc_map_comap f).u_inf
theorem comap_iInf {ι : Sort*} (f : F) (s : ι → NonUnitalSubring S) :
(iInf s).comap f = ⨅ i, (s i).comap f :=
(gc_map_comap f).u_iInf
@[simp]
theorem map_bot (f : R →ₙ+* S) : (⊥ : NonUnitalSubring R).map f = ⊥ :=
(gc_map_comap f).l_bot
@[simp]
theorem comap_top (f : R →ₙ+* S) : (⊤ : NonUnitalSubring S).comap f = ⊤ :=
(gc_map_comap f).u_top
/-- Given `NonUnitalSubring`s `s`, `t` of rings `R`, `S` respectively, `s.prod t` is `s ×ˢ t`
as a `NonUnitalSubring` of `R × S`. -/
def prod (s : NonUnitalSubring R) (t : NonUnitalSubring S) : NonUnitalSubring (R × S) :=
{ s.toSubsemigroup.prod t.toSubsemigroup, s.toAddSubgroup.prod t.toAddSubgroup with
carrier := s ×ˢ t }
@[norm_cast]
theorem coe_prod (s : NonUnitalSubring R) (t : NonUnitalSubring S) :
(s.prod t : Set (R × S)) = (s : Set R) ×ˢ t :=
rfl
theorem mem_prod {s : NonUnitalSubring R} {t : NonUnitalSubring S} {p : R × S} :
p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t :=
Iff.rfl
@[mono]
theorem prod_mono ⦃s₁ s₂ : NonUnitalSubring R⦄ (hs : s₁ ≤ s₂) ⦃t₁ t₂ : NonUnitalSubring S⦄
(ht : t₁ ≤ t₂) : s₁.prod t₁ ≤ s₂.prod t₂ :=
Set.prod_mono hs ht
theorem prod_mono_right (s : NonUnitalSubring R) :
Monotone fun t : NonUnitalSubring S => s.prod t :=
prod_mono (le_refl s)
theorem prod_mono_left (t : NonUnitalSubring S) : Monotone fun s : NonUnitalSubring R => s.prod t :=
fun _s₁ _s₂ hs => prod_mono hs (le_refl t)
theorem prod_top (s : NonUnitalSubring R) :
s.prod (⊤ : NonUnitalSubring S) = s.comap (NonUnitalRingHom.fst R S) :=
ext fun x => by simp [mem_prod, MonoidHom.coe_fst]
theorem top_prod (s : NonUnitalSubring S) :
(⊤ : NonUnitalSubring R).prod s = s.comap (NonUnitalRingHom.snd R S) :=
ext fun x => by simp [mem_prod, MonoidHom.coe_snd]
@[simp]
theorem top_prod_top : (⊤ : NonUnitalSubring R).prod (⊤ : NonUnitalSubring S) = ⊤ :=
(top_prod _).trans <| comap_top _
/-- Product of `NonUnitalSubring`s is isomorphic to their product as rings. -/
def prodEquiv (s : NonUnitalSubring R) (t : NonUnitalSubring S) : s.prod t ≃+* s × t :=
{ Equiv.Set.prod (s : Set R) (t : Set S) with
map_mul' := fun _ _ => rfl
map_add' := fun _ _ => rfl }
/-- The underlying set of a non-empty directed Sup of `NonUnitalSubring`s is just a union of the
`NonUnitalSubring`s. Note that this fails without the directedness assumption (the union of two
`NonUnitalSubring`s is typically not a `NonUnitalSubring`) -/
theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → NonUnitalSubring R}
(hS : Directed (· ≤ ·) S) {x : R} : (x ∈ ⨆ i, S i) ↔ ∃ i, x ∈ S i := by
refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩
let U : NonUnitalSubring R :=
NonUnitalSubring.mk' (⋃ i, (S i : Set R)) (⨆ i, (S i).toSubsemigroup) (⨆ i, (S i).toAddSubgroup)
(Subsemigroup.coe_iSup_of_directed hS) (AddSubgroup.coe_iSup_of_directed hS)
suffices ⨆ i, S i ≤ U by simpa [U] using @this x
exact iSup_le fun i x hx ↦ Set.mem_iUnion.2 ⟨i, hx⟩
theorem coe_iSup_of_directed {ι} [Nonempty ι] {S : ι → NonUnitalSubring R}
(hS : Directed (· ≤ ·) S) : ((⨆ i, S i : NonUnitalSubring R) : Set R) = ⋃ i, S i :=
Set.ext fun x ↦ by simp [mem_iSup_of_directed hS]
theorem mem_sSup_of_directedOn {S : Set (NonUnitalSubring R)} (Sne : S.Nonempty)
(hS : DirectedOn (· ≤ ·) S) {x : R} : x ∈ sSup S ↔ ∃ s ∈ S, x ∈ s := by
haveI : Nonempty S := Sne.to_subtype
simp only [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, SetCoe.exists, Subtype.coe_mk,
exists_prop]
theorem coe_sSup_of_directedOn {S : Set (NonUnitalSubring R)} (Sne : S.Nonempty)
(hS : DirectedOn (· ≤ ·) S) : (↑(sSup S) : Set R) = ⋃ s ∈ S, ↑s :=
Set.ext fun x => by simp [mem_sSup_of_directedOn Sne hS]
theorem mem_map_equiv {f : R ≃+* S} {K : NonUnitalSubring R} {x : S} :
x ∈ K.map (f : R →ₙ+* S) ↔ f.symm x ∈ K :=
@Set.mem_image_equiv _ _ (K : Set R) f.toEquiv x
theorem map_equiv_eq_comap_symm (f : R ≃+* S) (K : NonUnitalSubring R) :
K.map (f : R →ₙ+* S) = K.comap f.symm :=
SetLike.coe_injective (f.toEquiv.image_eq_preimage K)
theorem comap_equiv_eq_map_symm (f : R ≃+* S) (K : NonUnitalSubring S) :
K.comap (f : R →ₙ+* S) = K.map f.symm :=
(map_equiv_eq_comap_symm f.symm K).symm
end NonUnitalSubring
namespace NonUnitalRingHom
variable {F : Type w} {R : Type u} {S : Type v} {T : Type*}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T]
[FunLike F R S] [NonUnitalRingHomClass F R S]
(g : S →ₙ+* T) (f : R →ₙ+* S)
{s : NonUnitalSubring R}
open NonUnitalSubring
/-- Restriction of a ring homomorphism to its range interpreted as a `NonUnitalSubring`.
This is the bundled version of `Set.rangeFactorization`. -/
def rangeRestrict (f : R →ₙ+* S) : R →ₙ+* f.range :=
NonUnitalRingHom.codRestrict f f.range fun x => ⟨x, rfl⟩
@[simp]
theorem coe_rangeRestrict (f : R →ₙ+* S) (x : R) : (f.rangeRestrict x : S) = f x :=
rfl
theorem rangeRestrict_surjective (f : R →ₙ+* S) : Function.Surjective f.rangeRestrict :=
fun ⟨_y, hy⟩ =>
let ⟨x, hx⟩ := mem_range.mp hy
⟨x, Subtype.ext hx⟩
theorem range_top_iff_surjective {f : R →ₙ+* S} :
f.range = (⊤ : NonUnitalSubring S) ↔ Function.Surjective f :=
SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_range, coe_top]) Set.range_iff_surjective
/-- The range of a surjective ring homomorphism is the whole of the codomain. -/
@[simp]
theorem range_top_of_surjective (f : R →ₙ+* S) (hf : Function.Surjective f) :
f.range = (⊤ : NonUnitalSubring S) :=
range_top_iff_surjective.2 hf
/-- The `NonUnitalSubring` of elements `x : R` such that `f x = g x`, i.e.,
the equalizer of f and g as a `NonUnitalSubring` of R -/
def eqLocus (f g : R →ₙ+* S) : NonUnitalSubring R :=
{ (f : R →ₙ* S).eqLocus g, (f : R →+ S).eqLocus g with carrier := {x | f x = g x} }
@[simp]
theorem eqLocus_same (f : R →ₙ+* S) : f.eqLocus f = ⊤ :=
SetLike.ext fun _ => eq_self_iff_true _
/-- If two ring homomorphisms are equal on a set, then they are equal on its
`NonUnitalSubring` closure. -/
theorem eqOn_set_closure {f g : R →ₙ+* S} {s : Set R} (h : Set.EqOn f g s) :
Set.EqOn f g (closure s) :=
show closure s ≤ f.eqLocus g from closure_le.2 h
theorem eq_of_eqOn_set_top {f g : R →ₙ+* S} (h : Set.EqOn f g (⊤ : NonUnitalSubring R)) : f = g :=
ext fun _x => h trivial
theorem eq_of_eqOn_set_dense {s : Set R} (hs : closure s = ⊤) {f g : R →ₙ+* S} (h : s.EqOn f g) :
f = g :=
eq_of_eqOn_set_top <| hs ▸ eqOn_set_closure h
theorem closure_preimage_le (f : R →ₙ+* S) (s : Set S) : closure (f ⁻¹' s) ≤ (closure s).comap f :=
closure_le.2 fun _x hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx
/-- The image under a ring homomorphism of the `NonUnitalSubring` generated by a set equals
the `NonUnitalSubring` generated by the image of the set. -/
theorem map_closure (f : R →ₙ+* S) (s : Set R) : (closure s).map f = closure (f '' s) :=
le_antisymm
(map_le_iff_le_comap.2 <|
le_trans (closure_mono <| Set.subset_preimage_image _ _) (closure_preimage_le _ _))
(closure_le.2 <| Set.image_subset _ subset_closure)
end NonUnitalRingHom
namespace NonUnitalSubring
variable {F : Type w} {R : Type u} {S : Type v} {T : Type*}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T]
[FunLike F R S] [NonUnitalRingHomClass F R S]
(g : S →ₙ+* T) (f : R →ₙ+* S)
{s : NonUnitalSubring R}
open NonUnitalRingHom
/-- The ring homomorphism associated to an inclusion of `NonUnitalSubring`s. -/
def inclusion {S T : NonUnitalSubring R} (h : S ≤ T) : S →ₙ+* T :=
NonUnitalRingHom.codRestrict (NonUnitalSubringClass.subtype S) _ fun x => h x.2
@[simp]
theorem range_subtype (s : NonUnitalSubring R) : (NonUnitalSubringClass.subtype s).range = s :=
SetLike.coe_injective <| (coe_srange _).trans Subtype.range_coe
theorem range_fst : NonUnitalRingHom.srange (fst R S) = ⊤ :=
NonUnitalSubsemiring.range_fst
theorem range_snd : NonUnitalRingHom.srange (snd R S) = ⊤ :=
NonUnitalSubsemiring.range_snd