diff --git "a/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_Algebra_Subalgebra_Basic.jsonl" "b/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_Algebra_Subalgebra_Basic.jsonl" deleted file mode 100644--- "a/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_Algebra_Subalgebra_Basic.jsonl" +++ /dev/null @@ -1,133 +0,0 @@ -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\np q : Subalgebra R A\nh : (fun s => s.carrier) p = (fun s => s.carrier) q\n⊢ p = q","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by ","nextTactic":"cases p","declUpToTactic":"instance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.46_0.BO9UEYMCHxKwTRD","decl":"instance : SetLike (Subalgebra R A) A where\n coe s "} -{"state":"case mk\nR' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nq : Subalgebra R A\ntoSubsemiring✝ : Subsemiring A\nalgebraMap_mem'✝ : ∀ (r : R), (algebraMap R A) r ∈ toSubsemiring✝.carrier\nh :\n (fun s => s.carrier) { toSubsemiring := toSubsemiring✝, algebraMap_mem' := algebraMap_mem'✝ } = (fun s => s.carrier) q\n⊢ { toSubsemiring := toSubsemiring✝, algebraMap_mem' := algebraMap_mem'✝ } = q","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; ","nextTactic":"cases q","declUpToTactic":"instance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.46_0.BO9UEYMCHxKwTRD","decl":"instance : SetLike (Subalgebra R A) A where\n coe s "} -{"state":"case mk.mk\nR' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\ntoSubsemiring✝¹ : Subsemiring A\nalgebraMap_mem'✝¹ : ∀ (r : R), (algebraMap R A) r ∈ toSubsemiring✝¹.carrier\ntoSubsemiring✝ : Subsemiring A\nalgebraMap_mem'✝ : ∀ (r : R), (algebraMap R A) r ∈ toSubsemiring✝.carrier\nh :\n (fun s => s.carrier) { toSubsemiring := toSubsemiring✝¹, algebraMap_mem' := algebraMap_mem'✝¹ } =\n (fun s => s.carrier) { toSubsemiring := toSubsemiring✝, algebraMap_mem' := algebraMap_mem'✝ }\n⊢ { toSubsemiring := toSubsemiring✝¹, algebraMap_mem' := algebraMap_mem'✝¹ } =\n { toSubsemiring := toSubsemiring✝, algebraMap_mem' := algebraMap_mem'✝ }","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; ","nextTactic":"congr","declUpToTactic":"instance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.46_0.BO9UEYMCHxKwTRD","decl":"instance : SetLike (Subalgebra R A) A where\n coe s "} -{"state":"case mk.mk.e_toSubsemiring\nR' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\ntoSubsemiring✝¹ : Subsemiring A\nalgebraMap_mem'✝¹ : ∀ (r : R), (algebraMap R A) r ∈ toSubsemiring✝¹.carrier\ntoSubsemiring✝ : Subsemiring A\nalgebraMap_mem'✝ : ∀ (r : R), (algebraMap R A) r ∈ toSubsemiring✝.carrier\nh :\n (fun s => s.carrier) { toSubsemiring := toSubsemiring✝¹, algebraMap_mem' := algebraMap_mem'✝¹ } =\n (fun s => s.carrier) { toSubsemiring := toSubsemiring✝, algebraMap_mem' := algebraMap_mem'✝ }\n⊢ toSubsemiring✝¹ = toSubsemiring✝","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; ","nextTactic":"exact SetLike.coe_injective' h","declUpToTactic":"instance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.46_0.BO9UEYMCHxKwTRD","decl":"instance : SetLike (Subalgebra R A) A where\n coe s "} -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nS T : Subalgebra R A\nh : S.toSubsemiring = T.toSubsemiring\nx : A\n⊢ x ∈ S ↔ x ∈ T","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by ","nextTactic":"rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]","declUpToTactic":"theorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.76_0.BO9UEYMCHxKwTRD","decl":"theorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) "} -{"state":"R' : Type u'\nR✝ : Type u\nA✝ : Type v\nB : Type w\nC : Type w'\ninst✝⁹ : CommSemiring R✝\ninst✝⁸ : Semiring A✝\ninst✝⁷ : Algebra R✝ A✝\ninst✝⁶ : Semiring B\ninst✝⁵ : Algebra R✝ B\ninst✝⁴ : Semiring C\ninst✝³ : Algebra R✝ C\nS✝ : Subalgebra R✝ A✝\nR : Type u\nA : Type v\ninst✝² : CommRing R\ninst✝¹ : Ring A\ninst✝ : Algebra R A\nS T : Subalgebra R A\nh : toSubring S = toSubring T\nx : A\n⊢ x ∈ S ↔ x ∈ T","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by ","nextTactic":"rw [← mem_toSubring, ← mem_toSubring, h]","declUpToTactic":"theorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.244_0.BO9UEYMCHxKwTRD","decl":"theorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) "} -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝¹⁰ : CommSemiring R\ninst✝⁹ : Semiring A\ninst✝⁸ : Algebra R A\ninst✝⁷ : Semiring B\ninst✝⁶ : Algebra R B\ninst✝⁵ : Semiring C\ninst✝⁴ : Algebra R C\nS : Subalgebra R A\ninst✝³ : CommSemiring R'\ninst✝² : SMul R' R\ninst✝¹ : Algebra R' A\ninst✝ : IsScalarTower R' R A\nx : R'\n⊢ (algebraMap R' A) x ∈ S","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n ","nextTactic":"rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]","declUpToTactic":"instance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.373_0.BO9UEYMCHxKwTRD","decl":"instance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S "} -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝¹⁰ : CommSemiring R\ninst✝⁹ : Semiring A\ninst✝⁸ : Algebra R A\ninst✝⁷ : Semiring B\ninst✝⁶ : Algebra R B\ninst✝⁵ : Semiring C\ninst✝⁴ : Algebra R C\nS : Subalgebra R A\ninst✝³ : CommSemiring R'\ninst✝² : SMul R' R\ninst✝¹ : Algebra R' A\ninst✝ : IsScalarTower R' R A\nx : R'\n⊢ (algebraMap R A) (x • 1) ∈ S","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n ","nextTactic":"exact algebraMap_mem S\n _","declUpToTactic":"instance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.373_0.BO9UEYMCHxKwTRD","decl":"instance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S "} -{"state":"R : Type u_1\nA : Type u_2\ninst✝² : CommSemiring R\ninst✝¹ : Semiring A\ninst✝ : Algebra R A\np✝ p : Submodule R A\nh_one : 1 ∈ p\nh_mul : ∀ (x y : A), x ∈ p → y ∈ p → x * y ∈ p\nr : R\n⊢ (algebraMap R A) r ∈\n {\n toSubmonoid :=\n {\n toSubsemigroup :=\n { carrier := p.carrier, mul_mem' := (_ : ∀ {a b : A}, a ∈ p.carrier → b ∈ p.carrier → a * b ∈ p) },\n one_mem' := h_one },\n add_mem' := (_ : ∀ {a b : A}, a ∈ p.carrier → b ∈ p.carrier → a + b ∈ p.carrier),\n zero_mem' := (_ : 0 ∈ p.carrier) }.toSubmonoid.toSubsemigroup.carrier","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n ","nextTactic":"rw [Algebra.algebraMap_eq_smul_one]","declUpToTactic":"/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.558_0.BO9UEYMCHxKwTRD","decl":"/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A "} -{"state":"R : Type u_1\nA : Type u_2\ninst✝² : CommSemiring R\ninst✝¹ : Semiring A\ninst✝ : Algebra R A\np✝ p : Submodule R A\nh_one : 1 ∈ p\nh_mul : ∀ (x y : A), x ∈ p → y ∈ p → x * y ∈ p\nr : R\n⊢ r • 1 ∈\n {\n toSubmonoid :=\n {\n toSubsemigroup :=\n { carrier := p.carrier, mul_mem' := (_ : ∀ {a b : A}, a ∈ p.carrier → b ∈ p.carrier → a * b ∈ p) },\n one_mem' := h_one },\n add_mem' := (_ : ∀ {a b : A}, a ∈ p.carrier → b ∈ p.carrier → a + b ∈ p.carrier),\n zero_mem' := (_ : 0 ∈ p.carrier) }.toSubmonoid.toSubsemigroup.carrier","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n ","nextTactic":"exact p.smul_mem _ h_one","declUpToTactic":"/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.558_0.BO9UEYMCHxKwTRD","decl":"/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A "} -{"state":"R : Type u_1\nA : Type u_2\ninst✝² : CommSemiring R\ninst✝¹ : Semiring A\ninst✝ : Algebra R A\np s : Submodule R A\nh1 : 1 ∈ s\nhmul : ∀ (x y : A), x ∈ s → y ∈ s → x * y ∈ s\n⊢ ∀ (r : R),\n (algebraMap R A) r ∈\n { toSubmonoid := { toSubsemigroup := { carrier := ↑s, mul_mem' := hmul }, one_mem' := h1 },\n add_mem' := (_ : ∀ {a b : A}, a ∈ s → b ∈ s → a + b ∈ s),\n zero_mem' := (_ : 0 ∈ s) }.toSubmonoid.toSubsemigroup.carrier","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by ","nextTactic":"intro r","declUpToTactic":"theorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.581_0.BO9UEYMCHxKwTRD","decl":"theorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) "} -{"state":"R : Type u_1\nA : Type u_2\ninst✝² : CommSemiring R\ninst✝¹ : Semiring A\ninst✝ : Algebra R A\np s : Submodule R A\nh1 : 1 ∈ s\nhmul : ∀ (x y : A), x ∈ s → y ∈ s → x * y ∈ s\nr : R\n⊢ (algebraMap R A) r ∈\n { toSubmonoid := { toSubsemigroup := { carrier := ↑s, mul_mem' := hmul }, one_mem' := h1 },\n add_mem' := (_ : ∀ {a b : A}, a ∈ s → b ∈ s → a + b ∈ s),\n zero_mem' := (_ : 0 ∈ s) }.toSubmonoid.toSubsemigroup.carrier","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; ","nextTactic":"rw [Algebra.algebraMap_eq_smul_one]","declUpToTactic":"theorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.581_0.BO9UEYMCHxKwTRD","decl":"theorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) "} -{"state":"R : Type u_1\nA : Type u_2\ninst✝² : CommSemiring R\ninst✝¹ : Semiring A\ninst✝ : Algebra R A\np s : Submodule R A\nh1 : 1 ∈ s\nhmul : ∀ (x y : A), x ∈ s → y ∈ s → x * y ∈ s\nr : R\n⊢ r • 1 ∈\n { toSubmonoid := { toSubsemigroup := { carrier := ↑s, mul_mem' := hmul }, one_mem' := h1 },\n add_mem' := (_ : ∀ {a b : A}, a ∈ s → b ∈ s → a + b ∈ s),\n zero_mem' := (_ : 0 ∈ s) }.toSubmonoid.toSubsemigroup.carrier","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x �� s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; ","nextTactic":"apply s.smul_mem _ h1","declUpToTactic":"theorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.581_0.BO9UEYMCHxKwTRD","decl":"theorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) "} -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nφ✝ φ : A →ₐ[R] B\n⊢ ↑(AlgHom.range φ) = Set.range ⇑φ","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ","nextTactic":"ext","declUpToTactic":"@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.626_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ "} -{"state":"case h\nR' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nφ✝ φ : A →ₐ[R] B\nx✝ : B\n⊢ x✝ ∈ ↑(AlgHom.range φ) ↔ x✝ ∈ Set.range ⇑φ","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n ","nextTactic":"rw [SetLike.mem_coe]","declUpToTactic":"@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.626_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ "} -{"state":"case h\nR' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nφ✝ φ : A →ₐ[R] B\nx✝ : B\n⊢ x✝ ∈ AlgHom.range φ ↔ x✝ ∈ Set.range ⇑φ","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ��� S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n ","nextTactic":"rw [mem_range]","declUpToTactic":"@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.626_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ "} -{"state":"case h\nR' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nφ✝ φ : A →ₐ[R] B\nx✝ : B\n⊢ (∃ x, φ x = x✝) ↔ x✝ ∈ Set.range ⇑φ","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n ","nextTactic":"rfl","declUpToTactic":"@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.626_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ "} -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nφ ϕ ψ : A →ₐ[R] B\nx y : A\nhx : ϕ x = ψ x\nhy : ϕ y = ψ y\n⊢ x * y ∈ {a | ϕ a = ψ a}","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n ","nextTactic":"rw [Set.mem_setOf_eq]","declUpToTactic":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.672_0.BO9UEYMCHxKwTRD","decl":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier "} -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nφ ϕ ψ : A →ₐ[R] B\nx y : A\nhx : ϕ x = ψ x\nhy : ϕ y = ψ y\n⊢ ϕ (x * y) = ψ (x * y)","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n ","nextTactic":"rw [ϕ.map_mul]","declUpToTactic":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.672_0.BO9UEYMCHxKwTRD","decl":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier "} -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nφ ϕ ψ : A →ₐ[R] B\nx y : A\nhx : ϕ x = ψ x\nhy : ϕ y = ψ y\n⊢ ϕ x * ϕ y = ψ (x * y)","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n ","nextTactic":"rw [ψ.map_mul]","declUpToTactic":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.672_0.BO9UEYMCHxKwTRD","decl":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier "} -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nφ ϕ ψ : A →ₐ[R] B\nx y : A\nhx : ϕ x = ψ x\nhy : ϕ y = ψ y\n⊢ ϕ x * ϕ y = ψ x * ψ y","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n ","nextTactic":"rw [hx]","declUpToTactic":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.672_0.BO9UEYMCHxKwTRD","decl":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier "} -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nφ ϕ ψ : A →ₐ[R] B\nx y : A\nhx : ϕ x = ψ x\nhy : ϕ y = ψ y\n⊢ ψ x * ϕ y = ψ x * ψ y","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n ","nextTactic":"rw [hy]","declUpToTactic":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.672_0.BO9UEYMCHxKwTRD","decl":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier "} -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nφ ϕ ψ : A →ₐ[R] B\n⊢ 1 ∈\n { carrier := {a | ϕ a = ψ a},\n mul_mem' := (_ : ∀ {x y : A}, ϕ x = ψ x → ϕ y = ψ y → x * y ∈ {a | ϕ a = ψ a}) }.carrier","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by ","nextTactic":"simp only [Set.mem_setOf_eq, map_one]","declUpToTactic":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.672_0.BO9UEYMCHxKwTRD","decl":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier "} -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nφ ϕ ψ : A →ₐ[R] B\nx y : A\nhx : ϕ x = ψ x\nhy : ϕ y = ψ y\n⊢ x + y ∈\n {\n toSubsemigroup :=\n { carrier := {a | ϕ a = ψ a},\n mul_mem' := (_ : ∀ {x y : A}, ϕ x = ψ x → ϕ y = ψ y → x * y ∈ {a | ϕ a = ψ a}) },\n one_mem' := (_ : ϕ 1 = ψ 1) }.toSubsemigroup.carrier","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = �� a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n ","nextTactic":"rw [Set.mem_setOf_eq]","declUpToTactic":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.672_0.BO9UEYMCHxKwTRD","decl":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier "} -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nφ ϕ ψ : A →ₐ[R] B\nx y : A\nhx : ϕ x = ψ x\nhy : ϕ y = ψ y\n⊢ ϕ (x + y) = ψ (x + y)","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n ","nextTactic":"rw [ϕ.map_add]","declUpToTactic":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.672_0.BO9UEYMCHxKwTRD","decl":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier "} -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nφ ϕ ψ : A →ₐ[R] B\nx y : A\nhx : ϕ x = ψ x\nhy : ϕ y = ψ y\n⊢ ϕ x + ϕ y = ψ (x + y)","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n ","nextTactic":"rw [ψ.map_add]","declUpToTactic":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.672_0.BO9UEYMCHxKwTRD","decl":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier "} -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nφ ϕ ψ : A →ₐ[R] B\nx y : A\nhx : ϕ x = ψ x\nhy : ϕ y = ψ y\n⊢ ϕ x + ϕ y = ψ x + ψ y","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n ","nextTactic":"rw [hx]","declUpToTactic":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.672_0.BO9UEYMCHxKwTRD","decl":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier "} -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nφ ϕ ψ : A →ₐ[R] B\nx y : A\nhx : ϕ x = ψ x\nhy : ϕ y = ψ y\n⊢ ψ x + ϕ y = ψ x + ψ y","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n ","nextTactic":"rw [hy]","declUpToTactic":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.672_0.BO9UEYMCHxKwTRD","decl":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier "} -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nφ ϕ ψ : A →ₐ[R] B\n⊢ 0 ∈\n {\n toSubsemigroup :=\n { carrier := {a | ϕ a = ψ a},\n mul_mem' := (_ : ∀ {x y : A}, ϕ x = ψ x → ϕ y = ψ y → x * y ∈ {a | ϕ a = ψ a}) },\n one_mem' := (_ : ϕ 1 = ψ 1) }.toSubsemigroup.carrier","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by ","nextTactic":"simp only [Set.mem_setOf_eq, map_zero]","declUpToTactic":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.672_0.BO9UEYMCHxKwTRD","decl":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier "} -{"state":"R' : Type u'\nR : Type u\nA : Type v\nB : Type w\nC : Type w'\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\ninst✝¹ : Semiring C\ninst✝ : Algebra R C\nφ ϕ ψ : A →ₐ[R] B\nx : R\n⊢ (algebraMap R A) x ∈\n {\n toSubmonoid :=\n {\n toSubsemigroup :=\n { carrier := {a | ϕ a = ψ a},\n mul_mem' := (_ : ∀ {x y : A}, ϕ x = ψ x → ϕ y = ψ y → x * y ∈ {a | ϕ a = ψ a}) },\n one_mem' := (_ : ϕ 1 = ψ 1) },\n add_mem' :=\n (_ :\n ∀ {x y : A},\n ϕ x = ψ x →\n ϕ y = ψ y →\n x + y ∈\n {\n toSubsemigroup :=\n { carrier := {a | ϕ a = ψ a},\n mul_mem' := (_ : ∀ {x y : A}, ϕ x = ψ x → ϕ y = ψ y → x * y ∈ {a | ϕ a = ψ a}) },\n one_mem' := (_ : ϕ 1 = ψ 1) }.toSubsemigroup.carrier),\n zero_mem' := (_ : ϕ 0 = ψ 0) }.toSubmonoid.toSubsemigroup.carrier","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by ","nextTactic":"rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]","declUpToTactic":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.672_0.BO9UEYMCHxKwTRD","decl":"/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst��² : Semiring B\ninst✝¹ : Algebra R A\ninst✝ : Algebra R B\ng : B → A\nf : A →ₐ[R] B\nh : Function.LeftInverse g ⇑f\nsrc✝ : A →ₐ[R] ↥(AlgHom.range f) := AlgHom.rangeRestrict f\nx : ↥(AlgHom.range f)\nx' : A\nhx' : f x' = ↑x\n⊢ f (g ↑x) = ↑x","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by ","nextTactic":"rw [← hx', h x']","declUpToTactic":"/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.712_0.BO9UEYMCHxKwTRD","decl":"/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Semiring B\ninst✝¹ : Algebra R A\ninst✝ : Algebra R B\ne : A ≃ₐ[R] B\nS : Subalgebra R A\nsrc✝ : ↥S.toSubsemiring ≃+* ↥(Subsemiring.map (RingEquiv.toRingHom (toRingEquiv e)) S.toSubsemiring) :=\n RingEquiv.subsemiringMap (toRingEquiv e) S.toSubsemiring\nr : R\n⊢ Equiv.toFun src✝.toEquiv ((algebraMap R ↥S) r) = (algebraMap R ↥(Subalgebra.map (↑e) S)) r","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B ��� A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ","nextTactic":"ext","declUpToTactic":"/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.755_0.BO9UEYMCHxKwTRD","decl":"/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) "} -{"state":"case a\nR : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Semiring B\ninst✝¹ : Algebra R A\ninst✝ : Algebra R B\ne : A ≃ₐ[R] B\nS : Subalgebra R A\nsrc✝ : ↥S.toSubsemiring ≃+* ↥(Subsemiring.map (RingEquiv.toRingHom (toRingEquiv e)) S.toSubsemiring) :=\n RingEquiv.subsemiringMap (toRingEquiv e) S.toSubsemiring\nr : R\n⊢ ↑(Equiv.toFun src✝.toEquiv ((algebraMap R ↥S) r)) = ↑((algebraMap R ↥(Subalgebra.map (↑e) S)) r)","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A ���ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; ","nextTactic":"dsimp only","declUpToTactic":"/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.755_0.BO9UEYMCHxKwTRD","decl":"/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) "} -{"state":"case a\nR : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Semiring B\ninst✝¹ : Algebra R A\ninst✝ : Algebra R B\ne : A ≃ₐ[R] B\nS : Subalgebra R A\nsrc✝ : ↥S.toSubsemiring ≃+* ↥(Subsemiring.map (RingEquiv.toRingHom (toRingEquiv e)) S.toSubsemiring) :=\n RingEquiv.subsemiringMap (toRingEquiv e) S.toSubsemiring\nr : R\n⊢ ↑(Equiv.toFun (RingEquiv.subsemiringMap (toRingEquiv e) S.toSubsemiring).toEquiv ((algebraMap R ↥S) r)) =\n ↑((algebraMap R ↥(Subalgebra.map (↑e) S)) r)","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; ","nextTactic":"erw [RingEquiv.subsemiringMap_apply_coe]","declUpToTactic":"/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.755_0.BO9UEYMCHxKwTRD","decl":"/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) "} -{"state":"case a\nR : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Semiring B\ninst✝¹ : Algebra R A\ninst✝ : Algebra R B\ne : A ≃ₐ[R] B\nS : Subalgebra R A\nsrc✝ : ↥S.toSubsemiring ≃+* ↥(Subsemiring.map (RingEquiv.toRingHom (toRingEquiv e)) S.toSubsemiring) :=\n RingEquiv.subsemiringMap (toRingEquiv e) S.toSubsemiring\nr : R\n⊢ (toRingEquiv e) ↑((algebraMap R ↥S) r) = ↑((algebraMap R ↥(Subalgebra.map (↑e) S)) r)","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n ","nextTactic":"exact e.commutes _","declUpToTactic":"/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.755_0.BO9UEYMCHxKwTRD","decl":"/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nS : Set (Subalgebra R A)\nx : A\n⊢ x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n ","nextTactic":"simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]","declUpToTactic":"theorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.878_0.BO9UEYMCHxKwTRD","decl":"theorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nS : Set (Subalgebra R A)\n⊢ ↑(Subalgebra.toSubmodule (sInf S)) = ↑(sInf (⇑Subalgebra.toSubmodule '' S))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by ","nextTactic":"simp","declUpToTactic":"@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.882_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nS : Set (Subalgebra R A)\n⊢ ↑(sInf S).toSubsemiring = ↑(sInf (Subalgebra.toSubsemiring '' S))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x �� S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by ","nextTactic":"simp","declUpToTactic":"@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.888_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nι : Sort u_1\nS : ι → Subalgebra R A\n⊢ ↑(⨅ i, S i) = ⋂ i, ↑(S i)","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n ","nextTactic":"simp [iInf]","declUpToTactic":"@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.894_0.BO9UEYMCHxKwTRD","decl":"@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nι : Sort u_1\nS : ι → Subalgebra R A\nx : A\n⊢ x ∈ ⨅ i, S i ↔ ∀ (i : ι), x ∈ S i","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n ","nextTactic":"simp only [iInf, mem_sInf, Set.forall_range_iff]","declUpToTactic":"theorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.899_0.BO9UEYMCHxKwTRD","decl":"theorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nι : Sort u_1\nS : ι → Subalgebra R A\n⊢ ↑(toSubmodule (⨅ i, S i)) = ↑(⨅ i, toSubmodule (S i))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by ","nextTactic":"simp","declUpToTactic":"open Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.903_0.BO9UEYMCHxKwTRD","decl":"open Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nS : Subalgebra R A\nh : S = ⊤\nx : A\n⊢ x ∈ S","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by ","nextTactic":"rw [h]","declUpToTactic":"theorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.922_0.BO9UEYMCHxKwTRD","decl":"theorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nS : Subalgebra R A\nh : S = ⊤\nx : A\n⊢ x ∈ ⊤","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; ","nextTactic":"exact mem_top","declUpToTactic":"theorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.922_0.BO9UEYMCHxKwTRD","decl":"theorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nS : Subalgebra R A\nh : ∀ (x : A), x ∈ S\n⊢ S = ⊤","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ","nextTactic":"ext x","declUpToTactic":"theorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.922_0.BO9UEYMCHxKwTRD","decl":"theorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S "} -{"state":"case h\nR : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nS : Subalgebra R A\nh : ∀ (x : A), x ∈ S\nx : A\n⊢ x ∈ S ↔ x ∈ ⊤","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; ","nextTactic":"exact ⟨fun _ => mem_top, fun _ => h x⟩","declUpToTactic":"theorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.922_0.BO9UEYMCHxKwTRD","decl":"theorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S "} -{"state":"R : Type u\nA : Type v\nB✝ : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B✝\ninst✝¹ : Algebra R B✝\nS : Subalgebra R A\ninst✝ : Subsingleton A\nB C : Subalgebra R A\nx : A\n⊢ x ∈ B ↔ x ∈ C","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by ","nextTactic":"simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]","declUpToTactic":"instance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1007_0.BO9UEYMCHxKwTRD","decl":"instance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\ninst✝ : Subsingleton (Subalgebra R B)\nf g : A ≃ₐ[R] B\n⊢ f = g","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by ","nextTactic":"rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]","declUpToTactic":"instance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1024_0.BO9UEYMCHxKwTRD","decl":"instance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nS : Subalgebra R A\nsrc✝ : Inhabited (Subalgebra R R) := inferInstanceAs (Inhabited (Subalgebra R R))\n⊢ ∀ (a : Subalgebra R R), a = default","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n ","nextTactic":"intro S","declUpToTactic":"instance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1033_0.BO9UEYMCHxKwTRD","decl":"instance : Unique (Subalgebra R R) "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nS✝ : Subalgebra R A\nsrc✝ : Inhabited (Subalgebra R R) := inferInstanceAs (Inhabited (Subalgebra R R))\nS : Subalgebra R R\n⊢ S = default","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n ","nextTactic":"refine' le_antisymm ?_ bot_le","declUpToTactic":"instance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1033_0.BO9UEYMCHxKwTRD","decl":"instance : Unique (Subalgebra R R) "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nS✝ : Subalgebra R A\nsrc✝ : Inhabited (Subalgebra R R) := inferInstanceAs (Inhabited (Subalgebra R R))\nS : Subalgebra R R\n⊢ S ≤ default","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n ","nextTactic":"intro _ _","declUpToTactic":"instance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1033_0.BO9UEYMCHxKwTRD","decl":"instance : Unique (Subalgebra R R) "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nS✝ : Subalgebra R A\nsrc✝ : Inhabited (Subalgebra R R) := inferInstanceAs (Inhabited (Subalgebra R R))\nS : Subalgebra R R\nx✝ : R\na✝ : x✝ ∈ S\n⊢ x✝ ∈ default","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n ","nextTactic":"simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default]","declUpToTactic":"instance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1033_0.BO9UEYMCHxKwTRD","decl":"instance : Unique (Subalgebra R R) "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nS✝ S : Subalgebra R A\n⊢ equivOfEq S S (_ : S = S) = AlgEquiv.refl","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ","nextTactic":"ext","declUpToTactic":"@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1102_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl "} -{"state":"case h.a\nR : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nS✝ S : Subalgebra R A\na✝ : ↥S\n⊢ ↑((equivOfEq S S (_ : S = S)) a✝) = ↑(AlgEquiv.refl a✝)","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; ","nextTactic":"rfl","declUpToTactic":"@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1102_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nS : Subalgebra R A\nS₁ : Subalgebra R B\n⊢ prod ⊤ ⊤ = ⊤","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ","nextTactic":"ext","declUpToTactic":"@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1136_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ "} -{"state":"case h\nR : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nS : Subalgebra R A\nS₁ : Subalgebra R B\nx✝ : A × B\n⊢ x✝ ∈ prod ⊤ ⊤ ↔ x✝ ∈ ⊤","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; ","nextTactic":"simp","declUpToTactic":"@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1136_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\ni j : ι\nx : A\nhxi : x ∈ (fun i => ↑(K i)) i\nhxj : x ∈ (fun i => ↑(K i)) j\n⊢ (fun i x => (f i) x) i { val := x, property := hxi } = (fun i x => (f i) x) j { val := x, property := hxj }","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n ","nextTactic":"let ⟨k, hik, hjk⟩ := dir i j","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\ni j : ι\nx : A\nhxi : x ∈ (fun i => ↑(K i)) i\nhxj : x ∈ (fun i => ↑(K i)) j\nk : ι\nhik : (fun x x_1 => x ≤ x_1) (K i) (K k)\nhjk : (fun x x_1 => x ≤ x_1) (K j) (K k)\n⊢ (fun i x => (f i) x) i { val := x, property := hxi } = (fun i x => (f i) x) j { val := x, property := hxj }","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ��� S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n ","nextTactic":"dsimp","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\ni j : ι\nx : A\nhxi : x ∈ (fun i => ↑(K i)) i\nhxj : x ∈ (fun i => ↑(K i)) j\nk : ι\nhik : (fun x x_1 => x ≤ x_1) (K i) (K k)\nhjk : (fun x x_1 => x ≤ x_1) (K j) (K k)\n⊢ (f i) { val := x, property := hxi } = (f j) { val := x, property := hxj }","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n ","nextTactic":"rw [hf i k hik]","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\ni j : ι\nx : A\nhxi : x ∈ (fun i => ↑(K i)) i\nhxj : x ∈ (fun i => ↑(K i)) j\nk : ι\nhik : (fun x x_1 => x ≤ x_1) (K i) (K k)\nhjk : (fun x x_1 => x ≤ x_1) (K j) (K k)\n⊢ (AlgHom.comp (f k) (inclusion hik)) { val := x, property := hxi } = (f j) { val := x, property := hxj }","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n ","nextTactic":"rw [hf j k hjk]","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →���[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\ni j : ι\nx : A\nhxi : x ∈ (fun i => ↑(K i)) i\nhxj : x ∈ (fun i => ↑(K i)) j\nk : ι\nhik : (fun x x_1 => x ≤ x_1) (K i) (K k)\nhjk : (fun x x_1 => x ≤ x_1) (K j) (K k)\n⊢ (AlgHom.comp (f k) (inclusion hik)) { val := x, property := hxi } =\n (AlgHom.comp (f k) (inclusion hjk)) { val := x, property := hxj }","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n ","nextTactic":"rfl","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\n⊢ ↑T ⊆ ⋃ i, ↑(K i)","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ��� T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by ","nextTactic":"rw [hT, coe_iSup_of_directed dir]","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\n⊢ Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } = (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by ","nextTactic":"apply Set.iUnionLift_const _ (fun _ => 1)","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"case hci\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\n⊢ ∀ (i : ι), ↑1 = ↑1","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ��� φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> ","nextTactic":"simp","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"case h\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\n⊢ ∀ (i : ι), (f i) 1 = 1","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> ","nextTactic":"simp","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\n⊢ ∀ (x y : ↥T),\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n (x * y) =\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n x *\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n y","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n ","nextTactic":"subst hT","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (x y : ↥(iSup K)),\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n (x * y) =\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n x *\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n y","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x �� φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; ","nextTactic":"dsimp","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (x y : ↥(iSup K)),\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ ↑(K i)) (hxj : x ∈ ↑(K j)),\n (f i) { val := x, property := hxi } = (f j) { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) (x * y) =\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ ↑(K i)) (hxj : x ∈ ↑(K j)),\n (f i) { val := x, property := hxi } = (f j) { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) x *\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ ↑(K i)) (hxj : x ∈ ↑(K j)),\n (f i) { val := x, property := hxi } = (f j) { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) y","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (��S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n ","nextTactic":"apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"case hopi\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst��⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (i : ι) (x y : ↑↑(K i)),\n Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) (x * y) =\n Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) x * Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) y\ncase h\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (i : ι) (x y : ↑↑(K i)), (f i) (x * y) = (f i) x * (f i) y\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ↑(iSup K) ⊆ ⋃ i, ↑(K i)","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n ","nextTactic":"on_goal 3 => rw [coe_iSup_of_directed dir]","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"case hopi\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (i : ι) (x y : ↑↑(K i)),\n Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) (x * y) =\n Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) x * Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) y\ncase h\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (i : ι) (x y : ↑↑(K i)), (f i) (x * y) = (f i) x * (f i) y\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ↑(iSup K) ⊆ ⋃ i, ↑(K i)","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n ","nextTactic":"on_goal 3 => rw [coe_iSup_of_directed dir]","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ↑(iSup K) ⊆ ⋃ i, ↑(K i)","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => ","nextTactic":"rw [coe_iSup_of_directed dir]","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"case hopi\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (i : ι) (x y : ↑↑(K i)),\n Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) (x * y) =\n Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) x * Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) y\ncase h\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (i : ι) (x y : ↑↑(K i)), (f i) (x * y) = (f i) x * (f i) y","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n ","nextTactic":"all_goals simp","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"case hopi\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (i : ι) (x y : ↑↑(K i)),\n Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) (x * y) =\n Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) x * Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) y","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals ","nextTactic":"simp","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"case h\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (i : ι) (x y : ↑↑(K i)), (f i) (x * y) = (f i) x * (f i) y","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals ","nextTactic":"simp","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\n⊢ OneHom.toFun\n (↑{\n toOneHom :=\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) },\n map_mul' :=\n (_ :\n ∀ (x y : ↥T),\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n (x * y) =\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n x *\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n y) })\n 0 =\n 0","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by ","nextTactic":"dsimp","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\n⊢ Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ ↑(K i)) (hxj : x ∈ ↑(K j)),\n (f i) { val := x, property := hxi } = (f j) { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 0 =\n 0","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; ","nextTactic":"apply Set.iUnionLift_const _ (fun _ => 0)","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"case hci\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\n⊢ ∀ (i : ι), ↑0 = ↑0","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> ","nextTactic":"simp","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"case h\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\n⊢ ∀ (i : ι), (f i) 0 = 0","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> ","nextTactic":"simp","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\n⊢ ∀ (x y : ↥T),\n OneHom.toFun\n (↑{\n toOneHom :=\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) },\n map_mul' :=\n (_ :\n ∀ (x y : ↥T),\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n (x * y) =\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n x *\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n y) })\n (x + y) =\n OneHom.toFun\n (↑{\n toOneHom :=\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) },\n map_mul' :=\n (_ :\n ∀ (x y : ↥T),\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n (x * y) =\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n x *\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n y) })\n x +\n OneHom.toFun\n (↑{\n toOneHom :=\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) },\n map_mul' :=\n (_ :\n ∀ (x y : ↥T),\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n (x * y) =\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n x *\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n y) })\n y","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (���(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n ","nextTactic":"subst hT","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (x y : ↥(iSup K)),\n OneHom.toFun\n (↑{\n toOneHom :=\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) 1 =\n 1) },\n map_mul' :=\n (_ :\n ∀ (x y : ↥(iSup K)),\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n (x * y) =\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n x *\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n y) })\n (x + y) =\n OneHom.toFun\n (↑{\n toOneHom :=\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) 1 =\n 1) },\n map_mul' :=\n (_ :\n ∀ (x y : ↥(iSup K)),\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n (x * y) =\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n x *\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n y) })\n x +\n OneHom.toFun\n (↑{\n toOneHom :=\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) 1 =\n 1) },\n map_mul' :=\n (_ :\n ∀ (x y : ↥(iSup K)),\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n (x * y) =\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n x *\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n y) })\n y","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; ","nextTactic":"dsimp","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (x y : ↥(iSup K)),\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ ↑(K i)) (hxj : x ∈ ↑(K j)),\n (f i) { val := x, property := hxi } = (f j) { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) (x + y) =\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ ↑(K i)) (hxj : x ∈ ↑(K j)),\n (f i) { val := x, property := hxi } = (f j) { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) x +\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ ↑(K i)) (hxj : x ∈ ↑(K j)),\n (f i) { val := x, property := hxi } = (f j) { val := x, property := hxj })\n ↑(iSup K) (_ : ↑(iSup K) ⊆ ⋃ i, ↑(K i)) y","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n ","nextTactic":"apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"case hopi\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (i : ι) (x y : ↑↑(K i)),\n Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) (x + y) =\n Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) x + Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) y\ncase h\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (i : ι) (x y : ↑↑(K i)), (f i) (x + y) = (f i) x + (f i) y\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ↑(iSup K) ⊆ ⋃ i, ↑(K i)","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n ","nextTactic":"on_goal 3 => rw [coe_iSup_of_directed dir]","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"case hopi\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (i : ι) (x y : ↑↑(K i)),\n Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) (x + y) =\n Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) x + Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) y\ncase h\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (i : ι) (x y : ↑↑(K i)), (f i) (x + y) = (f i) x + (f i) y\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ↑(iSup K) ⊆ ⋃ i, ↑(K i)","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n ","nextTactic":"on_goal 3 => rw [coe_iSup_of_directed dir]","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ↑(iSup K) ⊆ ⋃ i, ↑(K i)","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => ","nextTactic":"rw [coe_iSup_of_directed dir]","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"case hopi\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (i : ι) (x y : ↑↑(K i)),\n Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) (x + y) =\n Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) x + Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) y\ncase h\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (i : ι) (x y : ↑↑(K i)), (f i) (x + y) = (f i) x + (f i) y","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n ","nextTactic":"all_goals simp","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"case hopi\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (i : ι) (x y : ↑↑(K i)),\n Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) (x + y) =\n Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) x + Set.inclusion (_ : ↑(K i) ⊆ ↑(iSup K)) y","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals ","nextTactic":"simp","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"case h\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\n⊢ ∀ (i : ι) (x y : ↑↑(K i)), (f i) (x + y) = (f i) x + (f i) y","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ���ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals ","nextTactic":"simp","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\nr : R\n⊢ OneHom.toFun\n (↑↑{\n toMonoidHom :=\n {\n toOneHom :=\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) },\n map_mul' :=\n (_ :\n ∀ (x y : ↥T),\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n (x * y) =\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n x *\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n y) },\n map_zero' :=\n (_ :\n OneHom.toFun\n (↑{\n toOneHom :=\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) },\n map_mul' :=\n (_ :\n ∀ (x y : ↥T),\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n (x * y) =\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n x *\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n y) })\n 0 =\n 0),\n map_add' :=\n (_ :\n ∀ (x y : ↥T),\n OneHom.toFun\n (↑{\n toOneHom :=\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) },\n map_mul' :=\n (_ :\n ∀ (x y : ↥T),\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n (x * y) =\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n x *\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n y) })\n (x + y) =\n OneHom.toFun\n (↑{\n toOneHom :=\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) },\n map_mul' :=\n (_ :\n ∀ (x y : ↥T),\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n (x * y) =\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n x *\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n y) })\n x +\n OneHom.toFun\n (↑{\n toOneHom :=\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) },\n map_mul' :=\n (_ :\n ∀ (x y : ↥T),\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n (x * y) =\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n x *\n OneHom.toFun\n {\n toFun :=\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)),\n map_one' :=\n (_ :\n Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i)\n (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } =\n (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) 1 =\n 1) }\n y) })\n y) })\n ((algebraMap R ↥T) r) =\n (algebraMap R B) r","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n ","nextTactic":"dsimp","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\nr : R\n⊢ Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ ↑(K i)) (hxj : x ∈ ↑(K j)),\n (f i) { val := x, property := hxi } = (f j) { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) ((algebraMap R ↥T) r) =\n (algebraMap R B) r","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ��� S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ �� i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n ","nextTactic":"apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r)","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"case hci\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\nr : R\n⊢ ∀ (i : ι), ↑((algebraMap R ↑↑(K i)) r) = ↑((algebraMap R ↥T) r)","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> ","nextTactic":"simp","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"case h\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\nr : R\n⊢ ∀ (i : ι), (f i) ((algebraMap R ↑↑(K i)) r) = (algebraMap R B) r","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> ","nextTactic":"simp","declUpToTactic":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1173_0.BO9UEYMCHxKwTRD","decl":"/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\ni : ι\nx : ↥(K i)\nh : K i ≤ T\n⊢ (iSupLift K dir f hf T hT) ((inclusion h) x) = (f i) x","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n ","nextTactic":"dsimp [iSupLift, inclusion]","declUpToTactic":"@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1203_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\ni : ι\nx : ↥(K i)\nh : K i ≤ T\n⊢ Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } = (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) (Set.inclusion h x) =\n (f i) x","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n ","nextTactic":"rw [Set.iUnionLift_inclusion]","declUpToTactic":"@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1203_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\ni : ι\nh : K i ≤ T\n⊢ AlgHom.comp (iSupLift K dir f hf T hT) (inclusion h) = f i","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ��))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ","nextTactic":"ext","declUpToTactic":"@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1210_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i "} -{"state":"case H\nR : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\ni : ι\nh : K i ≤ T\nx✝ : ↥(K i)\n⊢ (AlgHom.comp (iSupLift K dir f hf T hT) (inclusion h)) x✝ = (f i) x✝","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; ","nextTactic":"simp","declUpToTactic":"@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1210_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\ni : ι\nx : ↥(K i)\nhx : ↑x ∈ T\n⊢ (iSupLift K dir f hf T hT) { val := ↑x, property := hx } = (f i) x","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n ","nextTactic":"dsimp [iSupLift, inclusion]","declUpToTactic":"@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1215_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\ni : ι\nx : ↥(K i)\nhx : ↑x ∈ T\n⊢ Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } = (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) { val := ↑x, property := hx } =\n (f i) x","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n ","nextTactic":"rw [Set.iUnionLift_mk]","declUpToTactic":"@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1215_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\ni : ι\nx : ↥T\nhx : ↑x ∈ K i\n⊢ (iSupLift K dir f hf T hT) x = (f i) { val := ↑x, property := hx }","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n ","nextTactic":"dsimp [iSupLift, inclusion]","declUpToTactic":"theorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1222_0.BO9UEYMCHxKwTRD","decl":"theorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁵ : CommSemiring R\ninst✝⁴ : Semiring A\ninst✝³ : Algebra R A\ninst✝² : Semiring B\ninst✝¹ : Algebra R B\nS : Subalgebra R A\nι : Type u_1\ninst✝ : Nonempty ι\nK : ι → Subalgebra R A\ndir : Directed (fun x x_1 => x ≤ x_1) K\nf : (i : ι) → ↥(K i) →ₐ[R] B\nhf : ∀ (i j : ι) (h : K i ≤ K j), f i = AlgHom.comp (f j) (inclusion h)\nT : Subalgebra R A\nhT : T = iSup K\ni : ι\nx : ↥T\nhx : ↑x ∈ K i\n⊢ Set.iUnionLift (fun i => ↑(K i)) (fun i x => (f i) x)\n (_ :\n ∀ (i j : ι) (x : A) (hxi : x ∈ (fun i => ↑(K i)) i) (hxj : x ∈ (fun i => ↑(K i)) j),\n (fun i x => (f i) x) i { val := x, property := hxi } = (fun i x => (f i) x) j { val := x, property := hxj })\n ↑T (_ : ↑T ⊆ ⋃ i, ↑(K i)) x =\n (f i) { val := ↑x, property := hx }","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A ���ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n ","nextTactic":"rw [Set.iUnionLift_of_mem]","declUpToTactic":"theorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1222_0.BO9UEYMCHxKwTRD","decl":"theorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ "} -{"state":"R✝ : Type u\nA✝ : Type v\nB : Type w\ninst✝⁷ : CommSemiring R✝\ninst✝⁶ : Semiring A✝\ninst✝⁵ : Algebra R✝ A✝\ninst✝⁴ : Semiring B\ninst✝³ : Algebra R✝ B\nS✝ : Subalgebra R✝ A✝\nα : Type u_1\nβ : Type u_2\nR : Type u_3\nA : Type u_4\ninst✝² : CommSemiring R\ninst✝¹ : CommSemiring A\ninst✝ : Algebra R A\nS : Subalgebra R A\n⊢ RingHom.rangeS (algebraMap (↥S) A) = S.toSubsemiring","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n ","nextTactic":"rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]","declUpToTactic":"@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1305_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring "} -{"state":"R✝ : Type u\nA✝ : Type v\nB : Type w\ninst✝⁷ : CommSemiring R✝\ninst✝⁶ : Semiring A✝\ninst✝⁵ : Algebra R✝ A✝\ninst✝⁴ : Semiring B\ninst✝³ : Algebra R✝ B\nS✝ : Subalgebra R✝ A✝\nα : Type u_1\nβ : Type u_2\nR : Type u_3\nA : Type u_4\ninst✝² : CommRing R\ninst✝¹ : CommRing A\ninst✝ : Algebra R A\nS : Subalgebra R A\n⊢ RingHom.range (algebraMap (↥S) A) = toSubring S","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n ","nextTactic":"rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]","declUpToTactic":"@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1312_0.BO9UEYMCHxKwTRD","decl":"@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nS : Subalgebra R A\nr : R\n⊢ (algebraMap R A) r ∈ Set.center A","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n �� x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ���s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n ","nextTactic":"simp only [Semigroup.mem_center_iff, commutes, forall_const]","declUpToTactic":"theorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1329_0.BO9UEYMCHxKwTRD","decl":"theorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\nH : ∀ (i : ι), ∃ n, s i ^ n • x ∈ S'\n⊢ x ∈ S'","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n ","nextTactic":"let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\nH : ∀ (i : ι), ∃ n, s i ^ n • x ∈ S'\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\n⊢ x ∈ S'","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n ","nextTactic":"suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\nH : ∀ (i : ι), ∃ n, s i ^ n • x ∈ S'\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nthis : x ∈ toSubmodule (AlgHom.range (ofId (↥S') S))\n⊢ x ∈ S'","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ��� Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ��x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n ","nextTactic":"obtain ⟨x, rfl⟩ := this","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"case intro\nR : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nx : ↥S'\nH : ∀ (i : ι), ∃ n, s i ^ n • ↑(ofId (↥S') S) x ∈ S'\n⊢ ↑(ofId (↥S') S) x ∈ S'","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n ","nextTactic":"exact x.2","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\nH : ∀ (i : ι), ∃ n, s i ^ n • x ∈ S'\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\n⊢ x ∈ toSubmodule (AlgHom.range (ofId (↥S') S))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A ��).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n ","nextTactic":"choose n hn using H","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\n⊢ x ∈ toSubmodule (AlgHom.range (ofId (↥S') S))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n ","nextTactic":"let s' : ι → S' := fun x => ⟨s x, hs x⟩","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\n⊢ x ∈ toSubmodule (AlgHom.range (ofId (↥S') S))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n ","nextTactic":"let l' : ι → S' := fun x => ⟨l x, hl x⟩","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\n⊢ x ∈ toSubmodule (AlgHom.range (ofId (↥S') S))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n ","nextTactic":"have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\n⊢ ∑ i in ι', l' i * s' i = 1","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ","nextTactic":"ext","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"case a\nR : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\n⊢ ↑(∑ i in ι', l' i * s' i) = ↑1","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ��� :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n ","nextTactic":"show S'.subtype (∑ i in ι', l' i * s' i) = 1","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"case a\nR : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\n⊢ (Subsemiring.subtype S'.toSubsemiring) (∑ i in ι', l' i * s' i) = 1","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n ","nextTactic":"simpa only [map_sum, map_mul] using e","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\ne' : ∑ i in ι', l' i * s' i = 1\n⊢ x ∈ toSubmodule (AlgHom.range (ofId (↥S') S))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S�� := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n ","nextTactic":"have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\ne' : ∑ i in ι', l' i * s' i = 1\n⊢ Ideal.span (s' '' ↑ι') = ⊤","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →��[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n ","nextTactic":"rw [Ideal.eq_top_iff_one]","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) �� x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\ne' : ∑ i in ι', l' i * s' i = 1\n⊢ 1 ∈ Ideal.span (s' '' ↑ι')","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n ","nextTactic":"rw [← e']","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\ne' : ∑ i in ι', l' i * s' i = 1\n⊢ ∑ i in ι', l' i * s' i ∈ Ideal.span (s' '' ↑ι')","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n ","nextTactic":"apply sum_mem","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"case h\nR : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\ne' : ∑ i in ι', l' i * s' i = 1\n⊢ ∀ c ∈ ι', l' c * s' c ∈ Ideal.span (s' '' ↑ι')","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n ","nextTactic":"intros i hi","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"case h\nR : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\ne' : ∑ i in ι', l' i * s' i = 1\ni : ι\nhi : i ∈ ι'\n⊢ l' i * s' i ∈ Ideal.span (s' '' ↑ι')","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n ","nextTactic":"exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\ne' : ∑ i in ι', l' i * s' i = 1\nthis : Ideal.span (s' '' ↑ι') = ⊤\n⊢ x ∈ toSubmodule (AlgHom.range (ofId (↥S') S))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n ","nextTactic":"let N := ι'.sup n","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ��S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\ne' : ∑ i in ι', l' i * s' i = 1\nthis : Ideal.span (s' '' ↑ι') = ⊤\nN : ℕ := Finset.sup ι' n\n⊢ x ∈ toSubmodule (AlgHom.range (ofId (↥S') S))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n ","nextTactic":"have hN := Ideal.span_pow_eq_top _ this N","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ��� n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"R : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\ne' : ∑ i in ι', l' i * s' i = 1\nthis : Ideal.span (s' '' ↑ι') = ⊤\nN : ℕ := Finset.sup ι' n\nhN : Ideal.span ((fun x => x ^ N) '' (s' '' ↑ι')) = ⊤\n⊢ x ∈ toSubmodule (AlgHom.range (ofId (↥S') S))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n ","nextTactic":"apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"case H\nR : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\ne' : ∑ i in ι', l' i * s' i = 1\nthis : Ideal.span (s' '' ↑ι') = ⊤\nN : ℕ := Finset.sup ι' n\nhN : Ideal.span ((fun x => x ^ N) '' (s' '' ↑ι')) = ⊤\n⊢ ∀ (r : ↑((fun x => x ^ N) '' (s' '' ↑ι'))), ↑r • x ∈ toSubmodule (AlgHom.range (ofId (↥S') S))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n ","nextTactic":"rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"case H.mk.intro.intro.intro.intro\nR : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\ne' : ∑ i in ι', l' i * s' i = 1\nthis : Ideal.span (s' '' ↑ι') = ⊤\nN : ℕ := Finset.sup ι' n\nhN : Ideal.span ((fun x => x ^ N) '' (s' '' ↑ι')) = ⊤\ni : ι\nhi : i ∈ ↑ι'\n⊢ ↑{ val := (fun x => x ^ N) (s' i), property := (_ : ∃ a ∈ s' '' ↑ι', (fun x => x ^ N) a = (fun x => x ^ N) (s' i)) } •\n x ∈\n toSubmodule (AlgHom.range (ofId (↥S') S))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩\n ","nextTactic":"change s' i ^ N • x ∈ _","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"case H.mk.intro.intro.intro.intro\nR : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\ne' : ∑ i in ι', l' i * s' i = 1\nthis : Ideal.span (s' '' ↑ι') = ⊤\nN : ℕ := Finset.sup ι' n\nhN : Ideal.span ((fun x => x ^ N) '' (s' '' ↑ι')) = ⊤\ni : ι\nhi : i ∈ ↑ι'\n⊢ s' i ^ N • x ∈ toSubmodule (AlgHom.range (ofId (↥S') S))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩\n change s' i ^ N • x ∈ _\n ","nextTactic":"rw [← tsub_add_cancel_of_le (show n i ≤ N from Finset.le_sup hi)]","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩\n change s' i ^ N • x ∈ _\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"case H.mk.intro.intro.intro.intro\nR : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\ne' : ∑ i in ι', l' i * s' i = 1\nthis : Ideal.span (s' '' ↑ι') = ⊤\nN : ℕ := Finset.sup ι' n\nhN : Ideal.span ((fun x => x ^ N) '' (s' '' ↑ι')) = ⊤\ni : ι\nhi : i ∈ ↑ι'\n⊢ s' i ^ (N - n i + n i) • x ∈ toSubmodule (AlgHom.range (ofId (↥S') S))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩\n change s' i ^ N • x ∈ _\n rw [← tsub_add_cancel_of_le (show n i ≤ N from Finset.le_sup hi)]\n ","nextTactic":"rw [pow_add]","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩\n change s' i ^ N • x ∈ _\n rw [← tsub_add_cancel_of_le (show n i ≤ N from Finset.le_sup hi)]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"case H.mk.intro.intro.intro.intro\nR : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\ne' : ∑ i in ι', l' i * s' i = 1\nthis : Ideal.span (s' '' ↑ι') = ⊤\nN : ℕ := Finset.sup ι' n\nhN : Ideal.span ((fun x => x ^ N) '' (s' '' ↑ι')) = ⊤\ni : ι\nhi : i ∈ ↑ι'\n⊢ (s' i ^ (N - n i) * s' i ^ n i) • x ∈ toSubmodule (AlgHom.range (ofId (↥S') S))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩\n change s' i ^ N • x ∈ _\n rw [← tsub_add_cancel_of_le (show n i ≤ N from Finset.le_sup hi)]\n rw [pow_add]\n ","nextTactic":"rw [mul_smul]","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [��� e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩\n change s' i ^ N • x ∈ _\n rw [← tsub_add_cancel_of_le (show n i ≤ N from Finset.le_sup hi)]\n rw [pow_add]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"case H.mk.intro.intro.intro.intro\nR : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\ne' : ∑ i in ι', l' i * s' i = 1\nthis : Ideal.span (s' '' ↑ι') = ⊤\nN : ℕ := Finset.sup ι' n\nhN : Ideal.span ((fun x => x ^ N) '' (s' '' ↑ι')) = ⊤\ni : ι\nhi : i ∈ ↑ι'\n⊢ s' i ^ (N - n i) • s' i ^ n i • x ∈ toSubmodule (AlgHom.range (ofId (↥S') S))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩\n change s' i ^ N • x ∈ _\n rw [← tsub_add_cancel_of_le (show n i ≤ N from Finset.le_sup hi)]\n rw [pow_add]\n rw [mul_smul]\n ","nextTactic":"refine' Submodule.smul_mem _ (⟨_, pow_mem (hs i) _⟩ : S') _","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩\n change s' i ^ N • x ∈ _\n rw [← tsub_add_cancel_of_le (show n i ≤ N from Finset.le_sup hi)]\n rw [pow_add]\n rw [mul_smul]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"case H.mk.intro.intro.intro.intro\nR : Type u\nA : Type v\nB : Type w\ninst✝⁶ : CommSemiring R\ninst✝⁵ : Semiring A\ninst✝⁴ : Algebra R A\ninst✝³ : Semiring B\ninst✝² : Algebra R B\nS✝ : Subalgebra R A\nS : Type u_1\ninst✝¹ : CommRing S\ninst✝ : Algebra R S\nS' : Subalgebra R S\nι : Type u_2\nι' : Finset ι\ns l : ι → S\ne : ∑ i in ι', l i * s i = 1\nhs : ∀ (i : ι), s i ∈ S'\nhl : ∀ (i : ι), l i ∈ S'\nx : S\n_i : Algebra ↥S' ↥S' := Algebra.id ↥S'\nn : ι → ℕ\nhn : ∀ (i : ι), s i ^ n i • x ∈ S'\ns' : ι → ↥S' := fun x => { val := s x, property := (_ : s x ∈ S') }\nl' : ι → ↥S' := fun x => { val := l x, property := (_ : l x ∈ S') }\ne' : ∑ i in ι', l' i * s' i = 1\nthis : Ideal.span (s' '' ↑ι') = ⊤\nN : ℕ := Finset.sup ι' n\nhN : Ideal.span ((fun x => x ^ N) '' (s' '' ↑ι')) = ⊤\ni : ι\nhi : i ∈ ↑ι'\n⊢ s' i ^ n i • x ∈ toSubmodule (AlgHom.range (ofId (↥S') S))","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩\n change s' i ^ N • x ∈ _\n rw [← tsub_add_cancel_of_le (show n i ≤ N from Finset.le_sup hi)]\n rw [pow_add]\n rw [mul_smul]\n refine' Submodule.smul_mem _ (⟨_, pow_mem (hs i) _⟩ : S') _\n ","nextTactic":"exact ⟨⟨_, hn i⟩, rfl⟩","declUpToTactic":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩\n change s' i ^ N • x ∈ _\n rw [← tsub_add_cancel_of_le (show n i ≤ N from Finset.le_sup hi)]\n rw [pow_add]\n rw [mul_smul]\n refine' Submodule.smul_mem _ (⟨_, pow_mem (hs i) _⟩ : S') _\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1419_0.BO9UEYMCHxKwTRD","decl":"/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' "} -{"state":"R : Type u_1\ninst✝ : Ring R\nS : Subring R\ni : ℤ\n⊢ (algebraMap ℤ R) 0 ∈ S.carrier","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩\n change s' i ^ N • x ∈ _\n rw [← tsub_add_cancel_of_le (show n i ≤ N from Finset.le_sup hi)]\n rw [pow_add]\n rw [mul_smul]\n refine' Submodule.smul_mem _ (⟨_, pow_mem (hs i) _⟩ : S') _\n exact ⟨⟨_, hn i⟩, rfl⟩\n#align subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem\n\ntheorem mem_of_span_eq_top_of_smul_pow_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) (s : Set S) (l : s →₀ S) (hs : Finsupp.total s S S (↑) l = 1)\n (hs' : s ⊆ S') (hl : ∀ i, l i ∈ S') (x : S) (H : ∀ r : s, ∃ n : ℕ, (r : S) ^ n • x ∈ S') :\n x ∈ S' :=\n mem_of_finset_sum_eq_one_of_pow_smul_mem S' l.support (↑) l hs (fun x => hs' x.2) hl x H\n#align subalgebra.mem_of_span_eq_top_of_smul_pow_mem Subalgebra.mem_of_span_eq_top_of_smul_pow_mem\n\nend Subalgebra\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n/-- A subsemiring is an `ℕ`-subalgebra. -/\ndef subalgebraOfSubsemiring (S : Subsemiring R) : Subalgebra ℕ R :=\n { S with algebraMap_mem' := fun i => coe_nat_mem S i }\n#align subalgebra_of_subsemiring subalgebraOfSubsemiring\n\n@[simp]\ntheorem mem_subalgebraOfSubsemiring {x : R} {S : Subsemiring R} :\n x ∈ subalgebraOfSubsemiring S ↔ x ∈ S :=\n Iff.rfl\n#align mem_subalgebra_of_subsemiring mem_subalgebraOfSubsemiring\n\nend Nat\n\nsection Int\n\nvariable {R : Type*} [Ring R]\n\n/-- A subring is a `ℤ`-subalgebra. -/\ndef subalgebraOfSubring (S : Subring R) : Subalgebra ℤ R :=\n { S with\n algebraMap_mem' := fun i =>\n Int.induction_on i (by ","nextTactic":"simpa using S.zero_mem","declUpToTactic":"/-- A subring is a `ℤ`-subalgebra. -/\ndef subalgebraOfSubring (S : Subring R) : Subalgebra ℤ R :=\n { S with\n algebraMap_mem' := fun i =>\n Int.induction_on i (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1486_0.BO9UEYMCHxKwTRD","decl":"/-- A subring is a `ℤ`-subalgebra. -/\ndef subalgebraOfSubring (S : Subring R) : Subalgebra ℤ R "} -{"state":"R : Type u_1\ninst✝ : Ring R\nS : Subring R\ni✝ : ℤ\ni : ℕ\nih : (algebraMap ℤ R) ↑i ∈ S.carrier\n⊢ (algebraMap ℤ R) (↑i + 1) ∈ S.carrier","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩\n change s' i ^ N • x ∈ _\n rw [← tsub_add_cancel_of_le (show n i ≤ N from Finset.le_sup hi)]\n rw [pow_add]\n rw [mul_smul]\n refine' Submodule.smul_mem _ (⟨_, pow_mem (hs i) _⟩ : S') _\n exact ⟨⟨_, hn i⟩, rfl⟩\n#align subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem\n\ntheorem mem_of_span_eq_top_of_smul_pow_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) (s : Set S) (l : s →₀ S) (hs : Finsupp.total s S S (↑) l = 1)\n (hs' : s ⊆ S') (hl : ∀ i, l i ∈ S') (x : S) (H : ∀ r : s, ∃ n : ℕ, (r : S) ^ n • x ∈ S') :\n x ∈ S' :=\n mem_of_finset_sum_eq_one_of_pow_smul_mem S' l.support (↑) l hs (fun x => hs' x.2) hl x H\n#align subalgebra.mem_of_span_eq_top_of_smul_pow_mem Subalgebra.mem_of_span_eq_top_of_smul_pow_mem\n\nend Subalgebra\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n/-- A subsemiring is an `ℕ`-subalgebra. -/\ndef subalgebraOfSubsemiring (S : Subsemiring R) : Subalgebra ℕ R :=\n { S with algebraMap_mem' := fun i => coe_nat_mem S i }\n#align subalgebra_of_subsemiring subalgebraOfSubsemiring\n\n@[simp]\ntheorem mem_subalgebraOfSubsemiring {x : R} {S : Subsemiring R} :\n x ∈ subalgebraOfSubsemiring S ↔ x ∈ S :=\n Iff.rfl\n#align mem_subalgebra_of_subsemiring mem_subalgebraOfSubsemiring\n\nend Nat\n\nsection Int\n\nvariable {R : Type*} [Ring R]\n\n/-- A subring is a `ℤ`-subalgebra. -/\ndef subalgebraOfSubring (S : Subring R) : Subalgebra ℤ R :=\n { S with\n algebraMap_mem' := fun i =>\n Int.induction_on i (by simpa using S.zero_mem)\n (fun i ih => by ","nextTactic":"simpa using S.add_mem ih S.one_mem","declUpToTactic":"/-- A subring is a `ℤ`-subalgebra. -/\ndef subalgebraOfSubring (S : Subring R) : Subalgebra ℤ R :=\n { S with\n algebraMap_mem' := fun i =>\n Int.induction_on i (by simpa using S.zero_mem)\n (fun i ih => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1486_0.BO9UEYMCHxKwTRD","decl":"/-- A subring is a `ℤ`-subalgebra. -/\ndef subalgebraOfSubring (S : Subring R) : Subalgebra ℤ R "} -{"state":"R : Type u_1\ninst✝ : Ring R\nS : Subring R\ni✝ : ℤ\ni : ℕ\nih : (algebraMap ℤ R) (-↑i) ∈ S.carrier\n⊢ ↑(-↑i - 1) ∈ S","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩\n change s' i ^ N • x ∈ _\n rw [← tsub_add_cancel_of_le (show n i ≤ N from Finset.le_sup hi)]\n rw [pow_add]\n rw [mul_smul]\n refine' Submodule.smul_mem _ (⟨_, pow_mem (hs i) _⟩ : S') _\n exact ⟨⟨_, hn i⟩, rfl⟩\n#align subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem\n\ntheorem mem_of_span_eq_top_of_smul_pow_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) (s : Set S) (l : s →₀ S) (hs : Finsupp.total s S S (↑) l = 1)\n (hs' : s ⊆ S') (hl : ∀ i, l i ∈ S') (x : S) (H : ∀ r : s, ∃ n : ℕ, (r : S) ^ n • x ∈ S') :\n x ∈ S' :=\n mem_of_finset_sum_eq_one_of_pow_smul_mem S' l.support (↑) l hs (fun x => hs' x.2) hl x H\n#align subalgebra.mem_of_span_eq_top_of_smul_pow_mem Subalgebra.mem_of_span_eq_top_of_smul_pow_mem\n\nend Subalgebra\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n/-- A subsemiring is an `ℕ`-subalgebra. -/\ndef subalgebraOfSubsemiring (S : Subsemiring R) : Subalgebra ℕ R :=\n { S with algebraMap_mem' := fun i => coe_nat_mem S i }\n#align subalgebra_of_subsemiring subalgebraOfSubsemiring\n\n@[simp]\ntheorem mem_subalgebraOfSubsemiring {x : R} {S : Subsemiring R} :\n x ∈ subalgebraOfSubsemiring S ↔ x ∈ S :=\n Iff.rfl\n#align mem_subalgebra_of_subsemiring mem_subalgebraOfSubsemiring\n\nend Nat\n\nsection Int\n\nvariable {R : Type*} [Ring R]\n\n/-- A subring is a `ℤ`-subalgebra. -/\ndef subalgebraOfSubring (S : Subring R) : Subalgebra ℤ R :=\n { S with\n algebraMap_mem' := fun i =>\n Int.induction_on i (by simpa using S.zero_mem)\n (fun i ih => by simpa using S.add_mem ih S.one_mem) fun i ih =>\n show ((-i - 1 : ℤ) : R) ∈ S by\n ","nextTactic":"rw [Int.cast_sub]","declUpToTactic":"/-- A subring is a `ℤ`-subalgebra. -/\ndef subalgebraOfSubring (S : Subring R) : Subalgebra ℤ R :=\n { S with\n algebraMap_mem' := fun i =>\n Int.induction_on i (by simpa using S.zero_mem)\n (fun i ih => by simpa using S.add_mem ih S.one_mem) fun i ih =>\n show ((-i - 1 : ℤ) : R) ∈ S by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1486_0.BO9UEYMCHxKwTRD","decl":"/-- A subring is a `ℤ`-subalgebra. -/\ndef subalgebraOfSubring (S : Subring R) : Subalgebra ℤ R "} -{"state":"R : Type u_1\ninst✝ : Ring R\nS : Subring R\ni✝ : ℤ\ni : ℕ\nih : (algebraMap ℤ R) (-↑i) ∈ S.carrier\n⊢ ↑(-↑i) - ↑1 ∈ S","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩\n change s' i ^ N • x ∈ _\n rw [← tsub_add_cancel_of_le (show n i ≤ N from Finset.le_sup hi)]\n rw [pow_add]\n rw [mul_smul]\n refine' Submodule.smul_mem _ (⟨_, pow_mem (hs i) _⟩ : S') _\n exact ⟨⟨_, hn i⟩, rfl⟩\n#align subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem\n\ntheorem mem_of_span_eq_top_of_smul_pow_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) (s : Set S) (l : s →₀ S) (hs : Finsupp.total s S S (↑) l = 1)\n (hs' : s ⊆ S') (hl : ∀ i, l i ∈ S') (x : S) (H : ∀ r : s, ∃ n : ℕ, (r : S) ^ n • x ∈ S') :\n x ∈ S' :=\n mem_of_finset_sum_eq_one_of_pow_smul_mem S' l.support (↑) l hs (fun x => hs' x.2) hl x H\n#align subalgebra.mem_of_span_eq_top_of_smul_pow_mem Subalgebra.mem_of_span_eq_top_of_smul_pow_mem\n\nend Subalgebra\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n/-- A subsemiring is an `ℕ`-subalgebra. -/\ndef subalgebraOfSubsemiring (S : Subsemiring R) : Subalgebra ℕ R :=\n { S with algebraMap_mem' := fun i => coe_nat_mem S i }\n#align subalgebra_of_subsemiring subalgebraOfSubsemiring\n\n@[simp]\ntheorem mem_subalgebraOfSubsemiring {x : R} {S : Subsemiring R} :\n x ∈ subalgebraOfSubsemiring S ↔ x ∈ S :=\n Iff.rfl\n#align mem_subalgebra_of_subsemiring mem_subalgebraOfSubsemiring\n\nend Nat\n\nsection Int\n\nvariable {R : Type*} [Ring R]\n\n/-- A subring is a `ℤ`-subalgebra. -/\ndef subalgebraOfSubring (S : Subring R) : Subalgebra ℤ R :=\n { S with\n algebraMap_mem' := fun i =>\n Int.induction_on i (by simpa using S.zero_mem)\n (fun i ih => by simpa using S.add_mem ih S.one_mem) fun i ih =>\n show ((-i - 1 : ℤ) : R) ∈ S by\n rw [Int.cast_sub]\n ","nextTactic":"rw [Int.cast_one]","declUpToTactic":"/-- A subring is a `ℤ`-subalgebra. -/\ndef subalgebraOfSubring (S : Subring R) : Subalgebra ℤ R :=\n { S with\n algebraMap_mem' := fun i =>\n Int.induction_on i (by simpa using S.zero_mem)\n (fun i ih => by simpa using S.add_mem ih S.one_mem) fun i ih =>\n show ((-i - 1 : ℤ) : R) ∈ S by\n rw [Int.cast_sub]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1486_0.BO9UEYMCHxKwTRD","decl":"/-- A subring is a `ℤ`-subalgebra. -/\ndef subalgebraOfSubring (S : Subring R) : Subalgebra ℤ R "} -{"state":"R : Type u_1\ninst✝ : Ring R\nS : Subring R\ni✝ : ℤ\ni : ℕ\nih : (algebraMap ℤ R) (-↑i) ∈ S.carrier\n⊢ ↑(-↑i) - 1 ∈ S","srcUpToTactic":"/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-/\nimport Mathlib.Algebra.Algebra.Basic\nimport Mathlib.Data.Set.UnionLift\nimport Mathlib.LinearAlgebra.Finsupp\nimport Mathlib.RingTheory.Ideal.Operations\n\n#align_import algebra.algebra.subalgebra.basic from \"leanprover-community/mathlib\"@\"b915e9392ecb2a861e1e766f0e1df6ac481188ca\"\n\n/-!\n# Subalgebras over Commutative Semiring\n\nIn this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).\n\nMore lemmas about `adjoin` can be found in `RingTheory.Adjoin`.\n-/\n\n\nuniverse u u' v w w'\n\nopen BigOperators\n\n/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/\nstructure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] extends\n Subsemiring A : Type v where\n /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/\n algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier\n zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0\n one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1\n#align subalgebra Subalgebra\n\n/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/\nadd_decl_doc Subalgebra.toSubsemiring\n\nnamespace Subalgebra\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\ninstance : SetLike (Subalgebra R A) A where\n coe s := s.carrier\n coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h\n\ninstance SubsemiringClass : SubsemiringClass (Subalgebra R A) A where\n add_mem {s} := add_mem (s := s.toSubsemiring)\n mul_mem {s} := mul_mem (s := s.toSubsemiring)\n one_mem {s} := one_mem s.toSubsemiring\n zero_mem {s} := zero_mem s.toSubsemiring\n\n@[simp]\ntheorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subsemiring Subalgebra.mem_toSubsemiring\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=\n Iff.rfl\n#align subalgebra.mem_carrier Subalgebra.mem_carrier\n\n@[ext]\ntheorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=\n SetLike.ext h\n#align subalgebra.ext Subalgebra.ext\n\n@[simp]\ntheorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subsemiring Subalgebra.coe_toSubsemiring\n\ntheorem toSubsemiring_injective :\n Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h]\n#align subalgebra.to_subsemiring_injective Subalgebra.toSubsemiring_injective\n\ntheorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U :=\n toSubsemiring_injective.eq_iff\n#align subalgebra.to_subsemiring_inj Subalgebra.toSubsemiring_inj\n\n/-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional\nequalities. -/\nprotected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A :=\n { S.toSubsemiring.copy s hs with\n carrier := s\n algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' }\n#align subalgebra.copy Subalgebra.copy\n\n@[simp]\ntheorem coe_copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s :=\n rfl\n#align subalgebra.coe_copy Subalgebra.coe_copy\n\ntheorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=\n SetLike.coe_injective hs\n#align subalgebra.copy_eq Subalgebra.copy_eq\n\nvariable (S : Subalgebra R A)\n\ninstance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where\n smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx\n\n@[aesop safe apply (rule_sets [SetLike])]\ntheorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :\n algebraMap R A r ∈ s :=\n Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)\n\nprotected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S :=\n algebraMap_mem S r\n#align subalgebra.algebra_map_mem Subalgebra.algebraMap_mem\n\ntheorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ =>\n hr ▸ S.algebraMap_mem r\n#align subalgebra.srange_le Subalgebra.rangeS_le\n\ntheorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r\n#align subalgebra.range_subset Subalgebra.range_subset\n\ntheorem range_le : Set.range (algebraMap R A) ≤ S :=\n S.range_subset\n#align subalgebra.range_le Subalgebra.range_le\n\ntheorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S :=\n SMulMemClass.smul_mem r hx\n#align subalgebra.smul_mem Subalgebra.smul_mem\n\nprotected theorem one_mem : (1 : A) ∈ S :=\n one_mem S\n#align subalgebra.one_mem Subalgebra.one_mem\n\nprotected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S :=\n mul_mem hx hy\n#align subalgebra.mul_mem Subalgebra.mul_mem\n\nprotected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\n pow_mem hx n\n#align subalgebra.pow_mem Subalgebra.pow_mem\n\nprotected theorem zero_mem : (0 : A) ∈ S :=\n zero_mem S\n#align subalgebra.zero_mem Subalgebra.zero_mem\n\nprotected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S :=\n add_mem hx hy\n#align subalgebra.add_mem Subalgebra.add_mem\n\nprotected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S :=\n nsmul_mem hx n\n#align subalgebra.nsmul_mem Subalgebra.nsmul_mem\n\nprotected theorem coe_nat_mem (n : ℕ) : (n : A) ∈ S :=\n coe_nat_mem S n\n#align subalgebra.coe_nat_mem Subalgebra.coe_nat_mem\n\nprotected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S :=\n list_prod_mem h\n#align subalgebra.list_prod_mem Subalgebra.list_prod_mem\n\nprotected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S :=\n list_sum_mem h\n#align subalgebra.list_sum_mem Subalgebra.list_sum_mem\n\nprotected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S :=\n multiset_sum_mem m h\n#align subalgebra.multiset_sum_mem Subalgebra.multiset_sum_mem\n\nprotected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∑ x in t, f x) ∈ S :=\n sum_mem h\n#align subalgebra.sum_mem Subalgebra.sum_mem\n\nprotected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A]\n [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S :=\n multiset_prod_mem m h\n#align subalgebra.multiset_prod_mem Subalgebra.multiset_prod_mem\n\nprotected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) :\n (∏ x in t, f x) ∈ S :=\n prod_mem h\n#align subalgebra.prod_mem Subalgebra.prod_mem\n\ninstance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A :=\n { Subalgebra.SubsemiringClass with\n neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ }\n\nprotected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S :=\n neg_mem hx\n#align subalgebra.neg_mem Subalgebra.neg_mem\n\nprotected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S :=\n sub_mem hx hy\n#align subalgebra.sub_mem Subalgebra.sub_mem\n\nprotected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=\n zsmul_mem hx n\n#align subalgebra.zsmul_mem Subalgebra.zsmul_mem\n\nprotected theorem coe_int_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S :=\n coe_int_mem S n\n#align subalgebra.coe_int_mem Subalgebra.coe_int_mem\n\n/-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/\ndef toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n (S : Subalgebra R A) : AddSubmonoid A :=\n S.toSubsemiring.toAddSubmonoid\n#align subalgebra.to_add_submonoid Subalgebra.toAddSubmonoid\n\n-- Porting note: this field already exists in Lean 4.\n-- /-- The projection from a subalgebra of `A` to a submonoid of `A`. -/\n-- def toSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]\n-- (S : Subalgebra R A) : Submonoid A :=\n-- S.toSubsemiring.toSubmonoid\nset_option align.precheck false in\n#align subalgebra.to_submonoid Subalgebra.toSubmonoid\n\n/-- A subalgebra over a ring is also a `Subring`. -/\ndef toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n Subring A :=\n { S.toSubsemiring with neg_mem' := S.neg_mem }\n#align subalgebra.to_subring Subalgebra.toSubring\n\n@[simp]\ntheorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_to_subring Subalgebra.mem_toSubring\n\n@[simp]\ntheorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n (S : Subalgebra R A) : (↑S.toSubring : Set A) = S :=\n rfl\n#align subalgebra.coe_to_subring Subalgebra.coe_toSubring\n\ntheorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] :\n Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h =>\n ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h]\n#align subalgebra.to_subring_injective Subalgebra.toSubring_injective\n\ntheorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U :=\n toSubring_injective.eq_iff\n#align subalgebra.to_subring_inj Subalgebra.toSubring_inj\n\ninstance : Inhabited S :=\n ⟨(0 : S.toSubsemiring)⟩\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/\n\n\ninstance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) :\n Semiring S :=\n S.toSubsemiring.toSemiring\n#align subalgebra.to_semiring Subalgebra.toSemiring\n\ninstance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) :\n CommSemiring S :=\n S.toSubsemiring.toCommSemiring\n#align subalgebra.to_comm_semiring Subalgebra.toCommSemiring\n\ninstance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S :=\n S.toSubring.toRing\n#align subalgebra.to_ring Subalgebra.toRing\n\ninstance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) :\n CommRing S :=\n S.toSubring.toCommRing\n#align subalgebra.to_comm_ring Subalgebra.toCommRing\n\ninstance toOrderedSemiring {R A} [CommSemiring R] [OrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedSemiring S :=\n S.toSubsemiring.toOrderedSemiring\n#align subalgebra.to_ordered_semiring Subalgebra.toOrderedSemiring\n\ninstance toStrictOrderedSemiring {R A} [CommSemiring R] [StrictOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : StrictOrderedSemiring S :=\n S.toSubsemiring.toStrictOrderedSemiring\n#align subalgebra.to_strict_ordered_semiring Subalgebra.toStrictOrderedSemiring\n\ninstance toOrderedCommSemiring {R A} [CommSemiring R] [OrderedCommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommSemiring S :=\n S.toSubsemiring.toOrderedCommSemiring\n#align subalgebra.to_ordered_comm_semiring Subalgebra.toOrderedCommSemiring\n\ninstance toStrictOrderedCommSemiring {R A} [CommSemiring R] [StrictOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : StrictOrderedCommSemiring S :=\n S.toSubsemiring.toStrictOrderedCommSemiring\n#align subalgebra.to_strict_ordered_comm_semiring Subalgebra.toStrictOrderedCommSemiring\n\ninstance toOrderedRing {R A} [CommRing R] [OrderedRing A] [Algebra R A] (S : Subalgebra R A) :\n OrderedRing S :=\n S.toSubring.toOrderedRing\n#align subalgebra.to_ordered_ring Subalgebra.toOrderedRing\n\ninstance toOrderedCommRing {R A} [CommRing R] [OrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : OrderedCommRing S :=\n S.toSubring.toOrderedCommRing\n#align subalgebra.to_ordered_comm_ring Subalgebra.toOrderedCommRing\n\ninstance toLinearOrderedSemiring {R A} [CommSemiring R] [LinearOrderedSemiring A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedSemiring S :=\n S.toSubsemiring.toLinearOrderedSemiring\n#align subalgebra.to_linear_ordered_semiring Subalgebra.toLinearOrderedSemiring\n\ninstance toLinearOrderedCommSemiring {R A} [CommSemiring R] [LinearOrderedCommSemiring A]\n [Algebra R A] (S : Subalgebra R A) : LinearOrderedCommSemiring S :=\n S.toSubsemiring.toLinearOrderedCommSemiring\n#align subalgebra.to_linear_ordered_comm_semiring Subalgebra.toLinearOrderedCommSemiring\n\ninstance toLinearOrderedRing {R A} [CommRing R] [LinearOrderedRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedRing S :=\n S.toSubring.toLinearOrderedRing\n#align subalgebra.to_linear_ordered_ring Subalgebra.toLinearOrderedRing\n\ninstance toLinearOrderedCommRing {R A} [CommRing R] [LinearOrderedCommRing A] [Algebra R A]\n (S : Subalgebra R A) : LinearOrderedCommRing S :=\n S.toSubring.toLinearOrderedCommRing\n#align subalgebra.to_linear_ordered_comm_ring Subalgebra.toLinearOrderedCommRing\n\nend\n\n/-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/\ndef toSubmodule : Subalgebra R A ↪o Submodule R A where\n toEmbedding :=\n { toFun := fun S =>\n { S with\n carrier := S\n smul_mem' := fun c {x} hx ↦\n (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx }\n inj' := fun _ _ h ↦ ext <| fun x ↦ SetLike.ext_iff.mp h x }\n map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe\n#align subalgebra.to_submodule Subalgebra.toSubmodule\n\n/- TODO: bundle other forgetful maps between algebraic substructures, e.g.\n `to_subsemiring` and `to_subring` in this file. -/\n@[simp]\ntheorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl\n#align subalgebra.mem_to_submodule Subalgebra.mem_toSubmodule\n\n@[simp]\ntheorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl\n#align subalgebra.coe_to_submodule Subalgebra.coe_toSubmodule\n\ntheorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) :=\n fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :)\n\nsection\n\n/-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/\n\n\ninstance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=\n S.toSubmodule.module'\n#align subalgebra.module' Subalgebra.module'\n\ninstance : Module R S :=\n S.module'\n\ninstance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S :=\n inferInstanceAs (IsScalarTower R' R (toSubmodule S))\n\ninstance algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] :\n Algebra R' S :=\n { (algebraMap R' A).codRestrict S fun x => by\n rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ←\n Algebra.algebraMap_eq_smul_one]\n exact algebraMap_mem S\n _ with\n commutes' := fun c x => Subtype.eq <| Algebra.commutes _ _\n smul_def' := fun c x => Subtype.eq <| Algebra.smul_def _ _ }\n#align subalgebra.algebra' Subalgebra.algebra'\n\ninstance algebra : Algebra R S := S.algebra'\n#align subalgebra.algebra Subalgebra.algebra\n\nend\n\ninstance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=\n ⟨fun {c} {x : S} h =>\n have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)\n this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_bot Subalgebra.noZeroSMulDivisors_bot\n\nprotected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl\n#align subalgebra.coe_add Subalgebra.coe_add\n\nprotected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl\n#align subalgebra.coe_mul Subalgebra.coe_mul\n\nprotected theorem coe_zero : ((0 : S) : A) = 0 := rfl\n#align subalgebra.coe_zero Subalgebra.coe_zero\n\nprotected theorem coe_one : ((1 : S) : A) = 1 := rfl\n#align subalgebra.coe_one Subalgebra.coe_one\n\nprotected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl\n#align subalgebra.coe_neg Subalgebra.coe_neg\n\nprotected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]\n {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl\n#align subalgebra.coe_sub Subalgebra.coe_sub\n\n@[simp, norm_cast]\ntheorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :\n (↑(r • x) : A) = r • (x : A) := rfl\n#align subalgebra.coe_smul Subalgebra.coe_smul\n\n@[simp, norm_cast]\ntheorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A]\n (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl\n#align subalgebra.coe_algebra_map Subalgebra.coe_algebraMap\n\nprotected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n :=\n SubmonoidClass.coe_pow x n\n#align subalgebra.coe_pow Subalgebra.coe_pow\n\nprotected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=\n ZeroMemClass.coe_eq_zero\n#align subalgebra.coe_eq_zero Subalgebra.coe_eq_zero\n\nprotected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 :=\n OneMemClass.coe_eq_one\n#align subalgebra.coe_eq_one Subalgebra.coe_eq_one\n\n-- todo: standardize on the names these morphisms\n-- compare with submodule.subtype\n/-- Embedding of a subalgebra into the algebra. -/\ndef val : S →ₐ[R] A :=\n { toFun := ((↑) : S → A)\n map_zero' := rfl\n map_one' := rfl\n map_add' := fun _ _ ↦ rfl\n map_mul' := fun _ _ ↦ rfl\n commutes' := fun _ ↦ rfl }\n#align subalgebra.val Subalgebra.val\n\n@[simp]\ntheorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl\n#align subalgebra.coe_val Subalgebra.coe_val\n\ntheorem val_apply (x : S) : S.val x = (x : A) := rfl\n#align subalgebra.val_apply Subalgebra.val_apply\n\n@[simp]\ntheorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subsemiring_subtype Subalgebra.toSubsemiring_subtype\n\n@[simp]\ntheorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) :\n S.toSubring.subtype = (S.val : S →+* A) := rfl\n#align subalgebra.to_subring_subtype Subalgebra.toSubring_subtype\n\n/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,\nwe define it as a `LinearEquiv` to avoid type equalities. -/\ndef toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S :=\n LinearEquiv.ofEq _ _ rfl\n#align subalgebra.to_submodule_equiv Subalgebra.toSubmoduleEquiv\n\n/-- Transport a subalgebra via an algebra homomorphism. -/\ndef map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B :=\n { S.toSubsemiring.map (f : A →+* B) with\n algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) }\n#align subalgebra.map Subalgebra.map\n\ntheorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=\n Set.image_subset f\n#align subalgebra.map_mono Subalgebra.map_mono\n\ntheorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) :=\n fun _S₁ _S₂ ih =>\n ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih\n#align subalgebra.map_injective Subalgebra.map_injective\n\n@[simp]\ntheorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S :=\n SetLike.coe_injective <| Set.image_id _\n#align subalgebra.map_id Subalgebra.map_id\n\ntheorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :\n (S.map f).map g = S.map (g.comp f) :=\n SetLike.coe_injective <| Set.image_image _ _ _\n#align subalgebra.map_map Subalgebra.map_map\n\n@[simp]\ntheorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=\n Subsemiring.mem_map\n#align subalgebra.mem_map Subalgebra.mem_map\n\ntheorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (toSubmodule $ S.map f) = S.toSubmodule.map f.toLinearMap :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_submodule Subalgebra.map_toSubmodule\n\ntheorem map_toSubsemiring {S : Subalgebra R A} {f : A →ₐ[R] B} :\n (S.map f).toSubsemiring = S.toSubsemiring.map f.toRingHom :=\n SetLike.coe_injective rfl\n#align subalgebra.map_to_subsemiring Subalgebra.map_toSubsemiring\n\n@[simp]\ntheorem coe_map (S : Subalgebra R A) (f : A →ₐ[R] B) : (S.map f : Set B) = f '' S := rfl\n#align subalgebra.coe_map Subalgebra.coe_map\n\n/-- Preimage of a subalgebra under an algebra homomorphism. -/\ndef comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A :=\n { S.toSubsemiring.comap (f : A →+* B) with\n algebraMap_mem' := fun r =>\n show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r }\n#align subalgebra.comap Subalgebra.comap\n\ntheorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} :\n map f S ≤ U ↔ S ≤ comap f U :=\n Set.image_subset_iff\n#align subalgebra.map_le Subalgebra.map_le\n\ntheorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le\n#align subalgebra.gc_map_comap Subalgebra.gc_map_comap\n\n@[simp]\ntheorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S :=\n Iff.rfl\n#align subalgebra.mem_comap Subalgebra.mem_comap\n\n@[simp, norm_cast]\ntheorem coe_comap (S : Subalgebra R B) (f : A →ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) :=\n rfl\n#align subalgebra.coe_comap Subalgebra.coe_comap\n\ninstance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A]\n [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S :=\n inferInstanceAs (NoZeroDivisors S.toSubsemiring)\n#align subalgebra.no_zero_divisors Subalgebra.noZeroDivisors\n\ninstance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n (S : Subalgebra R A) : IsDomain S :=\n inferInstanceAs (IsDomain S.toSubring)\n#align subalgebra.is_domain Subalgebra.isDomain\n\nend Subalgebra\n\nnamespace Submodule\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\nvariable (p : Submodule R A)\n\n/-- A submodule containing `1` and closed under multiplication is a subalgebra. -/\ndef toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p)\n (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A :=\n { p with\n mul_mem' := fun hx hy ↦ h_mul _ _ hx hy\n one_mem' := h_one\n algebraMap_mem' := fun r => by\n rw [Algebra.algebraMap_eq_smul_one]\n exact p.smul_mem _ h_one }\n#align submodule.to_subalgebra Submodule.toSubalgebra\n\n@[simp]\ntheorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} :\n x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl\n#align submodule.mem_to_subalgebra Submodule.mem_toSubalgebra\n\n@[simp]\ntheorem coe_toSubalgebra (p : Submodule R A) (h_one h_mul) :\n (p.toSubalgebra h_one h_mul : Set A) = p := rfl\n#align submodule.coe_to_subalgebra Submodule.coe_toSubalgebra\n\n-- Porting note: changed statement to reflect new structures\n-- @[simp] -- Porting note: as a result, it is no longer a great simp lemma\ntheorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) :\n s.toSubalgebra h1 hmul =\n Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩\n (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) :=\n rfl\n#align submodule.to_subalgebra_mk Submodule.toSubalgebra_mk\n\n@[simp]\ntheorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) :\n Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p :=\n SetLike.coe_injective rfl\n#align submodule.to_subalgebra_to_submodule Submodule.toSubalgebra_toSubmodule\n\n@[simp]\ntheorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) :\n (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S :=\n SetLike.coe_injective rfl\n#align subalgebra.to_submodule_to_subalgebra Subalgebra.toSubmodule_toSubalgebra\n\nend Submodule\n\nnamespace AlgHom\n\nvariable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}\n\nvariable [CommSemiring R]\n\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]\n\nvariable (φ : A →ₐ[R] B)\n\n/-- Range of an `AlgHom` as a subalgebra. -/\nprotected def range (φ : A →ₐ[R] B) : Subalgebra R B :=\n { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ }\n#align alg_hom.range AlgHom.range\n\n@[simp]\ntheorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y :=\n RingHom.mem_rangeS\n#align alg_hom.mem_range AlgHom.mem_range\n\ntheorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range :=\n φ.mem_range.2 ⟨x, rfl⟩\n#align alg_hom.mem_range_self AlgHom.mem_range_self\n\n@[simp]\ntheorem coe_range (φ : A →ₐ[R] B) : (φ.range : Set B) = Set.range φ := by\n ext\n rw [SetLike.mem_coe]\n rw [mem_range]\n rfl\n#align alg_hom.coe_range AlgHom.coe_range\n\ntheorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g :=\n SetLike.coe_injective (Set.range_comp g f)\n#align alg_hom.range_comp AlgHom.range_comp\n\ntheorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range :=\n SetLike.coe_mono (Set.range_comp_subset_range f g)\n#align alg_hom.range_comp_le_range AlgHom.range_comp_le_range\n\n/-- Restrict the codomain of an algebra homomorphism. -/\ndef codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S :=\n { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r }\n#align alg_hom.cod_restrict AlgHom.codRestrict\n\n@[simp]\ntheorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n S.val.comp (f.codRestrict S hf) = f :=\n AlgHom.ext fun _ => rfl\n#align alg_hom.val_comp_cod_restrict AlgHom.val_comp_codRestrict\n\n@[simp]\ntheorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :\n ↑(f.codRestrict S hf x) = f x :=\n rfl\n#align alg_hom.coe_cod_restrict AlgHom.coe_codRestrict\n\ntheorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) :\n Function.Injective (f.codRestrict S hf) ↔ Function.Injective f :=\n ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩\n#align alg_hom.injective_cod_restrict AlgHom.injective_codRestrict\n\n/-- Restrict the codomain of an `AlgHom` `f` to `f.range`.\n\nThis is the bundled version of `Set.rangeFactorization`. -/\n@[reducible]\ndef rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range :=\n f.codRestrict f.range f.mem_range_self\n#align alg_hom.range_restrict AlgHom.rangeRestrict\n\n/-- The equalizer of two R-algebra homomorphisms -/\ndef equalizer (ϕ ψ : A →ₐ[R] B) : Subalgebra R A where\n carrier := { a | ϕ a = ψ a }\n zero_mem' := by simp only [Set.mem_setOf_eq, map_zero]\n one_mem' := by simp only [Set.mem_setOf_eq, map_one]\n add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_add]\n rw [ψ.map_add]\n rw [hx]\n rw [hy]\n mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by\n rw [Set.mem_setOf_eq]\n rw [ϕ.map_mul]\n rw [ψ.map_mul]\n rw [hx]\n rw [hy]\n algebraMap_mem' x := by rw [Set.mem_setOf_eq, AlgHom.commutes, AlgHom.commutes]\n#align alg_hom.equalizer AlgHom.equalizer\n\n@[simp]\ntheorem mem_equalizer (ϕ ψ : A →ₐ[R] B) (x : A) : x ∈ ϕ.equalizer ψ ↔ ϕ x = ψ x :=\n Iff.rfl\n#align alg_hom.mem_equalizer AlgHom.mem_equalizer\n\n/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.\n\nNote that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/\ninstance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range :=\n Set.fintypeRange φ\n#align alg_hom.fintype_range AlgHom.fintypeRange\n\nend AlgHom\n\nnamespace AlgEquiv\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.\n\nThis is a computable alternative to `AlgEquiv.ofInjective`. -/\ndef ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range :=\n { f.rangeRestrict with\n toFun := f.rangeRestrict\n invFun := g ∘ f.range.val\n left_inv := h\n right_inv := fun x =>\n Subtype.ext <|\n let ⟨x', hx'⟩ := f.mem_range.mp x.prop\n show f (g x) = x by rw [← hx', h x'] }\n#align alg_equiv.of_left_inverse AlgEquiv.ofLeftInverse\n\n@[simp]\ntheorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) :\n ↑(ofLeftInverse h x) = f x :=\n rfl\n#align alg_equiv.of_left_inverse_apply AlgEquiv.ofLeftInverse_apply\n\n@[simp]\ntheorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f)\n (x : f.range) : (ofLeftInverse h).symm x = g x :=\n rfl\n#align alg_equiv.of_left_inverse_symm_apply AlgEquiv.ofLeftInverse_symm_apply\n\n/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/\nnoncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range :=\n ofLeftInverse (Classical.choose_spec hf.hasLeftInverse)\n#align alg_equiv.of_injective AlgEquiv.ofInjective\n\n@[simp]\ntheorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) :\n ↑(ofInjective f hf x) = f x :=\n rfl\n#align alg_equiv.of_injective_apply AlgEquiv.ofInjective_apply\n\n/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/\nnoncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F]\n [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range :=\n ofInjective f f.toRingHom.injective\n#align alg_equiv.of_injective_field AlgEquiv.ofInjectiveField\n\n/-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`,\n`subalgebra_map` is the induced equivalence between `S` and `S.map e` -/\n@[simps!]\ndef subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) :=\n { e.toRingEquiv.subsemiringMap S.toSubsemiring with\n commutes' := fun r => by\n ext; dsimp only; erw [RingEquiv.subsemiringMap_apply_coe]\n exact e.commutes _ }\n#align alg_equiv.subalgebra_map AlgEquiv.subalgebraMap\n\nend AlgEquiv\n\nnamespace Algebra\n\nvariable (R : Type u) {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n/-- The minimal subalgebra that includes `s`. -/\ndef adjoin (s : Set A) : Subalgebra R A :=\n { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with\n algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }\n#align algebra.adjoin Algebra.adjoin\n\nvariable {R}\n\nprotected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>\n ⟨fun H => le_trans (le_trans (Set.subset_union_right _ _) Subsemiring.subset_closure) H,\n fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from\n Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩\n#align algebra.gc Algebra.gc\n\n/-- Galois insertion between `adjoin` and `coe`. -/\nprotected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where\n choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs\n gc := Algebra.gc\n le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl\n choice_eq _ _ := Subalgebra.copy_eq _ _ _\n#align algebra.gi Algebra.gi\n\ninstance : CompleteLattice (Subalgebra R A) where\n __ := GaloisInsertion.liftCompleteLattice Algebra.gi\n bot := (Algebra.ofId R A).range\n bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _\n\n@[simp]\ntheorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl\n#align algebra.coe_top Algebra.coe_top\n\n@[simp]\ntheorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x\n#align algebra.mem_top Algebra.mem_top\n\n@[simp]\ntheorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl\n#align algebra.top_to_submodule Algebra.top_toSubmodule\n\n@[simp]\ntheorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl\n#align algebra.top_to_subsemiring Algebra.top_toSubsemiring\n\n@[simp]\ntheorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :\n (⊤ : Subalgebra R A).toSubring = ⊤ := rfl\n#align algebra.top_to_subring Algebra.top_toSubring\n\n@[simp]\ntheorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule\n#align algebra.to_submodule_eq_top Algebra.toSubmodule_eq_top\n\n@[simp]\ntheorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring\n#align algebra.to_subsemiring_eq_top Algebra.toSubsemiring_eq_top\n\n@[simp]\ntheorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :\n S.toSubring = ⊤ ↔ S = ⊤ :=\n Subalgebra.toSubring_injective.eq_iff' top_toSubring\n#align algebra.to_subring_eq_top Algebra.toSubring_eq_top\n\ntheorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=\n have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_left Algebra.mem_sup_left\n\ntheorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=\n have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show`\n#align algebra.mem_sup_right Algebra.mem_sup_right\n\ntheorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n#align algebra.mul_mem_sup Algebra.mul_mem_sup\n\ntheorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=\n (Subalgebra.gc_map_comap f).l_sup\n#align algebra.map_sup Algebra.map_sup\n\n@[simp, norm_cast]\ntheorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl\n#align algebra.coe_inf Algebra.coe_inf\n\n@[simp]\ntheorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl\n#align algebra.mem_inf Algebra.mem_inf\n\nopen Subalgebra in\n@[simp]\ntheorem inf_toSubmodule (S T : Subalgebra R A) :\n toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl\n#align algebra.inf_to_submodule Algebra.inf_toSubmodule\n\n@[simp]\ntheorem inf_toSubsemiring (S T : Subalgebra R A) :\n (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=\n rfl\n#align algebra.inf_to_subsemiring Algebra.inf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=\n sInf_image\n#align algebra.coe_Inf Algebra.coe_sInf\n\ntheorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by\n simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]\n#align algebra.mem_Inf Algebra.mem_sInf\n\n@[simp]\ntheorem sInf_toSubmodule (S : Set (Subalgebra R A)) :\n Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_submodule Algebra.sInf_toSubmodule\n\n@[simp]\ntheorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :\n (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=\n SetLike.coe_injective <| by simp\n#align algebra.Inf_to_subsemiring Algebra.sInf_toSubsemiring\n\n@[simp, norm_cast]\ntheorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by\n simp [iInf]\n#align algebra.coe_infi Algebra.coe_iInf\n\ntheorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by\n simp only [iInf, mem_sInf, Set.forall_range_iff]\n#align algebra.mem_infi Algebra.mem_iInf\n\nopen Subalgebra in\n@[simp]\ntheorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :\n toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=\n SetLike.coe_injective <| by simp\n#align algebra.infi_to_submodule Algebra.iInf_toSubmodule\n\ninstance : Inhabited (Subalgebra R A) := ⟨⊥⟩\n\ntheorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl\n#align algebra.mem_bot Algebra.mem_bot\n\ntheorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := rfl\n#align algebra.to_submodule_bot Algebra.toSubmodule_bot\n\n@[simp]\ntheorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl\n#align algebra.coe_bot Algebra.coe_bot\n\ntheorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=\n ⟨fun h x => by rw [h]; exact mem_top, fun h => by\n ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩\n#align algebra.eq_top_iff Algebra.eq_top_iff\n\ntheorem range_top_iff_surjective (f : A →ₐ[R] B) :\n f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=\n Algebra.eq_top_iff\n#align algebra.range_top_iff_surjective Algebra.range_top_iff_surjective\n\n@[simp]\ntheorem range_id : (AlgHom.id R A).range = ⊤ :=\n SetLike.coe_injective Set.range_id\n#align algebra.range_id Algebra.range_id\n\n@[simp]\ntheorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=\n SetLike.coe_injective Set.image_univ\n#align algebra.map_top Algebra.map_top\n\n@[simp]\ntheorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=\n Subalgebra.toSubmodule_injective <| Submodule.map_one _\n#align algebra.map_bot Algebra.map_bot\n\n@[simp]\ntheorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=\n eq_top_iff.2 fun _x => mem_top\n#align algebra.comap_top Algebra.comap_top\n\n/-- `AlgHom` to `⊤ : Subalgebra R A`. -/\ndef toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=\n (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top\n#align algebra.to_top Algebra.toTop\n\ntheorem surjective_algebraMap_iff :\n Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h =>\n eq_bot_iff.2 fun y _ =>\n let ⟨_x, hx⟩ := h y\n hx ▸ Subalgebra.algebraMap_mem _ _,\n fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩\n#align algebra.surjective_algebra_map_iff Algebra.surjective_algebraMap_iff\n\ntheorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]\n [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=\n ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>\n ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩\n#align algebra.bijective_algebra_map_iff Algebra.bijective_algebraMap_iff\n\n/-- The bottom subalgebra is isomorphic to the base ring. -/\nnoncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :\n (⊥ : Subalgebra R A) ≃ₐ[R] R :=\n AlgEquiv.symm <|\n AlgEquiv.ofBijective (Algebra.ofId R _)\n ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy : _), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩\n#align algebra.bot_equiv_of_injective Algebra.botEquivOfInjective\n\n/-- The bottom subalgebra is isomorphic to the field. -/\n@[simps! symm_apply]\nnoncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :\n (⊥ : Subalgebra F R) ≃ₐ[F] F :=\n botEquivOfInjective (RingHom.injective _)\n#align algebra.bot_equiv Algebra.botEquiv\n\nend Algebra\n\nnamespace Subalgebra\n\nopen Algebra\n\nvariable {R : Type u} {A : Type v} {B : Type w}\n\nvariable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\nvariable (S : Subalgebra R A)\n\n/-- The top subalgebra is isomorphic to the algebra.\n\nThis is the algebra version of `Submodule.topEquiv`. -/\n@[simps!]\ndef topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=\n AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl <| AlgHom.ext fun _ => Subtype.ext rfl\n#align subalgebra.top_equiv Subalgebra.topEquiv\n\ninstance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) :=\n ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩\n#align subalgebra.subsingleton_of_subsingleton Subalgebra.subsingleton_of_subsingleton\n\ninstance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=\n ⟨fun f g =>\n AlgHom.ext fun a =>\n have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top\n let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)\n hx ▸ (f.commutes _).trans (g.commutes _).symm⟩\n#align alg_hom.subsingleton AlgHom.subsingleton\n\ninstance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩\n#align alg_equiv.subsingleton_left AlgEquiv.subsingleton_left\n\ninstance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :\n Subsingleton (A ≃ₐ[R] B) :=\n ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩\n#align alg_equiv.subsingleton_right AlgEquiv.subsingleton_right\n\ntheorem range_val : S.val.range = S :=\n ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val\n#align subalgebra.range_val Subalgebra.range_val\n\ninstance : Unique (Subalgebra R R) :=\n { inferInstanceAs (Inhabited (Subalgebra R R)) with\n uniq := by\n intro S\n refine' le_antisymm ?_ bot_le\n intro _ _\n simp only [Set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default] }\n\n/-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`.\n\nThis is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/\ndef inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T\n where\n toFun := Set.inclusion h\n map_one' := rfl\n map_add' _ _ := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n commutes' _ := rfl\n#align subalgebra.inclusion Subalgebra.inclusion\n\ntheorem inclusion_injective {S T : Subalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) :=\n fun _ _ => Subtype.ext ∘ Subtype.mk.inj\n#align subalgebra.inclusion_injective Subalgebra.inclusion_injective\n\n@[simp]\ntheorem inclusion_self {S : Subalgebra R A} : inclusion (le_refl S) = AlgHom.id R S :=\n AlgHom.ext fun _x => Subtype.ext rfl\n#align subalgebra.inclusion_self Subalgebra.inclusion_self\n\n@[simp]\ntheorem inclusion_mk {S T : Subalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :\n inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=\n rfl\n#align subalgebra.inclusion_mk Subalgebra.inclusion_mk\n\ntheorem inclusion_right {S T : Subalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :\n inclusion h ⟨x, m⟩ = x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_right Subalgebra.inclusion_right\n\n@[simp]\ntheorem inclusion_inclusion {S T U : Subalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) :\n inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=\n Subtype.ext rfl\n#align subalgebra.inclusion_inclusion Subalgebra.inclusion_inclusion\n\n@[simp]\ntheorem coe_inclusion {S T : Subalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s :=\n rfl\n#align subalgebra.coe_inclusion Subalgebra.coe_inclusion\n\n/-- Two subalgebras that are equal are also equivalent as algebras.\n\nThis is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.Set.ofEq`. -/\n@[simps apply]\ndef equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where\n __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h)\n toFun x := ⟨x, h ▸ x.2⟩\n invFun x := ⟨x, h.symm ▸ x.2⟩\n map_mul' _ _ := rfl\n commutes' _ := rfl\n#align subalgebra.equiv_of_eq Subalgebra.equivOfEq\n\n@[simp]\ntheorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) :\n (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl\n#align subalgebra.equiv_of_eq_symm Subalgebra.equivOfEq_symm\n\n@[simp]\ntheorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl\n#align subalgebra.equiv_of_eq_rfl Subalgebra.equivOfEq_rfl\n\n@[simp]\ntheorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) :\n (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl\n#align subalgebra.equiv_of_eq_trans Subalgebra.equivOfEq_trans\n\nsection Prod\n\nvariable (S₁ : Subalgebra R B)\n\n/-- The product of two subalgebras is a subalgebra. -/\ndef prod : Subalgebra R (A × B) :=\n { S.toSubsemiring.prod S₁.toSubsemiring with\n carrier := S ×ˢ S₁\n algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }\n#align subalgebra.prod Subalgebra.prod\n\n@[simp]\ntheorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=\n rfl\n#align subalgebra.coe_prod Subalgebra.coe_prod\n\nopen Subalgebra in\ntheorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl\n#align subalgebra.prod_to_submodule Subalgebra.prod_toSubmodule\n\n@[simp]\ntheorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :\n x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod\n#align subalgebra.mem_prod Subalgebra.mem_prod\n\n@[simp]\ntheorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp\n#align subalgebra.prod_top Subalgebra.prod_top\n\ntheorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=\n Set.prod_mono\n#align subalgebra.prod_mono Subalgebra.prod_mono\n\n@[simp]\ntheorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :\n S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=\n SetLike.coe_injective Set.prod_inter_prod\n#align subalgebra.prod_inf_prod Subalgebra.prod_inf_prod\n\nend Prod\n\nsection iSupLift\n\nvariable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K)\n\ntheorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) :=\n let s : Subalgebra R A :=\n { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm\n algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2\n ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ }\n have : iSup K = s := le_antisymm\n (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _)\n this.symm ▸ rfl\n#align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed\n\nvariable (K)\nvariable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))\n (T : Subalgebra R A) (hT : T = iSup K)\n\n-- Porting note: TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs\n-- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls\n/-- Define an algebra homomorphism on a directed supremum of subalgebras by defining\nit on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/\nnoncomputable def iSupLift : ↥T →ₐ[R] B :=\n { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)\n (fun i j x hxi hxj => by\n let ⟨k, hik, hjk⟩ := dir i j\n dsimp\n rw [hf i k hik]\n rw [hf j k hjk]\n rfl)\n T (by rw [hT, coe_iSup_of_directed dir])\n map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp\n map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp\n map_mul' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n map_add' := by\n subst hT; dsimp\n apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))\n on_goal 3 => rw [coe_iSup_of_directed dir]\n all_goals simp\n commutes' := fun r => by\n dsimp\n apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp }\n#align subalgebra.supr_lift Subalgebra.iSupLift\n\nvariable {K dir f hf T hT}\n\n@[simp]\ntheorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :\n iSupLift K dir f hf T hT (inclusion h x) = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_inclusion]\n#align subalgebra.supr_lift_inclusion Subalgebra.iSupLift_inclusion\n\n@[simp]\ntheorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :\n (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp\n#align subalgebra.supr_lift_comp_inclusion Subalgebra.iSupLift_comp_inclusion\n\n@[simp]\ntheorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :\n iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_mk]\n#align subalgebra.supr_lift_mk Subalgebra.iSupLift_mk\n\ntheorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) :\n iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by\n dsimp [iSupLift, inclusion]\n rw [Set.iUnionLift_of_mem]\n#align subalgebra.supr_lift_of_mem Subalgebra.iSupLift_of_mem\n\nend iSupLift\n\n/-! ## Actions by `Subalgebra`s\n\nThese are just copies of the definitions about `Subsemiring` starting from\n`Subring.mulAction`.\n-/\n\n\nsection Actions\n\nvariable {α β : Type*}\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [SMul A α] (S : Subalgebra R A) : SMul S α :=\n inferInstanceAs (SMul S.toSubsemiring α)\n\ntheorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl\n#align subalgebra.smul_def Subalgebra.smul_def\n\ninstance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) :\n SMulCommClass S α β :=\n S.toSubsemiring.smulCommClass_left\n#align subalgebra.smul_comm_class_left Subalgebra.smulCommClass_left\n\ninstance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) :\n SMulCommClass α S β :=\n S.toSubsemiring.smulCommClass_right\n#align subalgebra.smul_comm_class_right Subalgebra.smulCommClass_right\n\n/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/\ninstance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β]\n (S : Subalgebra R A) : IsScalarTower S α β :=\n inferInstanceAs (IsScalarTower S.toSubsemiring α β)\n#align subalgebra.is_scalar_tower_left Subalgebra.isScalarTower_left\n\ninstance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T]\n [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) :\n IsScalarTower R S' T :=\n ⟨fun _x y _z => (smul_assoc _ (y : S) _ : _)⟩\n#align subalgebra.is_scalar_tower_mid Subalgebra.isScalarTower_mid\n\ninstance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α :=\n inferInstanceAs (FaithfulSMul S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [MulAction A α] (S : Subalgebra R A) : MulAction S α :=\n inferInstanceAs (MulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α :=\n inferInstanceAs (DistribMulAction S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α :=\n inferInstanceAs (SMulWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α :=\n inferInstanceAs (MulActionWithZero S.toSubsemiring α)\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α :=\n inferInstanceAs (Module S.toSubsemiring α)\n#align subalgebra.module_left Subalgebra.moduleLeft\n\n/-- The action by a subalgebra is the action by the underlying algebra. -/\ninstance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : Algebra S α :=\n Algebra.ofSubsemiring S.toSubsemiring\n#align subalgebra.to_algebra Subalgebra.toAlgebra\n\ntheorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A]\n [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val :=\n rfl\n#align subalgebra.algebra_map_eq Subalgebra.algebraMap_eq\n\n@[simp]\ntheorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype,\n Subsemiring.rangeS_subtype]\n#align subalgebra.srange_algebra_map Subalgebra.rangeS_algebraMap\n\n@[simp]\ntheorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]\n (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by\n rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype,\n Subring.range_subtype]\n#align subalgebra.range_algebra_map Subalgebra.range_algebraMap\n\ninstance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A :=\n ⟨fun {c} x h =>\n have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h\n this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩\n#align subalgebra.no_zero_smul_divisors_top Subalgebra.noZeroSMulDivisors_top\n\nend Actions\n\nsection Center\n\ntheorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by\n simp only [Semigroup.mem_center_iff, commutes, forall_const]\n#align set.algebra_map_mem_center Set.algebraMap_mem_center\n\nvariable (R A)\n\n/-- The center of an algebra is the set of elements which commute with every element. They form a\nsubalgebra. -/\ndef center : Subalgebra R A :=\n { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center }\n#align subalgebra.center Subalgebra.center\n\ntheorem coe_center : (center R A : Set A) = Set.center A :=\n rfl\n#align subalgebra.coe_center Subalgebra.coe_center\n\n@[simp]\ntheorem center_toSubsemiring : (center R A).toSubsemiring = Subsemiring.center A :=\n rfl\n#align subalgebra.center_to_subsemiring Subalgebra.center_toSubsemiring\n\n@[simp]\ntheorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :\n (center R A).toSubring = Subring.center A :=\n rfl\n#align subalgebra.center_to_subring Subalgebra.center_toSubring\n\n@[simp]\ntheorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=\n SetLike.coe_injective (Set.center_eq_univ A)\n#align subalgebra.center_eq_top Subalgebra.center_eq_top\n\nvariable {R A}\n\ninstance : CommSemiring (center R A) :=\n inferInstanceAs (CommSemiring (Subsemiring.center A))\n\ninstance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) :=\n inferInstanceAs (CommRing (Subring.center A))\n\ntheorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b :=\n Subsemigroup.mem_center_iff\n#align subalgebra.mem_center_iff Subalgebra.mem_center_iff\n\nend Center\n\nsection Centralizer\n\n@[simp]\ntheorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) :\n algebraMap R A r ∈ s.centralizer :=\n fun _a _h => (Algebra.commutes _ _).symm\n#align set.algebra_map_mem_centralizer Set.algebraMap_mem_centralizer\n\nvariable (R)\n\n/-- The centralizer of a set as a subalgebra. -/\ndef centralizer (s : Set A) : Subalgebra R A :=\n { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer }\n#align subalgebra.centralizer Subalgebra.centralizer\n\n@[simp, norm_cast]\ntheorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer :=\n rfl\n#align subalgebra.coe_centralizer Subalgebra.coe_centralizer\n\ntheorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g :=\n Iff.rfl\n#align subalgebra.mem_centralizer_iff Subalgebra.mem_centralizer_iff\n\ntheorem center_le_centralizer (s) : center R A ≤ centralizer R s :=\n s.center_subset_centralizer\n#align subalgebra.center_le_centralizer Subalgebra.center_le_centralizer\n\ntheorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s :=\n Set.centralizer_subset h\n#align subalgebra.centralizer_le Subalgebra.centralizer_le\n\n@[simp]\ntheorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=\n SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset\n#align subalgebra.centralizer_eq_top_iff_subset Subalgebra.centralizer_eq_top_iff_subset\n\n@[simp]\ntheorem centralizer_univ : centralizer R Set.univ = center R A :=\n SetLike.ext' (Set.centralizer_univ A)\n#align subalgebra.centralizer_univ Subalgebra.centralizer_univ\n\nend Centralizer\n\n/-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` in `S`, and `S'` a subalgebra of `S` that contains\n`lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that\n`sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/\ntheorem mem_of_finset_sum_eq_one_of_pow_smul_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S)\n (e : ∑ i in ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S)\n (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by\n -- Porting note: needed to add this instance\n let _i : Algebra { x // x ∈ S' } { x // x ∈ S' } := Algebra.id _\n suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by\n obtain ⟨x, rfl⟩ := this\n exact x.2\n choose n hn using H\n let s' : ι → S' := fun x => ⟨s x, hs x⟩\n let l' : ι → S' := fun x => ⟨l x, hl x⟩\n have e' : ∑ i in ι', l' i * s' i = 1 := by\n ext\n show S'.subtype (∑ i in ι', l' i * s' i) = 1\n simpa only [map_sum, map_mul] using e\n have : Ideal.span (s' '' ι') = ⊤ := by\n rw [Ideal.eq_top_iff_one]\n rw [← e']\n apply sum_mem\n intros i hi\n exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi\n let N := ι'.sup n\n have hN := Ideal.span_pow_eq_top _ this N\n apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN\n rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩\n change s' i ^ N • x ∈ _\n rw [← tsub_add_cancel_of_le (show n i ≤ N from Finset.le_sup hi)]\n rw [pow_add]\n rw [mul_smul]\n refine' Submodule.smul_mem _ (⟨_, pow_mem (hs i) _⟩ : S') _\n exact ⟨⟨_, hn i⟩, rfl⟩\n#align subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem\n\ntheorem mem_of_span_eq_top_of_smul_pow_mem {S : Type*} [CommRing S] [Algebra R S]\n (S' : Subalgebra R S) (s : Set S) (l : s →₀ S) (hs : Finsupp.total s S S (↑) l = 1)\n (hs' : s ⊆ S') (hl : ∀ i, l i ∈ S') (x : S) (H : ∀ r : s, ∃ n : ℕ, (r : S) ^ n • x ∈ S') :\n x ∈ S' :=\n mem_of_finset_sum_eq_one_of_pow_smul_mem S' l.support (↑) l hs (fun x => hs' x.2) hl x H\n#align subalgebra.mem_of_span_eq_top_of_smul_pow_mem Subalgebra.mem_of_span_eq_top_of_smul_pow_mem\n\nend Subalgebra\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n/-- A subsemiring is an `ℕ`-subalgebra. -/\ndef subalgebraOfSubsemiring (S : Subsemiring R) : Subalgebra ℕ R :=\n { S with algebraMap_mem' := fun i => coe_nat_mem S i }\n#align subalgebra_of_subsemiring subalgebraOfSubsemiring\n\n@[simp]\ntheorem mem_subalgebraOfSubsemiring {x : R} {S : Subsemiring R} :\n x ∈ subalgebraOfSubsemiring S ↔ x ∈ S :=\n Iff.rfl\n#align mem_subalgebra_of_subsemiring mem_subalgebraOfSubsemiring\n\nend Nat\n\nsection Int\n\nvariable {R : Type*} [Ring R]\n\n/-- A subring is a `ℤ`-subalgebra. -/\ndef subalgebraOfSubring (S : Subring R) : Subalgebra ℤ R :=\n { S with\n algebraMap_mem' := fun i =>\n Int.induction_on i (by simpa using S.zero_mem)\n (fun i ih => by simpa using S.add_mem ih S.one_mem) fun i ih =>\n show ((-i - 1 : ℤ) : R) ∈ S by\n rw [Int.cast_sub]\n rw [Int.cast_one]\n ","nextTactic":"exact S.sub_mem ih S.one_mem","declUpToTactic":"/-- A subring is a `ℤ`-subalgebra. -/\ndef subalgebraOfSubring (S : Subring R) : Subalgebra ℤ R :=\n { S with\n algebraMap_mem' := fun i =>\n Int.induction_on i (by simpa using S.zero_mem)\n (fun i ih => by simpa using S.add_mem ih S.one_mem) fun i ih =>\n show ((-i - 1 : ℤ) : R) ∈ S by\n rw [Int.cast_sub]\n rw [Int.cast_one]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Subalgebra_Basic.1486_0.BO9UEYMCHxKwTRD","decl":"/-- A subring is a `ℤ`-subalgebra. -/\ndef subalgebraOfSubring (S : Subring R) : Subalgebra ℤ R "}