diff --git "a/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_Algebra_Basic.jsonl" "b/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_Algebra_Basic.jsonl" new file mode 100644--- /dev/null +++ "b/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_Algebra_Basic.jsonl" @@ -0,0 +1,72 @@ +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝² : CommSemiring R\ninst✝¹ : Semiring A\ninst✝ : Module R A\nh₁ : ∀ (r : R) (x : A), r • 1 * x = r • x\nh₂ : ∀ (r : R) (x : A), x * r • 1 = r • x\nr₁ r₂ : R\n⊢ OneHom.toFun { toFun := fun r => r • 1, map_one' := (_ : 1 • 1 = 1) } (r₁ * r₂) =\n OneHom.toFun { toFun := fun r => r • 1, map_one' := (_ : 1 • 1 = 1) } r₁ *\n OneHom.toFun { toFun := fun r => r • 1, map_one' := (_ : 1 • 1 = 1) } 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by ","nextTactic":"simp only [h₁, mul_smul]","declUpToTactic":"/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.272_0.lJPMR9lAgdsHXom","decl":"/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝² : CommSemiring R\ninst✝¹ : Semiring A\ninst✝ : Module R A\nh₁ : ∀ (r : R) (x : A), r • 1 * x = r • x\nh₂ : ∀ (r : R) (x : A), x * r • 1 = r • x\nr : R\nx : A\n⊢ {\n toMonoidHom :=\n { toOneHom := { toFun := fun r => r • 1, map_one' := (_ : 1 • 1 = 1) },\n map_mul' := (_ : ∀ (r₁ r₂ : R), (r₁ * r₂) • 1 = r₁ • 1 * r₂ • 1) },\n map_zero' := (_ : 0 • 1 = 0), map_add' := (_ : ∀ (r₁ r₂ : R), (r₁ + r₂) • 1 = r₁ • 1 + r₂ • 1) }\n r *\n x =\n x *\n {\n toMonoidHom :=\n { toOneHom := { toFun := fun r => r • 1, map_one' := (_ : 1 • 1 = 1) },\n map_mul' := (_ : ∀ (r₁ r₂ : R), (r₁ * r₂) • 1 = r₁ • 1 * r₂ • 1) },\n map_zero' := (_ : 0 • 1 = 0), map_add' := (_ : ∀ (r₁ r₂ : R), (r₁ + r₂) • 1 = r₁ • 1 + r₂ • 1) }\n 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by ","nextTactic":"simp [h₁, h₂]","declUpToTactic":"/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.272_0.lJPMR9lAgdsHXom","decl":"/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝² : CommSemiring R\ninst✝¹ : Semiring A\ninst✝ : Module R A\nh₁ : ∀ (r : R) (x : A), r • 1 * x = r • x\nh₂ : ∀ (r : R) (x : A), x * r • 1 = r • x\nr : R\nx : A\n⊢ r • x =\n {\n toMonoidHom :=\n { toOneHom := { toFun := fun r => r • 1, map_one' := (_ : 1 • 1 = 1) },\n map_mul' := (_ : ∀ (r₁ r₂ : R), (r₁ * r₂) • 1 = r₁ • 1 * r₂ • 1) },\n map_zero' := (_ : 0 • 1 = 0), map_add' := (_ : ∀ (r₁ r₂ : R), (r₁ + r₂) • 1 = r₁ • 1 + r₂ • 1) }\n r *\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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by ","nextTactic":"simp [h₁]","declUpToTactic":"/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.272_0.lJPMR9lAgdsHXom","decl":"/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝² : CommSemiring R\ninst✝¹ : Semiring A\ninst✝ : Module R A\nh₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y)\nh₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)\nr : R\nx : A\n⊢ r • 1 * x = r • 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by ","nextTactic":"rw [h₁, one_mul]","declUpToTactic":"/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.290_0.lJPMR9lAgdsHXom","decl":"/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝² : CommSemiring R\ninst✝¹ : Semiring A\ninst✝ : Module R A\nh₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y)\nh₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)\nr : R\nx : A\n⊢ x * r • 1 = r • 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by ","nextTactic":"rw [h₂, mul_one]","declUpToTactic":"/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.290_0.lJPMR9lAgdsHXom","decl":"/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A "} +{"state":"R✝ : Type u\nS : Type v\nA✝ : Type w\nB : Type u_1\ninst✝⁷ : CommSemiring R✝\ninst✝⁶ : CommSemiring S\ninst✝⁵ : Semiring A✝\ninst✝⁴ : Algebra R✝ A✝\ninst✝³ : Semiring B\ninst✝² : Algebra R✝ B\nR : Type u_2\ninst✝¹ : CommSemiring R\nA : Type u_3\ninst✝ : Semiring A\nP Q : Algebra R A\nh : ∀ (r : R), (algebraMap R A) r = (algebraMap R A) r\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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n ","nextTactic":"replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h","declUpToTactic":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.310_0.lJPMR9lAgdsHXom","decl":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI "} +{"state":"R✝ : Type u\nS : Type v\nA✝ : Type w\nB : Type u_1\ninst✝⁷ : CommSemiring R✝\ninst✝⁶ : CommSemiring S\ninst✝⁵ : Semiring A✝\ninst✝⁴ : Algebra R✝ A✝\ninst✝³ : Semiring B\ninst✝² : Algebra R✝ B\nR : Type u_2\ninst✝¹ : CommSemiring R\nA : Type u_3\ninst✝ : Semiring A\nP Q : Algebra R A\nh : toRingHom = toRingHom\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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n ","nextTactic":"have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]","declUpToTactic":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.310_0.lJPMR9lAgdsHXom","decl":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI "} +{"state":"R✝ : Type u\nS : Type v\nA✝ : Type w\nB : Type u_1\ninst✝⁷ : CommSemiring R✝\ninst✝⁶ : CommSemiring S\ninst✝⁵ : Semiring A✝\ninst✝⁴ : Algebra R✝ A✝\ninst✝³ : Semiring B\ninst✝² : Algebra R✝ B\nR : Type u_2\ninst✝¹ : CommSemiring R\nA : Type u_3\ninst✝ : Semiring A\nP Q : Algebra R A\nh : toRingHom = toRingHom\n⊢ (fun x x_1 => x • x_1) = fun x x_1 => x • x_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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n ","nextTactic":"funext r a","declUpToTactic":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.310_0.lJPMR9lAgdsHXom","decl":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI "} +{"state":"case h.h\nR✝ : Type u\nS : Type v\nA✝ : Type w\nB : Type u_1\ninst✝⁷ : CommSemiring R✝\ninst✝⁶ : CommSemiring S\ninst✝⁵ : Semiring A✝\ninst✝⁴ : Algebra R✝ A✝\ninst✝³ : Semiring B\ninst✝² : Algebra R✝ B\nR : Type u_2\ninst✝¹ : CommSemiring R\nA : Type u_3\ninst✝ : Semiring A\nP Q : Algebra R A\nh : toRingHom = toRingHom\nr : R\na : A\n⊢ r • a = r • 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h���, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n ","nextTactic":"rw [P.smul_def']","declUpToTactic":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.310_0.lJPMR9lAgdsHXom","decl":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI "} +{"state":"case h.h\nR✝ : Type u\nS : Type v\nA✝ : Type w\nB : Type u_1\ninst✝⁷ : CommSemiring R✝\ninst✝⁶ : CommSemiring S\ninst✝⁵ : Semiring A✝\ninst✝⁴ : Algebra R✝ A✝\ninst✝³ : Semiring B\ninst✝² : Algebra R✝ B\nR : Type u_2\ninst✝¹ : CommSemiring R\nA : Type u_3\ninst✝ : Semiring A\nP Q : Algebra R A\nh : toRingHom = toRingHom\nr : R\na : A\n⊢ toRingHom r * a = r • 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n ","nextTactic":"rw [Q.smul_def']","declUpToTactic":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.310_0.lJPMR9lAgdsHXom","decl":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI "} +{"state":"case h.h\nR✝ : Type u\nS : Type v\nA✝ : Type w\nB : Type u_1\ninst✝⁷ : CommSemiring R✝\ninst✝⁶ : CommSemiring S\ninst✝⁵ : Semiring A✝\ninst✝⁴ : Algebra R✝ A✝\ninst✝³ : Semiring B\ninst✝² : Algebra R✝ B\nR : Type u_2\ninst✝¹ : CommSemiring R\nA : Type u_3\ninst✝ : Semiring A\nP Q : Algebra R A\nh : toRingHom = toRingHom\nr : R\na : A\n⊢ toRingHom r * a = toRingHom r * 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n ","nextTactic":"rw [h]","declUpToTactic":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.310_0.lJPMR9lAgdsHXom","decl":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI "} +{"state":"R✝ : Type u\nS : Type v\nA✝ : Type w\nB : Type u_1\ninst✝⁷ : CommSemiring R✝\ninst✝⁶ : CommSemiring S\ninst✝⁵ : Semiring A✝\ninst✝⁴ : Algebra R✝ A✝\ninst✝³ : Semiring B\ninst✝² : Algebra R✝ B\nR : Type u_2\ninst✝¹ : CommSemiring R\nA : Type u_3\ninst✝ : Semiring A\nP Q : Algebra R A\nh : toRingHom = toRingHom\nh' : (fun x x_1 => x • x_1) = fun x x_1 => x • x_1\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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n ","nextTactic":"rcases P with @⟨⟨P⟩⟩","declUpToTactic":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.310_0.lJPMR9lAgdsHXom","decl":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI "} +{"state":"case mk.mk\nR✝ : Type u\nS : Type v\nA✝ : Type w\nB : Type u_1\ninst✝⁷ : CommSemiring R✝\ninst✝⁶ : CommSemiring S\ninst✝⁵ : Semiring A✝\ninst✝⁴ : Algebra R✝ A✝\ninst✝³ : Semiring B\ninst✝² : Algebra R✝ B\nR : Type u_2\ninst✝¹ : CommSemiring R\nA : Type u_3\ninst✝ : Semiring A\nQ : Algebra R A\ntoRingHom✝ : R →+* A\ncommutes'✝ : ∀ (r : R) (x : A), toRingHom✝ r * x = x * toRingHom✝ r\nP : R → A → A\nsmul_def'✝ : ∀ (r : R) (x : A), r • x = toRingHom✝ r * x\nh : toRingHom = toRingHom\nh' : (fun x x_1 => x • x_1) = fun x x_1 => x • x_1\n⊢ mk toRingHom✝ commutes'✝ smul_def'✝ = 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n ","nextTactic":"rcases Q with @⟨⟨Q⟩⟩","declUpToTactic":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.310_0.lJPMR9lAgdsHXom","decl":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI "} +{"state":"case mk.mk.mk.mk\nR✝ : Type u\nS : Type v\nA✝ : Type w\nB : Type u_1\ninst✝⁷ : CommSemiring R✝\ninst✝⁶ : CommSemiring S\ninst✝⁵ : Semiring A✝\ninst✝⁴ : Algebra R✝ A✝\ninst✝³ : Semiring B\ninst✝² : Algebra R✝ B\nR : Type u_2\ninst✝¹ : CommSemiring R\nA : Type u_3\ninst✝ : Semiring A\ntoRingHom✝¹ : R →+* A\ncommutes'✝¹ : ∀ (r : R) (x : A), toRingHom✝¹ r * x = x * toRingHom✝¹ r\nP : R → A → A\nsmul_def'✝¹ : ∀ (r : R) (x : A), r • x = toRingHom✝¹ r * x\ntoRingHom✝ : R →+* A\ncommutes'✝ : ∀ (r : R) (x : A), toRingHom✝ r * x = x * toRingHom✝ r\nQ : R → A → A\nsmul_def'✝ : ∀ (r : R) (x : A), r • x = toRingHom✝ r * x\nh : toRingHom = toRingHom\nh' : (fun x x_1 => x • x_1) = fun x x_1 => x • x_1\n⊢ mk toRingHom✝¹ commutes'✝¹ smul_def'✝¹ = mk toRingHom✝ commutes'✝ smul_def'✝","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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n ","nextTactic":"congr","declUpToTactic":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.310_0.lJPMR9lAgdsHXom","decl":"/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁵ : CommSemiring R\ninst✝⁴ : CommSemiring S\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nx✝ : A\n⊢ 1 • 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by ","nextTactic":"simp [smul_def']","declUpToTactic":"instance (priority := 200) toModule : Module R A where\n one_smul _ := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.329_0.lJPMR9lAgdsHXom","decl":"instance (priority "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁵ : CommSemiring R\ninst✝⁴ : CommSemiring S\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\n⊢ ∀ (x y : R) (b : A), (x * y) • b = x • y • b","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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by ","nextTactic":"simp [smul_def', mul_assoc]","declUpToTactic":"instance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.329_0.lJPMR9lAgdsHXom","decl":"instance (priority "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁵ : CommSemiring R\ninst✝⁴ : CommSemiring S\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\n⊢ ∀ (a : R), a • 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by ","nextTactic":"simp [smul_def']","declUpToTactic":"instance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.329_0.lJPMR9lAgdsHXom","decl":"instance (priority "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁵ : CommSemiring R\ninst✝⁴ : CommSemiring S\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\n⊢ ∀ (a : R) (x y : A), a • (x + y) = a • x + a • 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by ","nextTactic":"simp [smul_def', mul_add]","declUpToTactic":"instance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.329_0.lJPMR9lAgdsHXom","decl":"instance (priority "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁵ : CommSemiring R\ninst✝⁴ : CommSemiring S\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\n⊢ ∀ (r s : R) (x : A), (r + s) • x = r • 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by ","nextTactic":"simp [smul_def', add_mul]","declUpToTactic":"instance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.329_0.lJPMR9lAgdsHXom","decl":"instance (priority "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁵ : CommSemiring R\ninst✝⁴ : CommSemiring S\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\n⊢ ∀ (x : A), 0 • x = 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by ","nextTactic":"simp [smul_def']","declUpToTactic":"instance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.329_0.lJPMR9lAgdsHXom","decl":"instance (priority "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁵ : CommSemiring R\ninst✝⁴ : CommSemiring S\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nx : A\nr : R\ny : A\n⊢ x * ((algebraMap R A) r * y) = (algebraMap R A) r * (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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n ","nextTactic":"rw [← mul_assoc]","declUpToTactic":"/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.366_0.lJPMR9lAgdsHXom","decl":"/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁵ : CommSemiring R\ninst✝⁴ : CommSemiring S\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nx : A\nr : R\ny : A\n⊢ x * (algebraMap R A) r * y = (algebraMap R A) r * (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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n ","nextTactic":"rw [← commutes]","declUpToTactic":"/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.366_0.lJPMR9lAgdsHXom","decl":"/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁵ : CommSemiring R\ninst✝⁴ : CommSemiring S\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nx : A\nr : R\ny : A\n⊢ (algebraMap R A) r * x * y = (algebraMap R A) r * (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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n ","nextTactic":"rw [mul_assoc]","declUpToTactic":"/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.366_0.lJPMR9lAgdsHXom","decl":"/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁵ : CommSemiring R\ninst✝⁴ : CommSemiring S\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nx : A\nr : R\ny : A\n⊢ x * (algebraMap R A) r * y = x * y * (algebraMap R A) 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n ","nextTactic":"rw [mul_assoc]","declUpToTactic":"/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.374_0.lJPMR9lAgdsHXom","decl":"/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁵ : CommSemiring R\ninst✝⁴ : CommSemiring S\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nx : A\nr : R\ny : A\n⊢ x * ((algebraMap R A) r * y) = x * y * (algebraMap R A) 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n ","nextTactic":"rw [commutes]","declUpToTactic":"/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.374_0.lJPMR9lAgdsHXom","decl":"/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁵ : CommSemiring R\ninst✝⁴ : CommSemiring S\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nx : A\nr : R\ny : A\n⊢ x * (y * (algebraMap R A) r) = x * y * (algebraMap R A) 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n ","nextTactic":"rw [← mul_assoc]","declUpToTactic":"/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.374_0.lJPMR9lAgdsHXom","decl":"/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁵ : CommSemiring R\ninst✝⁴ : CommSemiring S\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nx : R\ny z : A\n⊢ (x • y) • z = x • y • z","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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R ���+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by ","nextTactic":"rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]","declUpToTactic":"instance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.382_0.lJPMR9lAgdsHXom","decl":"instance _root_.IsScalarTower.right : IsScalarTower R A A "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁵ : CommSemiring R\ninst✝⁴ : CommSemiring S\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\ns : R\nx y : A\n⊢ x * s • y = s • (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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n ","nextTactic":"rw [smul_def]","declUpToTactic":"/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.393_0.lJPMR9lAgdsHXom","decl":"/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁵ : CommSemiring R\ninst✝⁴ : CommSemiring S\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\ns : R\nx y : A\n⊢ x * ((algebraMap R A) s * y) = s • (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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n ","nextTactic":"rw [smul_def]","declUpToTactic":"/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.393_0.lJPMR9lAgdsHXom","decl":"/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁵ : CommSemiring R\ninst✝⁴ : CommSemiring S\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\ns : R\nx y : A\n⊢ x * ((algebraMap R A) s * y) = (algebraMap R A) s * (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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n ","nextTactic":"rw [left_comm]","declUpToTactic":"/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.393_0.lJPMR9lAgdsHXom","decl":"/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁸ : CommSemiring R\ninst✝⁷ : CommSemiring S\ninst✝⁶ : Semiring A\ninst✝⁵ : Algebra R A\ninst✝⁴ : Semiring B\ninst✝³ : Algebra R B\nα : Type u_2\ninst✝² : Monoid α\ninst✝¹ : MulDistribMulAction α A\ninst✝ : SMulCommClass α R A\na : α\nr : R\n⊢ a • (algebraMap R A) r = (algebraMap R A) 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n ","nextTactic":"rw [algebraMap_eq_smul_one]","declUpToTactic":"@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.409_0.lJPMR9lAgdsHXom","decl":"@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁸ : CommSemiring R\ninst✝⁷ : CommSemiring S\ninst✝⁶ : Semiring A\ninst✝⁵ : Algebra R A\ninst✝⁴ : Semiring B\ninst✝³ : Algebra R B\nα : Type u_2\ninst✝² : Monoid α\ninst✝¹ : MulDistribMulAction α A\ninst✝ : SMulCommClass α R A\na : α\nr : R\n⊢ a • r • 1 = r • 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n ","nextTactic":"rw [smul_comm a r (1 : A)]","declUpToTactic":"@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.409_0.lJPMR9lAgdsHXom","decl":"@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁸ : CommSemiring R\ninst✝⁷ : CommSemiring S\ninst✝⁶ : Semiring A\ninst✝⁵ : Algebra R A\ninst✝⁴ : Semiring B\ninst✝³ : Algebra R B\nα : Type u_2\ninst✝² : Monoid α\ninst✝¹ : MulDistribMulAction α A\ninst✝ : SMulCommClass α R A\na : α\nr : R\n⊢ r • a • 1 = r • 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n ","nextTactic":"rw [smul_one]","declUpToTactic":"@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.409_0.lJPMR9lAgdsHXom","decl":"@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝⁵ : CommSemiring R\ninst✝⁴ : CommSemiring S\ninst✝³ : Semiring A\ninst✝² : Algebra R A\ninst✝¹ : Semiring B\ninst✝ : Algebra R B\nsrc✝ : R →+* A := algebraMap R A\nx y : R\n⊢ AddHom.toFun\n { toFun := src✝.toFun,\n map_add' :=\n (_ : ∀ (x y : R), OneHom.toFun (↑↑src✝) (x + y) = OneHom.toFun (↑↑src✝) x + OneHom.toFun (↑↑src✝) y) }\n (x • y) =\n (RingHom.id R) x •\n AddHom.toFun\n { toFun := src✝.toFun,\n map_add' :=\n (_ : ∀ (x y : R), OneHom.toFun (↑↑src✝) (x + y) = OneHom.toFun (↑↑src✝) x + OneHom.toFun (↑↑src✝) 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by ","nextTactic":"simp [Algebra.smul_def]","declUpToTactic":"/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.432_0.lJPMR9lAgdsHXom","decl":"/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝² : CommSemiring R\ninst✝¹ : Ring A\ninst✝ : Algebra R A\nx : A\nr : R\n⊢ x * (x - (algebraMap R A) r) = (x - (algebraMap R A) r) * 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by ","nextTactic":"rw [mul_sub, ← commutes, sub_mul]","declUpToTactic":"theorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.575_0.lJPMR9lAgdsHXom","decl":"theorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝² : CommSemiring R\ninst✝¹ : Ring A\ninst✝ : Algebra R A\nx : A\nr : R\nn : ℕ\n⊢ x * (x - (algebraMap R A) r) ^ n = (x - (algebraMap R A) r) ^ 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n ","nextTactic":"induction' n with n ih","declUpToTactic":"theorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.579_0.lJPMR9lAgdsHXom","decl":"theorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x "} +{"state":"case zero\nR : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝² : CommSemiring R\ninst✝¹ : Ring A\ninst✝ : Algebra R A\nx : A\nr : R\n⊢ x * (x - (algebraMap R A) r) ^ Nat.zero = (x - (algebraMap R A) r) ^ Nat.zero * 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · ","nextTactic":"simp","declUpToTactic":"theorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.579_0.lJPMR9lAgdsHXom","decl":"theorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x "} +{"state":"case succ\nR : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝² : CommSemiring R\ninst✝¹ : Ring A\ninst✝ : Algebra R A\nx : A\nr : R\nn : ℕ\nih : x * (x - (algebraMap R A) r) ^ n = (x - (algebraMap R A) r) ^ n * x\n⊢ x * (x - (algebraMap R A) r) ^ Nat.succ n = (x - (algebraMap R A) r) ^ Nat.succ 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · ","nextTactic":"rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]","declUpToTactic":"theorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.579_0.lJPMR9lAgdsHXom","decl":"theorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝² : CommRing R\ninst✝¹ : Semiring A\ninst✝ : Algebra R A\nsrc✝¹ : AddCommGroup A := Module.addCommMonoidToAddCommGroup R\nsrc✝ : Semiring A := inferInstance\nz : ℕ\n⊢ IntCast.intCast ↑z = ↑z","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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by ","nextTactic":"simp only [Int.cast_ofNat, map_natCast]","declUpToTactic":"/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.594_0.lJPMR9lAgdsHXom","decl":"/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A "} +{"state":"R : Type u\nS : Type v\nA : Type w\nB : Type u_1\ninst✝² : CommRing R\ninst✝¹ : Semiring A\ninst✝ : Algebra R A\nsrc✝¹ : AddCommGroup A := Module.addCommMonoidToAddCommGroup R\nsrc✝ : Semiring A := inferInstance\nz : ℕ\n⊢ IntCast.intCast (Int.negSucc z) = -↑(z + 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by ","nextTactic":"simp","declUpToTactic":"/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.594_0.lJPMR9lAgdsHXom","decl":"/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A "} +{"state":"R : Type u\nS : Type v\nM : Type w\ninst✝⁷ : CommSemiring R\ninst✝⁶ : Semiring S\ninst✝⁵ : AddCommMonoid M\ninst✝⁴ : Module R M\ninst✝³ : Module S M\ninst✝² : SMulCommClass S R M\ninst✝¹ : SMul R S\ninst✝ : IsScalarTower R S M\nx : R\nh : IsUnit ((algebraMap R (End S M)) x)\nm m' : M\nH : m = x • m'\n⊢ ↑(IsUnit.unit h)⁻¹ (x • m') = m'","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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n ","nextTactic":"apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective","declUpToTactic":"theorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.640_0.lJPMR9lAgdsHXom","decl":"theorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' "} +{"state":"R : Type u\nS : Type v\nM : Type w\ninst✝⁷ : CommSemiring R\ninst✝⁶ : Semiring S\ninst✝⁵ : AddCommMonoid M\ninst✝⁴ : Module R M\ninst✝³ : Module S M\ninst✝² : SMulCommClass S R M\ninst✝¹ : SMul R S\ninst✝ : IsScalarTower R S M\nx : R\nh : IsUnit ((algebraMap R (End S M)) x)\nm m' : M\nH : m = x • m'\n⊢ ↑(IsUnit.unit h) (↑(IsUnit.unit h)⁻¹ (x • m')) = ↑(IsUnit.unit h) m'","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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n ","nextTactic":"erw [End_isUnit_apply_inv_apply_of_isUnit]","declUpToTactic":"theorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.640_0.lJPMR9lAgdsHXom","decl":"theorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' "} +{"state":"R : Type u\nS : Type v\nM : Type w\ninst✝⁷ : CommSemiring R\ninst✝⁶ : Semiring S\ninst✝⁵ : AddCommMonoid M\ninst✝⁴ : Module R M\ninst✝³ : Module S M\ninst✝² : SMulCommClass S R M\ninst✝¹ : SMul R S\ninst✝ : IsScalarTower R S M\nx : R\nh : IsUnit ((algebraMap R (End S M)) x)\nm m' : M\nH : m = x • m'\n⊢ x • m' = ↑(IsUnit.unit h) m'","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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n ","nextTactic":"rfl","declUpToTactic":"theorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.640_0.lJPMR9lAgdsHXom","decl":"theorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' "} +{"state":"R : Type u\nS : Type v\nM : Type w\ninst✝⁷ : CommSemiring R\ninst✝⁶ : Semiring S\ninst✝⁵ : AddCommMonoid M\ninst✝⁴ : Module R M\ninst✝³ : Module S M\ninst✝² : SMulCommClass S R M\ninst✝¹ : SMul R S\ninst✝ : IsScalarTower R S M\nx : R\nh : IsUnit ((algebraMap R (End S M)) x)\nm m' : M\nH : m = x • m'\n⊢ m' = ↑(IsUnit.unit h)⁻¹ (x • m')","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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n ","nextTactic":"apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective","declUpToTactic":"theorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.651_0.lJPMR9lAgdsHXom","decl":"theorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' "} +{"state":"R : Type u\nS : Type v\nM : Type w\ninst✝⁷ : CommSemiring R\ninst✝⁶ : Semiring S\ninst✝⁵ : AddCommMonoid M\ninst✝⁴ : Module R M\ninst✝³ : Module S M\ninst✝² : SMulCommClass S R M\ninst✝¹ : SMul R S\ninst✝ : IsScalarTower R S M\nx : R\nh : IsUnit ((algebraMap R (End S M)) x)\nm m' : M\nH : m = x • m'\n⊢ ↑(IsUnit.unit h) m' = ↑(IsUnit.unit h) (↑(IsUnit.unit h)⁻¹ (x • m'))","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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n ","nextTactic":"erw [End_isUnit_apply_inv_apply_of_isUnit]","declUpToTactic":"theorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.651_0.lJPMR9lAgdsHXom","decl":"theorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' "} +{"state":"R : Type u\nS : Type v\nM : Type w\ninst✝⁷ : CommSemiring R\ninst✝⁶ : Semiring S\ninst✝⁵ : AddCommMonoid M\ninst✝⁴ : Module R M\ninst✝³ : Module S M\ninst✝² : SMulCommClass S R M\ninst✝¹ : SMul R S\ninst✝ : IsScalarTower R S M\nx : R\nh : IsUnit ((algebraMap R (End S M)) x)\nm m' : M\nH : m = x • m'\n⊢ ↑(IsUnit.unit h) m' = x • m'","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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n ","nextTactic":"rfl","declUpToTactic":"theorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.651_0.lJPMR9lAgdsHXom","decl":"theorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' "} +{"state":"R : Type u_1\nA : Type u_2\nB : Type u_3\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Semiring B\ninst✝¹ : Algebra R A\ninst✝ : Algebra R B\nf : A →ₗ[R] B\na : A\nr : R\n⊢ f ((algebraMap R A) r * a) = (algebraMap R B) r * f 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n ","nextTactic":"rw [← Algebra.smul_def]","declUpToTactic":"/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.671_0.lJPMR9lAgdsHXom","decl":"/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a "} +{"state":"R : Type u_1\nA : Type u_2\nB : Type u_3\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Semiring B\ninst✝¹ : Algebra R A\ninst✝ : Algebra R B\nf : A →ₗ[R] B\na : A\nr : R\n⊢ f (r • a) = (algebraMap R B) r * f 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n ","nextTactic":"rw [← Algebra.smul_def]","declUpToTactic":"/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.671_0.lJPMR9lAgdsHXom","decl":"/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a "} +{"state":"R : Type u_1\nA : Type u_2\nB : Type u_3\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Semiring B\ninst✝¹ : Algebra R A\ninst✝ : Algebra R B\nf : A →ₗ[R] B\na : A\nr : R\n⊢ f (r • a) = r • f 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n ","nextTactic":"rw [map_smul]","declUpToTactic":"/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.671_0.lJPMR9lAgdsHXom","decl":"/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a "} +{"state":"R : Type u_1\nA : Type u_2\nB : Type u_3\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Semiring B\ninst✝¹ : Algebra R A\ninst✝ : Algebra R B\nf : A →ₗ[R] B\na : A\nr : R\n⊢ f (a * (algebraMap R A) r) = f a * (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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (��h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n ","nextTactic":"rw [← Algebra.commutes]","declUpToTactic":"theorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.680_0.lJPMR9lAgdsHXom","decl":"theorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r "} +{"state":"R : Type u_1\nA : Type u_2\nB : Type u_3\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Semiring B\ninst✝¹ : Algebra R A\ninst✝ : Algebra R B\nf : A →ₗ[R] B\na : A\nr : R\n⊢ f ((algebraMap R A) r * a) = f a * (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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n ","nextTactic":"rw [← Algebra.commutes]","declUpToTactic":"theorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.680_0.lJPMR9lAgdsHXom","decl":"theorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r "} +{"state":"R : Type u_1\nA : Type u_2\nB : Type u_3\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Semiring B\ninst✝¹ : Algebra R A\ninst✝ : Algebra R B\nf : A →ₗ[R] B\na : A\nr : R\n⊢ f ((algebraMap R A) r * a) = (algebraMap R B) r * f 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n ","nextTactic":"rw [map_algebraMap_mul]","declUpToTactic":"theorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.680_0.lJPMR9lAgdsHXom","decl":"theorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r "} +{"state":"R : Type u_1\ninst✝ : Semiring R\nP Q : Algebra ℕ R\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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ","nextTactic":"ext","declUpToTactic":"instance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.703_0.lJPMR9lAgdsHXom","decl":"instance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) "} +{"state":"case h\nR : Type u_1\ninst✝ : Semiring R\nP Q : Algebra ℕ R\nr✝ : ℕ\n⊢ (algebraMap ℕ R) r✝ = (algebraMap ℕ R) 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; ","nextTactic":"simp","declUpToTactic":"instance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.703_0.lJPMR9lAgdsHXom","decl":"instance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) "} +{"state":"R : Type u_1\nA : Type u_2\ninst✝⁴ : CommRing R\ninst✝³ : Ring A\ninst✝² : Nontrivial A\ninst✝¹ : Algebra R A\ninst✝ : NoZeroSMulDivisors R A\n⊢ Function.Injective ⇑(algebraMap R 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n ","nextTactic":"have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero","declUpToTactic":"theorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.792_0.lJPMR9lAgdsHXom","decl":"theorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) "} +{"state":"R : Type u_1\nA : Type u_2\ninst✝⁴ : CommRing R\ninst✝³ : Ring A\ninst✝² : Nontrivial A\ninst✝¹ : Algebra R A\ninst✝ : NoZeroSMulDivisors R A\nthis : Function.Injective fun c => c • 1\n⊢ Function.Injective ⇑(algebraMap R 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n ","nextTactic":"simpa only [algebraMap_eq_smul_one'] using this","declUpToTactic":"theorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.792_0.lJPMR9lAgdsHXom","decl":"theorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) "} +{"state":"R : Type u_1\ninst✝¹⁰ : CommSemiring R\nA : Type u_2\ninst✝⁹ : Semiring A\ninst✝⁸ : Algebra R A\nM : Type u_3\ninst✝⁷ : AddCommMonoid M\ninst✝⁶ : Module A M\ninst✝⁵ : Module R M\ninst✝⁴ : IsScalarTower R A M\nN : Type u_4\ninst✝³ : AddCommMonoid N\ninst✝² : Module A N\ninst✝¹ : Module R N\ninst✝ : IsScalarTower R A N\nr : R\nm : M\n⊢ r • m = (algebraMap R A) r • m","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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n simpa only [algebraMap_eq_smul_one'] using this\n#align no_zero_smul_divisors.algebra_map_injective NoZeroSMulDivisors.algebraMap_injective\n\ntheorem _root_.NeZero.of_noZeroSMulDivisors (n : ℕ) [CommRing R] [NeZero (n : R)] [Ring A]\n [Nontrivial A] [Algebra R A] [NoZeroSMulDivisors R A] : NeZero (n : A) :=\n -- porting note: todo: drop implicit args\n @NeZero.nat_of_injective R A (R →+* A) _ _ n ‹_› _ _ <|\n NoZeroSMulDivisors.algebraMap_injective R A\n#align ne_zero.of_no_zero_smul_divisors NeZero.of_noZeroSMulDivisors\n\nvariable {R A}\n\ntheorem iff_algebraMap_injective [CommRing R] [Ring A] [IsDomain A] [Algebra R A] :\n NoZeroSMulDivisors R A ↔ Function.Injective (algebraMap R A) :=\n ⟨@NoZeroSMulDivisors.algebraMap_injective R A _ _ _ _, NoZeroSMulDivisors.of_algebraMap_injective⟩\n#align no_zero_smul_divisors.iff_algebra_map_injective NoZeroSMulDivisors.iff_algebraMap_injective\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_nat [Semiring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℕ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℕ R).injective_nat\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_nat NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_nat\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_int [Ring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℤ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℤ R).injective_int\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_int NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_int\n\nsection Field\n\nvariable [Field R] [Semiring A] [Algebra R A]\n\n-- see note [lower instance priority]\ninstance (priority := 100) Algebra.noZeroSMulDivisors [Nontrivial A] [NoZeroDivisors A] :\n NoZeroSMulDivisors R A :=\n NoZeroSMulDivisors.of_algebraMap_injective (algebraMap R A).injective\n#align no_zero_smul_divisors.algebra.no_zero_smul_divisors NoZeroSMulDivisors.Algebra.noZeroSMulDivisors\n\nend Field\n\nend NoZeroSMulDivisors\n\nsection IsScalarTower\n\nvariable {R : Type*} [CommSemiring R]\nvariable (A : Type*) [Semiring A] [Algebra R A]\nvariable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]\nvariable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A N]\n\ntheorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n ","nextTactic":"rw [← one_smul A m]","declUpToTactic":"theorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.847_0.lJPMR9lAgdsHXom","decl":"theorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m "} +{"state":"R : Type u_1\ninst✝¹⁰ : CommSemiring R\nA : Type u_2\ninst✝⁹ : Semiring A\ninst✝⁸ : Algebra R A\nM : Type u_3\ninst✝⁷ : AddCommMonoid M\ninst✝⁶ : Module A M\ninst✝⁵ : Module R M\ninst✝⁴ : IsScalarTower R A M\nN : Type u_4\ninst✝³ : AddCommMonoid N\ninst✝² : Module A N\ninst✝¹ : Module R N\ninst✝ : IsScalarTower R A N\nr : R\nm : M\n⊢ r • 1 • m = (algebraMap R A) r • 1 • m","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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n simpa only [algebraMap_eq_smul_one'] using this\n#align no_zero_smul_divisors.algebra_map_injective NoZeroSMulDivisors.algebraMap_injective\n\ntheorem _root_.NeZero.of_noZeroSMulDivisors (n : ℕ) [CommRing R] [NeZero (n : R)] [Ring A]\n [Nontrivial A] [Algebra R A] [NoZeroSMulDivisors R A] : NeZero (n : A) :=\n -- porting note: todo: drop implicit args\n @NeZero.nat_of_injective R A (R →+* A) _ _ n ‹_› _ _ <|\n NoZeroSMulDivisors.algebraMap_injective R A\n#align ne_zero.of_no_zero_smul_divisors NeZero.of_noZeroSMulDivisors\n\nvariable {R A}\n\ntheorem iff_algebraMap_injective [CommRing R] [Ring A] [IsDomain A] [Algebra R A] :\n NoZeroSMulDivisors R A ↔ Function.Injective (algebraMap R A) :=\n ⟨@NoZeroSMulDivisors.algebraMap_injective R A _ _ _ _, NoZeroSMulDivisors.of_algebraMap_injective⟩\n#align no_zero_smul_divisors.iff_algebra_map_injective NoZeroSMulDivisors.iff_algebraMap_injective\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_nat [Semiring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℕ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℕ R).injective_nat\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_nat NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_nat\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_int [Ring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℤ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℤ R).injective_int\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_int NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_int\n\nsection Field\n\nvariable [Field R] [Semiring A] [Algebra R A]\n\n-- see note [lower instance priority]\ninstance (priority := 100) Algebra.noZeroSMulDivisors [Nontrivial A] [NoZeroDivisors A] :\n NoZeroSMulDivisors R A :=\n NoZeroSMulDivisors.of_algebraMap_injective (algebraMap R A).injective\n#align no_zero_smul_divisors.algebra.no_zero_smul_divisors NoZeroSMulDivisors.Algebra.noZeroSMulDivisors\n\nend Field\n\nend NoZeroSMulDivisors\n\nsection IsScalarTower\n\nvariable {R : Type*} [CommSemiring R]\nvariable (A : Type*) [Semiring A] [Algebra R A]\nvariable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]\nvariable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A N]\n\ntheorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n ","nextTactic":"rw [← smul_assoc]","declUpToTactic":"theorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.847_0.lJPMR9lAgdsHXom","decl":"theorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m "} +{"state":"R : Type u_1\ninst✝¹⁰ : CommSemiring R\nA : Type u_2\ninst✝⁹ : Semiring A\ninst✝⁸ : Algebra R A\nM : Type u_3\ninst✝⁷ : AddCommMonoid M\ninst✝⁶ : Module A M\ninst✝⁵ : Module R M\ninst✝⁴ : IsScalarTower R A M\nN : Type u_4\ninst✝³ : AddCommMonoid N\ninst✝² : Module A N\ninst✝¹ : Module R N\ninst✝ : IsScalarTower R A N\nr : R\nm : M\n⊢ (r • 1) • m = (algebraMap R A) r • 1 • m","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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n simpa only [algebraMap_eq_smul_one'] using this\n#align no_zero_smul_divisors.algebra_map_injective NoZeroSMulDivisors.algebraMap_injective\n\ntheorem _root_.NeZero.of_noZeroSMulDivisors (n : ℕ) [CommRing R] [NeZero (n : R)] [Ring A]\n [Nontrivial A] [Algebra R A] [NoZeroSMulDivisors R A] : NeZero (n : A) :=\n -- porting note: todo: drop implicit args\n @NeZero.nat_of_injective R A (R →+* A) _ _ n ‹_› _ _ <|\n NoZeroSMulDivisors.algebraMap_injective R A\n#align ne_zero.of_no_zero_smul_divisors NeZero.of_noZeroSMulDivisors\n\nvariable {R A}\n\ntheorem iff_algebraMap_injective [CommRing R] [Ring A] [IsDomain A] [Algebra R A] :\n NoZeroSMulDivisors R A ↔ Function.Injective (algebraMap R A) :=\n ⟨@NoZeroSMulDivisors.algebraMap_injective R A _ _ _ _, NoZeroSMulDivisors.of_algebraMap_injective⟩\n#align no_zero_smul_divisors.iff_algebra_map_injective NoZeroSMulDivisors.iff_algebraMap_injective\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_nat [Semiring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℕ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℕ R).injective_nat\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_nat NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_nat\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_int [Ring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℤ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℤ R).injective_int\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_int NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_int\n\nsection Field\n\nvariable [Field R] [Semiring A] [Algebra R A]\n\n-- see note [lower instance priority]\ninstance (priority := 100) Algebra.noZeroSMulDivisors [Nontrivial A] [NoZeroDivisors A] :\n NoZeroSMulDivisors R A :=\n NoZeroSMulDivisors.of_algebraMap_injective (algebraMap R A).injective\n#align no_zero_smul_divisors.algebra.no_zero_smul_divisors NoZeroSMulDivisors.Algebra.noZeroSMulDivisors\n\nend Field\n\nend NoZeroSMulDivisors\n\nsection IsScalarTower\n\nvariable {R : Type*} [CommSemiring R]\nvariable (A : Type*) [Semiring A] [Algebra R A]\nvariable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]\nvariable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A N]\n\ntheorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n rw [← smul_assoc]\n ","nextTactic":"rw [Algebra.smul_def]","declUpToTactic":"theorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n rw [← smul_assoc]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.847_0.lJPMR9lAgdsHXom","decl":"theorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m "} +{"state":"R : Type u_1\ninst✝¹⁰ : CommSemiring R\nA : Type u_2\ninst✝⁹ : Semiring A\ninst✝⁸ : Algebra R A\nM : Type u_3\ninst✝⁷ : AddCommMonoid M\ninst✝⁶ : Module A M\ninst✝⁵ : Module R M\ninst✝⁴ : IsScalarTower R A M\nN : Type u_4\ninst✝³ : AddCommMonoid N\ninst✝² : Module A N\ninst✝¹ : Module R N\ninst✝ : IsScalarTower R A N\nr : R\nm : M\n⊢ ((algebraMap R A) r * 1) • m = (algebraMap R A) r • 1 • m","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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n simpa only [algebraMap_eq_smul_one'] using this\n#align no_zero_smul_divisors.algebra_map_injective NoZeroSMulDivisors.algebraMap_injective\n\ntheorem _root_.NeZero.of_noZeroSMulDivisors (n : ℕ) [CommRing R] [NeZero (n : R)] [Ring A]\n [Nontrivial A] [Algebra R A] [NoZeroSMulDivisors R A] : NeZero (n : A) :=\n -- porting note: todo: drop implicit args\n @NeZero.nat_of_injective R A (R →+* A) _ _ n ‹_› _ _ <|\n NoZeroSMulDivisors.algebraMap_injective R A\n#align ne_zero.of_no_zero_smul_divisors NeZero.of_noZeroSMulDivisors\n\nvariable {R A}\n\ntheorem iff_algebraMap_injective [CommRing R] [Ring A] [IsDomain A] [Algebra R A] :\n NoZeroSMulDivisors R A ↔ Function.Injective (algebraMap R A) :=\n ⟨@NoZeroSMulDivisors.algebraMap_injective R A _ _ _ _, NoZeroSMulDivisors.of_algebraMap_injective⟩\n#align no_zero_smul_divisors.iff_algebra_map_injective NoZeroSMulDivisors.iff_algebraMap_injective\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_nat [Semiring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℕ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℕ R).injective_nat\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_nat NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_nat\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_int [Ring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℤ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℤ R).injective_int\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_int NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_int\n\nsection Field\n\nvariable [Field R] [Semiring A] [Algebra R A]\n\n-- see note [lower instance priority]\ninstance (priority := 100) Algebra.noZeroSMulDivisors [Nontrivial A] [NoZeroDivisors A] :\n NoZeroSMulDivisors R A :=\n NoZeroSMulDivisors.of_algebraMap_injective (algebraMap R A).injective\n#align no_zero_smul_divisors.algebra.no_zero_smul_divisors NoZeroSMulDivisors.Algebra.noZeroSMulDivisors\n\nend Field\n\nend NoZeroSMulDivisors\n\nsection IsScalarTower\n\nvariable {R : Type*} [CommSemiring R]\nvariable (A : Type*) [Semiring A] [Algebra R A]\nvariable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]\nvariable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A N]\n\ntheorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n rw [← smul_assoc]\n rw [Algebra.smul_def]\n ","nextTactic":"rw [mul_one]","declUpToTactic":"theorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n rw [← smul_assoc]\n rw [Algebra.smul_def]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.847_0.lJPMR9lAgdsHXom","decl":"theorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m "} +{"state":"R : Type u_1\ninst✝¹⁰ : CommSemiring R\nA : Type u_2\ninst✝��� : Semiring A\ninst✝⁸ : Algebra R A\nM : Type u_3\ninst✝⁷ : AddCommMonoid M\ninst✝⁶ : Module A M\ninst✝⁵ : Module R M\ninst✝⁴ : IsScalarTower R A M\nN : Type u_4\ninst✝³ : AddCommMonoid N\ninst✝² : Module A N\ninst✝¹ : Module R N\ninst✝ : IsScalarTower R A N\nr : R\nm : M\n⊢ (algebraMap R A) r • m = (algebraMap R A) r • 1 • m","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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n simpa only [algebraMap_eq_smul_one'] using this\n#align no_zero_smul_divisors.algebra_map_injective NoZeroSMulDivisors.algebraMap_injective\n\ntheorem _root_.NeZero.of_noZeroSMulDivisors (n : ℕ) [CommRing R] [NeZero (n : R)] [Ring A]\n [Nontrivial A] [Algebra R A] [NoZeroSMulDivisors R A] : NeZero (n : A) :=\n -- porting note: todo: drop implicit args\n @NeZero.nat_of_injective R A (R →+* A) _ _ n ‹_› _ _ <|\n NoZeroSMulDivisors.algebraMap_injective R A\n#align ne_zero.of_no_zero_smul_divisors NeZero.of_noZeroSMulDivisors\n\nvariable {R A}\n\ntheorem iff_algebraMap_injective [CommRing R] [Ring A] [IsDomain A] [Algebra R A] :\n NoZeroSMulDivisors R A ↔ Function.Injective (algebraMap R A) :=\n ⟨@NoZeroSMulDivisors.algebraMap_injective R A _ _ _ _, NoZeroSMulDivisors.of_algebraMap_injective⟩\n#align no_zero_smul_divisors.iff_algebra_map_injective NoZeroSMulDivisors.iff_algebraMap_injective\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_nat [Semiring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℕ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℕ R).injective_nat\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_nat NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_nat\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_int [Ring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℤ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℤ R).injective_int\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_int NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_int\n\nsection Field\n\nvariable [Field R] [Semiring A] [Algebra R A]\n\n-- see note [lower instance priority]\ninstance (priority := 100) Algebra.noZeroSMulDivisors [Nontrivial A] [NoZeroDivisors A] :\n NoZeroSMulDivisors R A :=\n NoZeroSMulDivisors.of_algebraMap_injective (algebraMap R A).injective\n#align no_zero_smul_divisors.algebra.no_zero_smul_divisors NoZeroSMulDivisors.Algebra.noZeroSMulDivisors\n\nend Field\n\nend NoZeroSMulDivisors\n\nsection IsScalarTower\n\nvariable {R : Type*} [CommSemiring R]\nvariable (A : Type*) [Semiring A] [Algebra R A]\nvariable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]\nvariable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A N]\n\ntheorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n rw [← smul_assoc]\n rw [Algebra.smul_def]\n rw [mul_one]\n ","nextTactic":"rw [one_smul]","declUpToTactic":"theorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n rw [← smul_assoc]\n rw [Algebra.smul_def]\n rw [mul_one]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.847_0.lJPMR9lAgdsHXom","decl":"theorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m "} +{"state":"R✝ : Type u_1\ninst✝²⁰ : CommSemiring R✝\nA✝ : Type u_2\ninst✝¹⁹ : Semiring A✝\ninst✝¹⁸ : Algebra R✝ A✝\nM✝ : Type u_3\ninst✝¹⁷ : AddCommMonoid M✝\ninst✝¹⁶ : Module A✝ M✝\ninst✝¹⁵ : Module R✝ M✝\ninst✝¹⁴ : IsScalarTower R✝ A✝ M✝\nN : Type u_4\ninst✝¹³ : AddCommMonoid N\ninst✝¹² : Module A✝ N\ninst✝¹¹ : Module R✝ N\ninst✝¹⁰ : IsScalarTower R✝ A✝ N\nR : Type u_5\nA : Type u_6\nM : Type u_7\ninst✝⁹ : CommRing R\ninst✝⁸ : Ring A\ninst✝⁷ : IsDomain A\ninst✝⁶ : Algebra R A\ninst✝⁵ : AddCommGroup M\ninst✝⁴ : Module R M\ninst✝³ : Module A M\ninst✝² : IsScalarTower R A M\ninst✝¹ : NoZeroSMulDivisors R A\ninst✝ : NoZeroSMulDivisors A M\n⊢ NoZeroSMulDivisors R M","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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n simpa only [algebraMap_eq_smul_one'] using this\n#align no_zero_smul_divisors.algebra_map_injective NoZeroSMulDivisors.algebraMap_injective\n\ntheorem _root_.NeZero.of_noZeroSMulDivisors (n : ℕ) [CommRing R] [NeZero (n : R)] [Ring A]\n [Nontrivial A] [Algebra R A] [NoZeroSMulDivisors R A] : NeZero (n : A) :=\n -- porting note: todo: drop implicit args\n @NeZero.nat_of_injective R A (R →+* A) _ _ n ‹_› _ _ <|\n NoZeroSMulDivisors.algebraMap_injective R A\n#align ne_zero.of_no_zero_smul_divisors NeZero.of_noZeroSMulDivisors\n\nvariable {R A}\n\ntheorem iff_algebraMap_injective [CommRing R] [Ring A] [IsDomain A] [Algebra R A] :\n NoZeroSMulDivisors R A ↔ Function.Injective (algebraMap R A) :=\n ⟨@NoZeroSMulDivisors.algebraMap_injective R A _ _ _ _, NoZeroSMulDivisors.of_algebraMap_injective⟩\n#align no_zero_smul_divisors.iff_algebra_map_injective NoZeroSMulDivisors.iff_algebraMap_injective\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_nat [Semiring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℕ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℕ R).injective_nat\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_nat NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_nat\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_int [Ring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℤ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℤ R).injective_int\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_int NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_int\n\nsection Field\n\nvariable [Field R] [Semiring A] [Algebra R A]\n\n-- see note [lower instance priority]\ninstance (priority := 100) Algebra.noZeroSMulDivisors [Nontrivial A] [NoZeroDivisors A] :\n NoZeroSMulDivisors R A :=\n NoZeroSMulDivisors.of_algebraMap_injective (algebraMap R A).injective\n#align no_zero_smul_divisors.algebra.no_zero_smul_divisors NoZeroSMulDivisors.Algebra.noZeroSMulDivisors\n\nend Field\n\nend NoZeroSMulDivisors\n\nsection IsScalarTower\n\nvariable {R : Type*} [CommSemiring R]\nvariable (A : Type*) [Semiring A] [Algebra R A]\nvariable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]\nvariable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A N]\n\ntheorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n rw [← smul_assoc]\n rw [Algebra.smul_def]\n rw [mul_one]\n rw [one_smul]\n#align algebra_compatible_smul algebra_compatible_smul\n\n@[simp]\ntheorem algebraMap_smul (r : R) (m : M) : (algebraMap R A) r • m = r • m :=\n (algebra_compatible_smul A r m).symm\n#align algebra_map_smul algebraMap_smul\n\ntheorem intCast_smul {k V : Type*} [CommRing k] [AddCommGroup V] [Module k V] (r : ℤ) (x : V) :\n (r : k) • x = r • x :=\n algebraMap_smul k r x\n#align int_cast_smul intCast_smul\n\ntheorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n ","nextTactic":"refine' ⟨fun {r m} h => _⟩","declUpToTactic":"theorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.865_0.lJPMR9lAgdsHXom","decl":"theorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M "} +{"state":"R✝ : Type u_1\ninst✝²⁰ : CommSemiring R✝\nA✝ : Type u_2\ninst✝¹⁹ : Semiring A✝\ninst✝¹⁸ : Algebra R✝ A✝\nM✝ : Type u_3\ninst✝¹⁷ : AddCommMonoid M✝\ninst✝¹⁶ : Module A✝ M✝\ninst✝¹⁵ : Module R✝ M✝\ninst✝¹⁴ : IsScalarTower R✝ A✝ M✝\nN : Type u_4\ninst✝¹³ : AddCommMonoid N\ninst✝¹² : Module A✝ N\ninst✝¹¹ : Module R✝ N\ninst✝¹⁰ : IsScalarTower R✝ A✝ N\nR : Type u_5\nA : Type u_6\nM : Type u_7\ninst✝⁹ : CommRing R\ninst✝⁸ : Ring A\ninst✝⁷ : IsDomain A\ninst✝⁶ : Algebra R A\ninst✝⁵ : AddCommGroup M\ninst✝⁴ : Module R M\ninst✝³ : Module A M\ninst✝² : IsScalarTower R A M\ninst✝¹ : NoZeroSMulDivisors R A\ninst✝ : NoZeroSMulDivisors A M\nr : R\nm : M\nh : r • m = 0\n⊢ r = 0 ∨ m = 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n simpa only [algebraMap_eq_smul_one'] using this\n#align no_zero_smul_divisors.algebra_map_injective NoZeroSMulDivisors.algebraMap_injective\n\ntheorem _root_.NeZero.of_noZeroSMulDivisors (n : ℕ) [CommRing R] [NeZero (n : R)] [Ring A]\n [Nontrivial A] [Algebra R A] [NoZeroSMulDivisors R A] : NeZero (n : A) :=\n -- porting note: todo: drop implicit args\n @NeZero.nat_of_injective R A (R →+* A) _ _ n ‹_› _ _ <|\n NoZeroSMulDivisors.algebraMap_injective R A\n#align ne_zero.of_no_zero_smul_divisors NeZero.of_noZeroSMulDivisors\n\nvariable {R A}\n\ntheorem iff_algebraMap_injective [CommRing R] [Ring A] [IsDomain A] [Algebra R A] :\n NoZeroSMulDivisors R A ↔ Function.Injective (algebraMap R A) :=\n ⟨@NoZeroSMulDivisors.algebraMap_injective R A _ _ _ _, NoZeroSMulDivisors.of_algebraMap_injective⟩\n#align no_zero_smul_divisors.iff_algebra_map_injective NoZeroSMulDivisors.iff_algebraMap_injective\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_nat [Semiring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℕ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℕ R).injective_nat\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_nat NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_nat\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_int [Ring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℤ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℤ R).injective_int\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_int NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_int\n\nsection Field\n\nvariable [Field R] [Semiring A] [Algebra R A]\n\n-- see note [lower instance priority]\ninstance (priority := 100) Algebra.noZeroSMulDivisors [Nontrivial A] [NoZeroDivisors A] :\n NoZeroSMulDivisors R A :=\n NoZeroSMulDivisors.of_algebraMap_injective (algebraMap R A).injective\n#align no_zero_smul_divisors.algebra.no_zero_smul_divisors NoZeroSMulDivisors.Algebra.noZeroSMulDivisors\n\nend Field\n\nend NoZeroSMulDivisors\n\nsection IsScalarTower\n\nvariable {R : Type*} [CommSemiring R]\nvariable (A : Type*) [Semiring A] [Algebra R A]\nvariable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]\nvariable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A N]\n\ntheorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n rw [← smul_assoc]\n rw [Algebra.smul_def]\n rw [mul_one]\n rw [one_smul]\n#align algebra_compatible_smul algebra_compatible_smul\n\n@[simp]\ntheorem algebraMap_smul (r : R) (m : M) : (algebraMap R A) r • m = r • m :=\n (algebra_compatible_smul A r m).symm\n#align algebra_map_smul algebraMap_smul\n\ntheorem intCast_smul {k V : Type*} [CommRing k] [AddCommGroup V] [Module k V] (r : ℤ) (x : V) :\n (r : k) • x = r • x :=\n algebraMap_smul k r x\n#align int_cast_smul intCast_smul\n\ntheorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n refine' ⟨fun {r m} h => _⟩\n ","nextTactic":"rw [algebra_compatible_smul A r m] at h","declUpToTactic":"theorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n refine' ⟨fun {r m} h => _⟩\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.865_0.lJPMR9lAgdsHXom","decl":"theorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M "} +{"state":"R✝ : Type u_1\ninst✝²⁰ : CommSemiring R✝\nA✝ : Type u_2\ninst✝¹⁹ : Semiring A✝\ninst✝¹⁸ : Algebra R✝ A✝\nM✝ : Type u_3\ninst✝¹⁷ : AddCommMonoid M✝\ninst✝¹⁶ : Module A✝ M✝\ninst✝¹⁵ : Module R✝ M✝\ninst✝¹⁴ : IsScalarTower R✝ A✝ M✝\nN : Type u_4\ninst✝¹³ : AddCommMonoid N\ninst✝¹² : Module A✝ N\ninst✝¹¹ : Module R✝ N\ninst✝¹⁰ : IsScalarTower R✝ A✝ N\nR : Type u_5\nA : Type u_6\nM : Type u_7\ninst✝⁹ : CommRing R\ninst✝⁸ : Ring A\ninst✝⁷ : IsDomain A\ninst✝⁶ : Algebra R A\ninst✝⁵ : AddCommGroup M\ninst✝⁴ : Module R M\ninst✝³ : Module A M\ninst✝² : IsScalarTower R A M\ninst✝¹ : NoZeroSMulDivisors R A\ninst✝ : NoZeroSMulDivisors A M\nr : R\nm : M\nh : (algebraMap R A) r • m = 0\n⊢ r = 0 ∨ m = 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n simpa only [algebraMap_eq_smul_one'] using this\n#align no_zero_smul_divisors.algebra_map_injective NoZeroSMulDivisors.algebraMap_injective\n\ntheorem _root_.NeZero.of_noZeroSMulDivisors (n : ℕ) [CommRing R] [NeZero (n : R)] [Ring A]\n [Nontrivial A] [Algebra R A] [NoZeroSMulDivisors R A] : NeZero (n : A) :=\n -- porting note: todo: drop implicit args\n @NeZero.nat_of_injective R A (R →+* A) _ _ n ‹_› _ _ <|\n NoZeroSMulDivisors.algebraMap_injective R A\n#align ne_zero.of_no_zero_smul_divisors NeZero.of_noZeroSMulDivisors\n\nvariable {R A}\n\ntheorem iff_algebraMap_injective [CommRing R] [Ring A] [IsDomain A] [Algebra R A] :\n NoZeroSMulDivisors R A ↔ Function.Injective (algebraMap R A) :=\n ⟨@NoZeroSMulDivisors.algebraMap_injective R A _ _ _ _, NoZeroSMulDivisors.of_algebraMap_injective⟩\n#align no_zero_smul_divisors.iff_algebra_map_injective NoZeroSMulDivisors.iff_algebraMap_injective\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_nat [Semiring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℕ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℕ R).injective_nat\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_nat NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_nat\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_int [Ring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℤ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℤ R).injective_int\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_int NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_int\n\nsection Field\n\nvariable [Field R] [Semiring A] [Algebra R A]\n\n-- see note [lower instance priority]\ninstance (priority := 100) Algebra.noZeroSMulDivisors [Nontrivial A] [NoZeroDivisors A] :\n NoZeroSMulDivisors R A :=\n NoZeroSMulDivisors.of_algebraMap_injective (algebraMap R A).injective\n#align no_zero_smul_divisors.algebra.no_zero_smul_divisors NoZeroSMulDivisors.Algebra.noZeroSMulDivisors\n\nend Field\n\nend NoZeroSMulDivisors\n\nsection IsScalarTower\n\nvariable {R : Type*} [CommSemiring R]\nvariable (A : Type*) [Semiring A] [Algebra R A]\nvariable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]\nvariable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A N]\n\ntheorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n rw [← smul_assoc]\n rw [Algebra.smul_def]\n rw [mul_one]\n rw [one_smul]\n#align algebra_compatible_smul algebra_compatible_smul\n\n@[simp]\ntheorem algebraMap_smul (r : R) (m : M) : (algebraMap R A) r • m = r • m :=\n (algebra_compatible_smul A r m).symm\n#align algebra_map_smul algebraMap_smul\n\ntheorem intCast_smul {k V : Type*} [CommRing k] [AddCommGroup V] [Module k V] (r : ℤ) (x : V) :\n (r : k) • x = r • x :=\n algebraMap_smul k r x\n#align int_cast_smul intCast_smul\n\ntheorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n refine' ⟨fun {r m} h => _⟩\n rw [algebra_compatible_smul A r m] at h\n ","nextTactic":"cases' smul_eq_zero.1 h with H H","declUpToTactic":"theorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n refine' ⟨fun {r m} h => _⟩\n rw [algebra_compatible_smul A r m] at h\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.865_0.lJPMR9lAgdsHXom","decl":"theorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M "} +{"state":"case inl\nR✝ : Type u_1\ninst✝²⁰ : CommSemiring R✝\nA✝ : Type u_2\ninst✝¹⁹ : Semiring A✝\ninst✝¹⁸ : Algebra R✝ A✝\nM✝ : Type u_3\ninst✝¹⁷ : AddCommMonoid M✝\ninst✝¹⁶ : Module A✝ M✝\ninst✝¹⁵ : Module R✝ M✝\ninst✝¹⁴ : IsScalarTower R✝ A✝ M✝\nN : Type u_4\ninst✝¹³ : AddCommMonoid N\ninst✝¹² : Module A✝ N\ninst✝¹¹ : Module R✝ N\ninst✝¹⁰ : IsScalarTower R✝ A✝ N\nR : Type u_5\nA : Type u_6\nM : Type u_7\ninst✝⁹ : CommRing R\ninst✝⁸ : Ring A\ninst✝⁷ : IsDomain A\ninst✝⁶ : Algebra R A\ninst✝⁵ : AddCommGroup M\ninst✝⁴ : Module R M\ninst✝³ : Module A M\ninst✝² : IsScalarTower R A M\ninst✝¹ : NoZeroSMulDivisors R A\ninst✝ : NoZeroSMulDivisors A M\nr : R\nm : M\nh : (algebraMap R A) r • m = 0\nH : (algebraMap R A) r = 0\n⊢ r = 0 ∨ m = 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n simpa only [algebraMap_eq_smul_one'] using this\n#align no_zero_smul_divisors.algebra_map_injective NoZeroSMulDivisors.algebraMap_injective\n\ntheorem _root_.NeZero.of_noZeroSMulDivisors (n : ℕ) [CommRing R] [NeZero (n : R)] [Ring A]\n [Nontrivial A] [Algebra R A] [NoZeroSMulDivisors R A] : NeZero (n : A) :=\n -- porting note: todo: drop implicit args\n @NeZero.nat_of_injective R A (R →+* A) _ _ n ‹_› _ _ <|\n NoZeroSMulDivisors.algebraMap_injective R A\n#align ne_zero.of_no_zero_smul_divisors NeZero.of_noZeroSMulDivisors\n\nvariable {R A}\n\ntheorem iff_algebraMap_injective [CommRing R] [Ring A] [IsDomain A] [Algebra R A] :\n NoZeroSMulDivisors R A ↔ Function.Injective (algebraMap R A) :=\n ⟨@NoZeroSMulDivisors.algebraMap_injective R A _ _ _ _, NoZeroSMulDivisors.of_algebraMap_injective⟩\n#align no_zero_smul_divisors.iff_algebra_map_injective NoZeroSMulDivisors.iff_algebraMap_injective\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_nat [Semiring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℕ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℕ R).injective_nat\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_nat NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_nat\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_int [Ring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℤ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℤ R).injective_int\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_int NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_int\n\nsection Field\n\nvariable [Field R] [Semiring A] [Algebra R A]\n\n-- see note [lower instance priority]\ninstance (priority := 100) Algebra.noZeroSMulDivisors [Nontrivial A] [NoZeroDivisors A] :\n NoZeroSMulDivisors R A :=\n NoZeroSMulDivisors.of_algebraMap_injective (algebraMap R A).injective\n#align no_zero_smul_divisors.algebra.no_zero_smul_divisors NoZeroSMulDivisors.Algebra.noZeroSMulDivisors\n\nend Field\n\nend NoZeroSMulDivisors\n\nsection IsScalarTower\n\nvariable {R : Type*} [CommSemiring R]\nvariable (A : Type*) [Semiring A] [Algebra R A]\nvariable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]\nvariable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A N]\n\ntheorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n rw [← smul_assoc]\n rw [Algebra.smul_def]\n rw [mul_one]\n rw [one_smul]\n#align algebra_compatible_smul algebra_compatible_smul\n\n@[simp]\ntheorem algebraMap_smul (r : R) (m : M) : (algebraMap R A) r • m = r • m :=\n (algebra_compatible_smul A r m).symm\n#align algebra_map_smul algebraMap_smul\n\ntheorem intCast_smul {k V : Type*} [CommRing k] [AddCommGroup V] [Module k V] (r : ℤ) (x : V) :\n (r : k) • x = r • x :=\n algebraMap_smul k r x\n#align int_cast_smul intCast_smul\n\ntheorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n refine' ⟨fun {r m} h => _⟩\n rw [algebra_compatible_smul A r m] at h\n cases' smul_eq_zero.1 h with H H\n · ","nextTactic":"have : Function.Injective (algebraMap R A) :=\n NoZeroSMulDivisors.iff_algebraMap_injective.1 inferInstance","declUpToTactic":"theorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n refine' ⟨fun {r m} h => _⟩\n rw [algebra_compatible_smul A r m] at h\n cases' smul_eq_zero.1 h with H H\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.865_0.lJPMR9lAgdsHXom","decl":"theorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M "} +{"state":"case inl\nR✝ : Type u_1\ninst✝²⁰ : CommSemiring R✝\nA✝ : Type u_2\ninst✝¹⁹ : Semiring A✝\ninst✝¹⁸ : Algebra R✝ A✝\nM✝ : Type u_3\ninst✝¹⁷ : AddCommMonoid M✝\ninst✝¹⁶ : Module A✝ M✝\ninst✝¹⁵ : Module R✝ M✝\ninst✝¹⁴ : IsScalarTower R✝ A✝ M✝\nN : Type u_4\ninst✝¹³ : AddCommMonoid N\ninst✝¹² : Module A✝ N\ninst✝¹¹ : Module R✝ N\ninst✝¹⁰ : IsScalarTower R✝ A✝ N\nR : Type u_5\nA : Type u_6\nM : Type u_7\ninst✝⁹ : CommRing R\ninst✝⁸ : Ring A\ninst✝⁷ : IsDomain A\ninst✝⁶ : Algebra R A\ninst✝⁵ : AddCommGroup M\ninst✝⁴ : Module R M\ninst✝³ : Module A M\ninst✝² : IsScalarTower R A M\ninst✝¹ : NoZeroSMulDivisors R A\ninst✝ : NoZeroSMulDivisors A M\nr : R\nm : M\nh : (algebraMap R A) r • m = 0\nH : (algebraMap R A) r = 0\nthis : Function.Injective ⇑(algebraMap R A)\n⊢ r = 0 ∨ m = 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n simpa only [algebraMap_eq_smul_one'] using this\n#align no_zero_smul_divisors.algebra_map_injective NoZeroSMulDivisors.algebraMap_injective\n\ntheorem _root_.NeZero.of_noZeroSMulDivisors (n : ℕ) [CommRing R] [NeZero (n : R)] [Ring A]\n [Nontrivial A] [Algebra R A] [NoZeroSMulDivisors R A] : NeZero (n : A) :=\n -- porting note: todo: drop implicit args\n @NeZero.nat_of_injective R A (R →+* A) _ _ n ‹_› _ _ <|\n NoZeroSMulDivisors.algebraMap_injective R A\n#align ne_zero.of_no_zero_smul_divisors NeZero.of_noZeroSMulDivisors\n\nvariable {R A}\n\ntheorem iff_algebraMap_injective [CommRing R] [Ring A] [IsDomain A] [Algebra R A] :\n NoZeroSMulDivisors R A ↔ Function.Injective (algebraMap R A) :=\n ⟨@NoZeroSMulDivisors.algebraMap_injective R A _ _ _ _, NoZeroSMulDivisors.of_algebraMap_injective⟩\n#align no_zero_smul_divisors.iff_algebra_map_injective NoZeroSMulDivisors.iff_algebraMap_injective\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_nat [Semiring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℕ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℕ R).injective_nat\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_nat NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_nat\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_int [Ring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℤ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℤ R).injective_int\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_int NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_int\n\nsection Field\n\nvariable [Field R] [Semiring A] [Algebra R A]\n\n-- see note [lower instance priority]\ninstance (priority := 100) Algebra.noZeroSMulDivisors [Nontrivial A] [NoZeroDivisors A] :\n NoZeroSMulDivisors R A :=\n NoZeroSMulDivisors.of_algebraMap_injective (algebraMap R A).injective\n#align no_zero_smul_divisors.algebra.no_zero_smul_divisors NoZeroSMulDivisors.Algebra.noZeroSMulDivisors\n\nend Field\n\nend NoZeroSMulDivisors\n\nsection IsScalarTower\n\nvariable {R : Type*} [CommSemiring R]\nvariable (A : Type*) [Semiring A] [Algebra R A]\nvariable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]\nvariable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A N]\n\ntheorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n rw [← smul_assoc]\n rw [Algebra.smul_def]\n rw [mul_one]\n rw [one_smul]\n#align algebra_compatible_smul algebra_compatible_smul\n\n@[simp]\ntheorem algebraMap_smul (r : R) (m : M) : (algebraMap R A) r • m = r • m :=\n (algebra_compatible_smul A r m).symm\n#align algebra_map_smul algebraMap_smul\n\ntheorem intCast_smul {k V : Type*} [CommRing k] [AddCommGroup V] [Module k V] (r : ℤ) (x : V) :\n (r : k) • x = r • x :=\n algebraMap_smul k r x\n#align int_cast_smul intCast_smul\n\ntheorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n refine' ⟨fun {r m} h => _⟩\n rw [algebra_compatible_smul A r m] at h\n cases' smul_eq_zero.1 h with H H\n · have : Function.Injective (algebraMap R A) :=\n NoZeroSMulDivisors.iff_algebraMap_injective.1 inferInstance\n ","nextTactic":"left","declUpToTactic":"theorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n refine' ⟨fun {r m} h => _⟩\n rw [algebra_compatible_smul A r m] at h\n cases' smul_eq_zero.1 h with H H\n · have : Function.Injective (algebraMap R A) :=\n NoZeroSMulDivisors.iff_algebraMap_injective.1 inferInstance\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.865_0.lJPMR9lAgdsHXom","decl":"theorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M "} +{"state":"case inl.h\nR✝ : Type u_1\ninst✝²⁰ : CommSemiring R✝\nA✝ : Type u_2\ninst✝¹⁹ : Semiring A✝\ninst✝¹⁸ : Algebra R✝ A✝\nM✝ : Type u_3\ninst✝¹⁷ : AddCommMonoid M✝\ninst✝¹⁶ : Module A✝ M✝\ninst✝¹⁵ : Module R✝ M✝\ninst✝¹⁴ : IsScalarTower R✝ A✝ M✝\nN : Type u_4\ninst��¹³ : AddCommMonoid N\ninst✝¹² : Module A✝ N\ninst✝¹¹ : Module R✝ N\ninst✝¹⁰ : IsScalarTower R✝ A✝ N\nR : Type u_5\nA : Type u_6\nM : Type u_7\ninst✝⁹ : CommRing R\ninst✝⁸ : Ring A\ninst✝⁷ : IsDomain A\ninst✝⁶ : Algebra R A\ninst✝⁵ : AddCommGroup M\ninst✝⁴ : Module R M\ninst✝³ : Module A M\ninst✝² : IsScalarTower R A M\ninst✝¹ : NoZeroSMulDivisors R A\ninst✝ : NoZeroSMulDivisors A M\nr : R\nm : M\nh : (algebraMap R A) r • m = 0\nH : (algebraMap R A) r = 0\nthis : Function.Injective ⇑(algebraMap R A)\n⊢ r = 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n simpa only [algebraMap_eq_smul_one'] using this\n#align no_zero_smul_divisors.algebra_map_injective NoZeroSMulDivisors.algebraMap_injective\n\ntheorem _root_.NeZero.of_noZeroSMulDivisors (n : ℕ) [CommRing R] [NeZero (n : R)] [Ring A]\n [Nontrivial A] [Algebra R A] [NoZeroSMulDivisors R A] : NeZero (n : A) :=\n -- porting note: todo: drop implicit args\n @NeZero.nat_of_injective R A (R →+* A) _ _ n ‹_› _ _ <|\n NoZeroSMulDivisors.algebraMap_injective R A\n#align ne_zero.of_no_zero_smul_divisors NeZero.of_noZeroSMulDivisors\n\nvariable {R A}\n\ntheorem iff_algebraMap_injective [CommRing R] [Ring A] [IsDomain A] [Algebra R A] :\n NoZeroSMulDivisors R A ↔ Function.Injective (algebraMap R A) :=\n ⟨@NoZeroSMulDivisors.algebraMap_injective R A _ _ _ _, NoZeroSMulDivisors.of_algebraMap_injective⟩\n#align no_zero_smul_divisors.iff_algebra_map_injective NoZeroSMulDivisors.iff_algebraMap_injective\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_nat [Semiring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℕ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℕ R).injective_nat\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_nat NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_nat\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_int [Ring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℤ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℤ R).injective_int\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_int NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_int\n\nsection Field\n\nvariable [Field R] [Semiring A] [Algebra R A]\n\n-- see note [lower instance priority]\ninstance (priority := 100) Algebra.noZeroSMulDivisors [Nontrivial A] [NoZeroDivisors A] :\n NoZeroSMulDivisors R A :=\n NoZeroSMulDivisors.of_algebraMap_injective (algebraMap R A).injective\n#align no_zero_smul_divisors.algebra.no_zero_smul_divisors NoZeroSMulDivisors.Algebra.noZeroSMulDivisors\n\nend Field\n\nend NoZeroSMulDivisors\n\nsection IsScalarTower\n\nvariable {R : Type*} [CommSemiring R]\nvariable (A : Type*) [Semiring A] [Algebra R A]\nvariable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]\nvariable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A N]\n\ntheorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n rw [← smul_assoc]\n rw [Algebra.smul_def]\n rw [mul_one]\n rw [one_smul]\n#align algebra_compatible_smul algebra_compatible_smul\n\n@[simp]\ntheorem algebraMap_smul (r : R) (m : M) : (algebraMap R A) r • m = r • m :=\n (algebra_compatible_smul A r m).symm\n#align algebra_map_smul algebraMap_smul\n\ntheorem intCast_smul {k V : Type*} [CommRing k] [AddCommGroup V] [Module k V] (r : ℤ) (x : V) :\n (r : k) • x = r • x :=\n algebraMap_smul k r x\n#align int_cast_smul intCast_smul\n\ntheorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n refine' ⟨fun {r m} h => _⟩\n rw [algebra_compatible_smul A r m] at h\n cases' smul_eq_zero.1 h with H H\n · have : Function.Injective (algebraMap R A) :=\n NoZeroSMulDivisors.iff_algebraMap_injective.1 inferInstance\n left\n ","nextTactic":"exact (injective_iff_map_eq_zero _).1 this _ H","declUpToTactic":"theorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n refine' ⟨fun {r m} h => _⟩\n rw [algebra_compatible_smul A r m] at h\n cases' smul_eq_zero.1 h with H H\n · have : Function.Injective (algebraMap R A) :=\n NoZeroSMulDivisors.iff_algebraMap_injective.1 inferInstance\n left\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.865_0.lJPMR9lAgdsHXom","decl":"theorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M "} +{"state":"case inr\nR✝ : Type u_1\ninst✝²⁰ : CommSemiring R✝\nA✝ : Type u_2\ninst✝¹⁹ : Semiring A✝\ninst✝¹⁸ : Algebra R✝ A✝\nM✝ : Type u_3\ninst✝¹⁷ : AddCommMonoid M✝\ninst✝¹⁶ : Module A✝ M✝\ninst✝¹⁵ : Module R✝ M✝\ninst✝¹⁴ : IsScalarTower R✝ A✝ M✝\nN : Type u_4\ninst✝¹³ : AddCommMonoid N\ninst✝¹² : Module A✝ N\ninst✝¹¹ : Module R✝ N\ninst✝¹⁰ : IsScalarTower R✝ A✝ N\nR : Type u_5\nA : Type u_6\nM : Type u_7\ninst✝⁹ : CommRing R\ninst✝⁸ : Ring A\ninst✝⁷ : IsDomain A\ninst✝⁶ : Algebra R A\ninst✝⁵ : AddCommGroup M\ninst✝⁴ : Module R M\ninst✝³ : Module A M\ninst✝² : IsScalarTower R A M\ninst✝¹ : NoZeroSMulDivisors R A\ninst✝ : NoZeroSMulDivisors A M\nr : R\nm : M\nh : (algebraMap R A) r • m = 0\nH : m = 0\n⊢ r = 0 ∨ m = 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n simpa only [algebraMap_eq_smul_one'] using this\n#align no_zero_smul_divisors.algebra_map_injective NoZeroSMulDivisors.algebraMap_injective\n\ntheorem _root_.NeZero.of_noZeroSMulDivisors (n : ℕ) [CommRing R] [NeZero (n : R)] [Ring A]\n [Nontrivial A] [Algebra R A] [NoZeroSMulDivisors R A] : NeZero (n : A) :=\n -- porting note: todo: drop implicit args\n @NeZero.nat_of_injective R A (R →+* A) _ _ n ‹_› _ _ <|\n NoZeroSMulDivisors.algebraMap_injective R A\n#align ne_zero.of_no_zero_smul_divisors NeZero.of_noZeroSMulDivisors\n\nvariable {R A}\n\ntheorem iff_algebraMap_injective [CommRing R] [Ring A] [IsDomain A] [Algebra R A] :\n NoZeroSMulDivisors R A ↔ Function.Injective (algebraMap R A) :=\n ⟨@NoZeroSMulDivisors.algebraMap_injective R A _ _ _ _, NoZeroSMulDivisors.of_algebraMap_injective⟩\n#align no_zero_smul_divisors.iff_algebra_map_injective NoZeroSMulDivisors.iff_algebraMap_injective\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_nat [Semiring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℕ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℕ R).injective_nat\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_nat NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_nat\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_int [Ring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℤ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℤ R).injective_int\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_int NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_int\n\nsection Field\n\nvariable [Field R] [Semiring A] [Algebra R A]\n\n-- see note [lower instance priority]\ninstance (priority := 100) Algebra.noZeroSMulDivisors [Nontrivial A] [NoZeroDivisors A] :\n NoZeroSMulDivisors R A :=\n NoZeroSMulDivisors.of_algebraMap_injective (algebraMap R A).injective\n#align no_zero_smul_divisors.algebra.no_zero_smul_divisors NoZeroSMulDivisors.Algebra.noZeroSMulDivisors\n\nend Field\n\nend NoZeroSMulDivisors\n\nsection IsScalarTower\n\nvariable {R : Type*} [CommSemiring R]\nvariable (A : Type*) [Semiring A] [Algebra R A]\nvariable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]\nvariable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A N]\n\ntheorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n rw [← smul_assoc]\n rw [Algebra.smul_def]\n rw [mul_one]\n rw [one_smul]\n#align algebra_compatible_smul algebra_compatible_smul\n\n@[simp]\ntheorem algebraMap_smul (r : R) (m : M) : (algebraMap R A) r • m = r • m :=\n (algebra_compatible_smul A r m).symm\n#align algebra_map_smul algebraMap_smul\n\ntheorem intCast_smul {k V : Type*} [CommRing k] [AddCommGroup V] [Module k V] (r : ℤ) (x : V) :\n (r : k) • x = r • x :=\n algebraMap_smul k r x\n#align int_cast_smul intCast_smul\n\ntheorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n refine' ⟨fun {r m} h => _⟩\n rw [algebra_compatible_smul A r m] at h\n cases' smul_eq_zero.1 h with H H\n · have : Function.Injective (algebraMap R A) :=\n NoZeroSMulDivisors.iff_algebraMap_injective.1 inferInstance\n left\n exact (injective_iff_map_eq_zero _).1 this _ H\n · ","nextTactic":"right","declUpToTactic":"theorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n refine' ⟨fun {r m} h => _⟩\n rw [algebra_compatible_smul A r m] at h\n cases' smul_eq_zero.1 h with H H\n · have : Function.Injective (algebraMap R A) :=\n NoZeroSMulDivisors.iff_algebraMap_injective.1 inferInstance\n left\n exact (injective_iff_map_eq_zero _).1 this _ H\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.865_0.lJPMR9lAgdsHXom","decl":"theorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M "} +{"state":"case inr.h\nR✝ : Type u_1\ninst✝²⁰ : CommSemiring R✝\nA✝ : Type u_2\ninst✝¹⁹ : Semiring A✝\ninst✝¹⁸ : Algebra R✝ A✝\nM✝ : Type u_3\ninst✝¹⁷ : AddCommMonoid M✝\ninst✝¹⁶ : Module A✝ M✝\ninst✝¹⁵ : Module R✝ M✝\ninst✝¹⁴ : IsScalarTower R✝ A✝ M✝\nN : Type u_4\ninst✝¹³ : AddCommMonoid N\ninst✝¹² : Module A✝ N\ninst✝¹¹ : Module R✝ N\ninst✝¹⁰ : IsScalarTower R✝ A✝ N\nR : Type u_5\nA : Type u_6\nM : Type u_7\ninst✝⁹ : CommRing R\ninst✝⁸ : Ring A\ninst✝⁷ : IsDomain A\ninst✝⁶ : Algebra R A\ninst✝⁵ : AddCommGroup M\ninst✝⁴ : Module R M\ninst✝³ : Module A M\ninst✝² : IsScalarTower R A M\ninst✝¹ : NoZeroSMulDivisors R A\ninst✝ : NoZeroSMulDivisors A M\nr : R\nm : M\nh : (algebraMap R A) r • m = 0\nH : m = 0\n⊢ m = 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (��(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n simpa only [algebraMap_eq_smul_one'] using this\n#align no_zero_smul_divisors.algebra_map_injective NoZeroSMulDivisors.algebraMap_injective\n\ntheorem _root_.NeZero.of_noZeroSMulDivisors (n : ℕ) [CommRing R] [NeZero (n : R)] [Ring A]\n [Nontrivial A] [Algebra R A] [NoZeroSMulDivisors R A] : NeZero (n : A) :=\n -- porting note: todo: drop implicit args\n @NeZero.nat_of_injective R A (R →+* A) _ _ n ‹_› _ _ <|\n NoZeroSMulDivisors.algebraMap_injective R A\n#align ne_zero.of_no_zero_smul_divisors NeZero.of_noZeroSMulDivisors\n\nvariable {R A}\n\ntheorem iff_algebraMap_injective [CommRing R] [Ring A] [IsDomain A] [Algebra R A] :\n NoZeroSMulDivisors R A ↔ Function.Injective (algebraMap R A) :=\n ⟨@NoZeroSMulDivisors.algebraMap_injective R A _ _ _ _, NoZeroSMulDivisors.of_algebraMap_injective⟩\n#align no_zero_smul_divisors.iff_algebra_map_injective NoZeroSMulDivisors.iff_algebraMap_injective\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_nat [Semiring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℕ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℕ R).injective_nat\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_nat NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_nat\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_int [Ring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℤ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℤ R).injective_int\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_int NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_int\n\nsection Field\n\nvariable [Field R] [Semiring A] [Algebra R A]\n\n-- see note [lower instance priority]\ninstance (priority := 100) Algebra.noZeroSMulDivisors [Nontrivial A] [NoZeroDivisors A] :\n NoZeroSMulDivisors R A :=\n NoZeroSMulDivisors.of_algebraMap_injective (algebraMap R A).injective\n#align no_zero_smul_divisors.algebra.no_zero_smul_divisors NoZeroSMulDivisors.Algebra.noZeroSMulDivisors\n\nend Field\n\nend NoZeroSMulDivisors\n\nsection IsScalarTower\n\nvariable {R : Type*} [CommSemiring R]\nvariable (A : Type*) [Semiring A] [Algebra R A]\nvariable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]\nvariable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A N]\n\ntheorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n rw [← smul_assoc]\n rw [Algebra.smul_def]\n rw [mul_one]\n rw [one_smul]\n#align algebra_compatible_smul algebra_compatible_smul\n\n@[simp]\ntheorem algebraMap_smul (r : R) (m : M) : (algebraMap R A) r • m = r • m :=\n (algebra_compatible_smul A r m).symm\n#align algebra_map_smul algebraMap_smul\n\ntheorem intCast_smul {k V : Type*} [CommRing k] [AddCommGroup V] [Module k V] (r : ℤ) (x : V) :\n (r : k) • x = r • x :=\n algebraMap_smul k r x\n#align int_cast_smul intCast_smul\n\ntheorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n refine' ⟨fun {r m} h => _⟩\n rw [algebra_compatible_smul A r m] at h\n cases' smul_eq_zero.1 h with H H\n · have : Function.Injective (algebraMap R A) :=\n NoZeroSMulDivisors.iff_algebraMap_injective.1 inferInstance\n left\n exact (injective_iff_map_eq_zero _).1 this _ H\n · right\n ","nextTactic":"exact H","declUpToTactic":"theorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n refine' ⟨fun {r m} h => _⟩\n rw [algebra_compatible_smul A r m] at h\n cases' smul_eq_zero.1 h with H H\n · have : Function.Injective (algebraMap R A) :=\n NoZeroSMulDivisors.iff_algebraMap_injective.1 inferInstance\n left\n exact (injective_iff_map_eq_zero _).1 this _ H\n · right\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.865_0.lJPMR9lAgdsHXom","decl":"theorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M "} +{"state":"R : Type u_1\ninst✝¹⁰ : CommSemiring R\nA : Type u_2\ninst✝⁹ : Semiring A\ninst✝⁸ : Algebra R A\nM : Type u_3\ninst✝⁷ : AddCommMonoid M\ninst✝⁶ : Module A M\ninst✝⁵ : Module R M\ninst✝⁴ : IsScalarTower R A M\nN : Type u_4\ninst✝³ : AddCommMonoid N\ninst✝² : Module A N\ninst✝¹ : Module R N\ninst✝ : IsScalarTower R A N\nr : R\na : A\nm : M\n⊢ r • a • m = a • r • m","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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n simpa only [algebraMap_eq_smul_one'] using this\n#align no_zero_smul_divisors.algebra_map_injective NoZeroSMulDivisors.algebraMap_injective\n\ntheorem _root_.NeZero.of_noZeroSMulDivisors (n : ℕ) [CommRing R] [NeZero (n : R)] [Ring A]\n [Nontrivial A] [Algebra R A] [NoZeroSMulDivisors R A] : NeZero (n : A) :=\n -- porting note: todo: drop implicit args\n @NeZero.nat_of_injective R A (R →+* A) _ _ n ‹_› _ _ <|\n NoZeroSMulDivisors.algebraMap_injective R A\n#align ne_zero.of_no_zero_smul_divisors NeZero.of_noZeroSMulDivisors\n\nvariable {R A}\n\ntheorem iff_algebraMap_injective [CommRing R] [Ring A] [IsDomain A] [Algebra R A] :\n NoZeroSMulDivisors R A ↔ Function.Injective (algebraMap R A) :=\n ⟨@NoZeroSMulDivisors.algebraMap_injective R A _ _ _ _, NoZeroSMulDivisors.of_algebraMap_injective⟩\n#align no_zero_smul_divisors.iff_algebra_map_injective NoZeroSMulDivisors.iff_algebraMap_injective\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_nat [Semiring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℕ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℕ R).injective_nat\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_nat NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_nat\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_int [Ring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℤ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℤ R).injective_int\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_int NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_int\n\nsection Field\n\nvariable [Field R] [Semiring A] [Algebra R A]\n\n-- see note [lower instance priority]\ninstance (priority := 100) Algebra.noZeroSMulDivisors [Nontrivial A] [NoZeroDivisors A] :\n NoZeroSMulDivisors R A :=\n NoZeroSMulDivisors.of_algebraMap_injective (algebraMap R A).injective\n#align no_zero_smul_divisors.algebra.no_zero_smul_divisors NoZeroSMulDivisors.Algebra.noZeroSMulDivisors\n\nend Field\n\nend NoZeroSMulDivisors\n\nsection IsScalarTower\n\nvariable {R : Type*} [CommSemiring R]\nvariable (A : Type*) [Semiring A] [Algebra R A]\nvariable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]\nvariable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A N]\n\ntheorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n rw [← smul_assoc]\n rw [Algebra.smul_def]\n rw [mul_one]\n rw [one_smul]\n#align algebra_compatible_smul algebra_compatible_smul\n\n@[simp]\ntheorem algebraMap_smul (r : R) (m : M) : (algebraMap R A) r • m = r • m :=\n (algebra_compatible_smul A r m).symm\n#align algebra_map_smul algebraMap_smul\n\ntheorem intCast_smul {k V : Type*} [CommRing k] [AddCommGroup V] [Module k V] (r : ℤ) (x : V) :\n (r : k) • x = r • x :=\n algebraMap_smul k r x\n#align int_cast_smul intCast_smul\n\ntheorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n refine' ⟨fun {r m} h => _⟩\n rw [algebra_compatible_smul A r m] at h\n cases' smul_eq_zero.1 h with H H\n · have : Function.Injective (algebraMap R A) :=\n NoZeroSMulDivisors.iff_algebraMap_injective.1 inferInstance\n left\n exact (injective_iff_map_eq_zero _).1 this _ H\n · right\n exact H\n#align no_zero_smul_divisors.trans NoZeroSMulDivisors.trans\n\nvariable {A}\n\n-- see Note [lower instance priority]\ninstance (priority := 100) IsScalarTower.to_smulCommClass : SMulCommClass R A M :=\n ⟨fun r a m => by\n ","nextTactic":"rw [algebra_compatible_smul A r (a • m), smul_smul, Algebra.commutes, mul_smul, ←\n algebra_compatible_smul]","declUpToTactic":"instance (priority := 100) IsScalarTower.to_smulCommClass : SMulCommClass R A M :=\n ⟨fun r a m => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.882_0.lJPMR9lAgdsHXom","decl":"instance (priority "} +{"state":"R : Type u_1\nA : Type u_2\nB : Type u_3\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Semiring B\ninst✝¹ : Algebra R A\ninst✝ : Algebra R B\nf : A →ₗ[R] B\nhf : f 1 = 1\nr : R\nh : Invertible ((algebraMap R A) r)\n⊢ f ⅟((algebraMap R A) r) * (algebraMap R B) r = 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n simpa only [algebraMap_eq_smul_one'] using this\n#align no_zero_smul_divisors.algebra_map_injective NoZeroSMulDivisors.algebraMap_injective\n\ntheorem _root_.NeZero.of_noZeroSMulDivisors (n : ℕ) [CommRing R] [NeZero (n : R)] [Ring A]\n [Nontrivial A] [Algebra R A] [NoZeroSMulDivisors R A] : NeZero (n : A) :=\n -- porting note: todo: drop implicit args\n @NeZero.nat_of_injective R A (R →+* A) _ _ n ‹_› _ _ <|\n NoZeroSMulDivisors.algebraMap_injective R A\n#align ne_zero.of_no_zero_smul_divisors NeZero.of_noZeroSMulDivisors\n\nvariable {R A}\n\ntheorem iff_algebraMap_injective [CommRing R] [Ring A] [IsDomain A] [Algebra R A] :\n NoZeroSMulDivisors R A ↔ Function.Injective (algebraMap R A) :=\n ⟨@NoZeroSMulDivisors.algebraMap_injective R A _ _ _ _, NoZeroSMulDivisors.of_algebraMap_injective⟩\n#align no_zero_smul_divisors.iff_algebra_map_injective NoZeroSMulDivisors.iff_algebraMap_injective\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_nat [Semiring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℕ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℕ R).injective_nat\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_nat NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_nat\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_int [Ring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℤ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℤ R).injective_int\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_int NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_int\n\nsection Field\n\nvariable [Field R] [Semiring A] [Algebra R A]\n\n-- see note [lower instance priority]\ninstance (priority := 100) Algebra.noZeroSMulDivisors [Nontrivial A] [NoZeroDivisors A] :\n NoZeroSMulDivisors R A :=\n NoZeroSMulDivisors.of_algebraMap_injective (algebraMap R A).injective\n#align no_zero_smul_divisors.algebra.no_zero_smul_divisors NoZeroSMulDivisors.Algebra.noZeroSMulDivisors\n\nend Field\n\nend NoZeroSMulDivisors\n\nsection IsScalarTower\n\nvariable {R : Type*} [CommSemiring R]\nvariable (A : Type*) [Semiring A] [Algebra R A]\nvariable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]\nvariable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A N]\n\ntheorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n rw [← smul_assoc]\n rw [Algebra.smul_def]\n rw [mul_one]\n rw [one_smul]\n#align algebra_compatible_smul algebra_compatible_smul\n\n@[simp]\ntheorem algebraMap_smul (r : R) (m : M) : (algebraMap R A) r • m = r • m :=\n (algebra_compatible_smul A r m).symm\n#align algebra_map_smul algebraMap_smul\n\ntheorem intCast_smul {k V : Type*} [CommRing k] [AddCommGroup V] [Module k V] (r : ℤ) (x : V) :\n (r : k) • x = r • x :=\n algebraMap_smul k r x\n#align int_cast_smul intCast_smul\n\ntheorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n refine' ⟨fun {r m} h => _⟩\n rw [algebra_compatible_smul A r m] at h\n cases' smul_eq_zero.1 h with H H\n · have : Function.Injective (algebraMap R A) :=\n NoZeroSMulDivisors.iff_algebraMap_injective.1 inferInstance\n left\n exact (injective_iff_map_eq_zero _).1 this _ H\n · right\n exact H\n#align no_zero_smul_divisors.trans NoZeroSMulDivisors.trans\n\nvariable {A}\n\n-- see Note [lower instance priority]\ninstance (priority := 100) IsScalarTower.to_smulCommClass : SMulCommClass R A M :=\n ⟨fun r a m => by\n rw [algebra_compatible_smul A r (a • m), smul_smul, Algebra.commutes, mul_smul, ←\n algebra_compatible_smul]⟩\n#align is_scalar_tower.to_smul_comm_class IsScalarTower.to_smulCommClass\n\n-- see Note [lower instance priority]\ninstance (priority := 100) IsScalarTower.to_smulCommClass' : SMulCommClass A R M :=\n SMulCommClass.symm _ _ _\n#align is_scalar_tower.to_smul_comm_class' IsScalarTower.to_smulCommClass'\n\n-- see Note [lower instance priority]\ninstance (priority := 200) Algebra.to_smulCommClass {R A} [CommSemiring R] [Semiring A]\n [Algebra R A] : SMulCommClass R A A :=\n IsScalarTower.to_smulCommClass\n#align algebra.to_smul_comm_class Algebra.to_smulCommClass\n\ntheorem smul_algebra_smul_comm (r : R) (a : A) (m : M) : a • r • m = r • a • m :=\n smul_comm _ _ _\n#align smul_algebra_smul_comm smul_algebra_smul_comm\n\nnamespace LinearMap\n\nvariable (R)\n\n#align linear_map.coe_restrict_scalars_eq_coe LinearMap.coe_restrictScalars\n#align linear_map.coe_coe_is_scalar_tower LinearMap.coe_restrictScalars\n\n-- porting note: todo: generalize to `CompatibleSMul`\n/-- `A`-linearly coerce an `R`-linear map from `M` to `A` to a function, given an algebra `A` over\na commutative semiring `R` and `M` a module over `R`. -/\ndef ltoFun (R : Type u) (M : Type v) (A : Type w) [CommSemiring R] [AddCommMonoid M] [Module R M]\n [CommSemiring A] [Algebra R A] : (M →ₗ[R] A) →ₗ[A] M → A where\n toFun f := f.toFun\n map_add' _ _ := rfl\n map_smul' _ _ := rfl\n#align linear_map.lto_fun LinearMap.ltoFun\n\nend LinearMap\n\nend IsScalarTower\n\n/-! TODO: The following lemmas no longer involve `Algebra` at all, and could be moved closer\nto `Algebra/Module/Submodule.lean`. Currently this is tricky because `ker`, `range`, `⊤`, and `⊥`\nare all defined in `LinearAlgebra/Basic.lean`. -/\n\nsection Module\n\nvariable (R : Type*) {S M N : Type*} [Semiring R] [Semiring S] [SMul R S]\nvariable [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M]\nvariable [AddCommMonoid N] [Module R N] [Module S N] [IsScalarTower R S N]\n\n@[simp]\ntheorem LinearMap.ker_restrictScalars (f : M →ₗ[S] N) :\n LinearMap.ker (f.restrictScalars R) = f.ker.restrictScalars R :=\n rfl\n#align linear_map.ker_restrict_scalars LinearMap.ker_restrictScalars\n\nend Module\n\nexample {R A} [CommSemiring R] [Semiring A] [Module R A] [SMulCommClass R A A]\n [IsScalarTower R A A] : Algebra R A :=\n Algebra.ofModule smul_mul_assoc mul_smul_comm\n\nsection invertibility\n\nvariable {R A B : Type*}\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- If there is a linear map `f : A →ₗ[R] B` that preserves `1`, then `algebraMap R B r` is\ninvertible when `algebraMap R A r` is. -/\nabbrev Invertible.algebraMapOfInvertibleAlgebraMap (f : A →ₗ[R] B) (hf : f 1 = 1) {r : R}\n (h : Invertible (algebraMap R A r)) : Invertible (algebraMap R B r) where\n invOf := f ⅟(algebraMap R A r)\n invOf_mul_self := by ","nextTactic":"rw [← Algebra.commutes, ← Algebra.smul_def, ← map_smul, Algebra.smul_def,\n mul_invOf_self, hf]","declUpToTactic":"/-- If there is a linear map `f : A →ₗ[R] B` that preserves `1`, then `algebraMap R B r` is\ninvertible when `algebraMap R A r` is. -/\nabbrev Invertible.algebraMapOfInvertibleAlgebraMap (f : A →ₗ[R] B) (hf : f 1 = 1) {r : R}\n (h : Invertible (algebraMap R A r)) : Invertible (algebraMap R B r) where\n invOf := f ⅟(algebraMap R A r)\n invOf_mul_self := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.951_0.lJPMR9lAgdsHXom","decl":"/-- If there is a linear map `f : A →ₗ[R] B` that preserves `1`, then `algebraMap R B r` is\ninvertible when `algebraMap R A r` is. -/\nabbrev Invertible.algebraMapOfInvertibleAlgebraMap (f : A →ₗ[R] B) (hf : f 1 = 1) {r : R}\n (h : Invertible (algebraMap R A r)) : Invertible (algebraMap R B r) where\n invOf "} +{"state":"R : Type u_1\nA : Type u_2\nB : Type u_3\ninst✝⁴ : CommSemiring R\ninst✝³ : Semiring A\ninst✝² : Semiring B\ninst✝¹ : Algebra R A\ninst✝ : Algebra R B\nf : A →ₗ[R] B\nhf : f 1 = 1\nr : R\nh : Invertible ((algebraMap R A) r)\n⊢ (algebraMap R B) r * f ⅟((algebraMap R A) r) = 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.CharZero.Lemmas\nimport Mathlib.Algebra.Module.ULift\nimport Mathlib.LinearAlgebra.Basic\nimport Mathlib.RingTheory.Subring.Basic\n\n#align_import algebra.algebra.basic from \"leanprover-community/mathlib\"@\"36b8aa61ea7c05727161f96a0532897bd72aedab\"\n\n/-!\n# Algebras over commutative semirings\n\nIn this file we define associative unital `Algebra`s over commutative (semi)rings.\n\n* algebra homomorphisms `AlgHom` are defined in `Mathlib.Algebra.Algebra.Hom`;\n\n* algebra equivalences `AlgEquiv` are defined in `Mathlib.Algebra.Algebra.Equiv`;\n\n* `Subalgebra`s are defined in `Mathlib.Algebra.Algebra.Subalgebra`;\n\n* The category `AlgebraCat R` of `R`-algebras is defined in the file\n `Mathlib.Algebra.Category.Algebra.Basic`.\n\nSee the implementation notes for remarks about non-associative and non-unital algebras.\n\n## Main definitions:\n\n* `Algebra R A`: the algebra typeclass.\n* `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the\n preferred spelling of this map, it is also available as:\n * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`.\n * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file).\n* Instances of `Algebra` in this file:\n * `Algebra.id`\n * `algebraNat`\n * `algebraInt`\n * `algebraRat`\n * `Module.End.instAlgebra`\n\n## Implementation notes\n\nGiven a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a\n(possibly noncommutative) (semi)ring `A`:\n* By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the\n center of `A`.\n* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication\n as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.\n\nWe define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and\nrequiring that this scalar action `r • x` must agree with left multiplication by the image of the\nstructure morphism `algebraMap R A r * x`.\n\nAs a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:\n1. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Algebra R A]\n ```\n2. ```lean\n variables [CommSemiring R] [Semiring A]\n variables [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]\n ```\n\nThe first approach implies the second via typeclass search; so any lemma stated with the second set\nof arguments will automatically apply to the first set. Typeclass search does not know that the\nsecond approach implies the first, but this can be shown with:\n```lean\nexample {R A : Type*} [CommSemiring R] [Semiring A]\n [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A :=\nAlgebra.ofModule smul_mul_assoc mul_smul_comm\n```\n\nThe advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and\n`Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally\nconvenient.\n\nThe advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can\nall be relaxed independently; for instance, this allows us to:\n* Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or\n non-associative algebras.\n* Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`,\n which when `R' = Rˣ` lets us talk about the \"algebra-like\" action of `Rˣ` on an\n `R`-algebra `A`.\n\nWhile `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can.\n\nYou should always use the first approach when working with associative unital algebras, and mimic\nthe second approach only when you need to weaken a condition on either `R` or `A`.\n\n-/\n\nuniverse u v w u₁ v₁\n\nopen BigOperators\n\nsection Prio\n\n-- We set this priority to 0 later in this file\n-- porting note: unsupported set_option extends_priority 200\n\n/- control priority of\n`instance [Algebra R A] : SMul R A` -/\n/-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.\n\nSee the implementation notes in this file for discussion of the details of this definition.\n-/\n-- porting note: unsupported @[nolint has_nonempty_instance]\nclass Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A,\n R →+* A where\n commutes' : ∀ r x, toRingHom r * x = x * toRingHom r\n smul_def' : ∀ r x, r • x = toRingHom r * x\n#align algebra Algebra\n\nend Prio\n\n/-- Embedding `R →+* A` given by `Algebra` structure. -/\ndef algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A :=\n Algebra.toRingHom\n#align algebra_map algebraMap\n\n/-- Coercion from a commutative semiring to an algebra over this semiring. -/\n@[coe] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A :=\n algebraMap R A\n\nnamespace algebraMap\n\nscoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :\n CoeHTCT R A :=\n ⟨Algebra.cast⟩\n#align algebra_map.has_lift_t algebraMap.coeHTCT\n\nsection CommSemiringSemiring\n\nvariable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]\n\n@[simp, norm_cast]\ntheorem coe_zero : (↑(0 : R) : A) = 0 :=\n map_zero (algebraMap R A)\n#align algebra_map.coe_zero algebraMap.coe_zero\n\n@[simp, norm_cast]\ntheorem coe_one : (↑(1 : R) : A) = 1 :=\n map_one (algebraMap R A)\n#align algebra_map.coe_one algebraMap.coe_one\n\n@[norm_cast]\ntheorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=\n map_add (algebraMap R A) a b\n#align algebra_map.coe_add algebraMap.coe_add\n\n@[norm_cast]\ntheorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=\n map_mul (algebraMap R A) a b\n#align algebra_map.coe_mul algebraMap.coe_mul\n\n@[norm_cast]\ntheorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n :=\n map_pow (algebraMap R A) _ _\n#align algebra_map.coe_pow algebraMap.coe_pow\n\nend CommSemiringSemiring\n\nsection CommRingRing\n\nvariable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=\n map_neg (algebraMap R A) x\n#align algebra_map.coe_neg algebraMap.coe_neg\n\nend CommRingRing\n\nsection CommSemiringCommSemiring\n\nvariable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A]\n\nopen BigOperators\n\n-- direct to_additive fails because of some mix-up with polynomials\n@[norm_cast]\ntheorem coe_prod {ι : Type*} {s : Finset ι} (a : ι → R) :\n (↑(∏ i : ι in s, a i : R) : A) = ∏ i : ι in s, (↑(a i) : A) :=\n map_prod (algebraMap R A) a s\n#align algebra_map.coe_prod algebraMap.coe_prod\n\n-- to_additive fails for some reason\n@[norm_cast]\ntheorem coe_sum {ι : Type*} {s : Finset ι} (a : ι → R) :\n ↑(∑ i : ι in s, a i) = ∑ i : ι in s, (↑(a i) : A) :=\n map_sum (algebraMap R A) a s\n#align algebra_map.coe_sum algebraMap.coe_sum\n\n-- porting note: removed attribute [to_additive] coe_prod; why should this be a `to_additive`?\n\nend CommSemiringCommSemiring\n\nsection FieldNontrivial\n\nvariable {R A : Type*} [Field R] [CommSemiring A] [Nontrivial A] [Algebra R A]\n\n@[norm_cast, simp]\ntheorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=\n (algebraMap R A).injective.eq_iff\n#align algebra_map.coe_inj algebraMap.coe_inj\n\n@[norm_cast, simp]\ntheorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=\n map_eq_zero_iff _ (algebraMap R A).injective\n#align algebra_map.lift_map_eq_zero_iff algebraMap.lift_map_eq_zero_iff\n\nend FieldNontrivial\n\nsection SemifieldSemidivisionRing\n\nvariable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) :=\n map_inv₀ (algebraMap R A) r\n#align algebra_map.coe_inv algebraMap.coe_inv\n\n@[norm_cast]\ntheorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) :=\n map_div₀ (algebraMap R A) r s\n#align algebra_map.coe_div algebraMap.coe_div\n\n@[norm_cast]\ntheorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z :=\n map_zpow₀ (algebraMap R A) r z\n#align algebra_map.coe_zpow algebraMap.coe_zpow\n\nend SemifieldSemidivisionRing\n\nsection FieldDivisionRing\n\nvariable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A]\n\n@[norm_cast]\ntheorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q\n#align algebra_map.coe_rat_cast algebraMap.coe_ratCast\n\nend FieldDivisionRing\n\nend algebraMap\n\n/-- Creating an algebra from a morphism to the center of a semiring. -/\ndef RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S)\n (h : ∀ c x, i c * x = x * i c) : Algebra R S where\n smul c x := i c * x\n commutes' := h\n smul_def' _ _ := rfl\n toRingHom := i\n#align ring_hom.to_algebra' RingHom.toAlgebra'\n\n/-- Creating an algebra from a morphism to a commutative semiring. -/\ndef RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S :=\n i.toAlgebra' fun _ => mul_comm _\n#align ring_hom.to_algebra RingHom.toAlgebra\n\ntheorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) :\n @algebraMap R S _ _ i.toAlgebra = i :=\n rfl\n#align ring_hom.algebra_map_to_algebra RingHom.algebraMap_toAlgebra\n\nnamespace Algebra\n\nvariable {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra`\nover `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule' [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x)\n (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where\n toFun r := r • (1 : A)\n map_one' := one_smul _ _\n map_mul' r₁ r₂ := by simp only [h₁, mul_smul]\n map_zero' := zero_smul _ _\n map_add' r₁ r₂ := add_smul r₁ r₂ 1\n commutes' r x := by simp [h₁, h₂]\n smul_def' r x := by simp [h₁]\n#align algebra.of_module' Algebra.ofModule'\n\n/-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure.\nIf `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `Algebra` over `R`.\n\nSee note [reducible non-instances]. -/\n@[reducible]\ndef ofModule [CommSemiring R] [Semiring A] [Module R A]\n (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y))\n (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A :=\n ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one]\n#align algebra.of_module Algebra.ofModule\n\nsection Semiring\n\nvariable [CommSemiring R] [CommSemiring S]\nvariable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]\n\n-- porting note: deleted a private lemma\n\n-- We'll later use this to show `Algebra ℤ M` is a subsingleton.\n/-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree,\nit suffices to check the `algebraMap`s agree.\n-/\n@[ext]\ntheorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A)\n (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) :\n P = Q := by\n replace h : P.toRingHom = Q.toRingHom := FunLike.ext _ _ h\n have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by\n funext r a\n rw [P.smul_def']\n rw [Q.smul_def']\n rw [h]\n rcases P with @⟨⟨P⟩⟩\n rcases Q with @⟨⟨Q⟩⟩\n congr\n#align algebra.algebra_ext Algebra.algebra_ext\n\n-- see Note [lower instance priority]\ninstance (priority := 200) toModule : Module R A where\n one_smul _ := by simp [smul_def']\n mul_smul := by simp [smul_def', mul_assoc]\n smul_add := by simp [smul_def', mul_add]\n smul_zero := by simp [smul_def']\n add_smul := by simp [smul_def', add_mul]\n zero_smul := by simp [smul_def']\n#align algebra.to_module Algebra.toModule\n\n-- porting note: this caused deterministic timeouts later in mathlib3 but not in mathlib 4.\n-- attribute [instance 0] Algebra.toSMul\n\ntheorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x :=\n Algebra.smul_def' r x\n#align algebra.smul_def Algebra.smul_def\n\ntheorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) :=\n calc\n algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm\n _ = r • (1 : A) := (Algebra.smul_def r 1).symm\n#align algebra.algebra_map_eq_smul_one Algebra.algebraMap_eq_smul_one\n\ntheorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) :=\n funext algebraMap_eq_smul_one\n#align algebra.algebra_map_eq_smul_one' Algebra.algebraMap_eq_smul_one'\n\n/-- `mul_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r :=\n Algebra.commutes' r x\n#align algebra.commutes Algebra.commutes\n\nlemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x :=\n Algebra.commutes r x\n\nlemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) :=\n (Algebra.commutes r x).symm\n\n/-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by\n rw [← mul_assoc]\n rw [← commutes]\n rw [mul_assoc]\n#align algebra.left_comm Algebra.left_comm\n\n/-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/\ntheorem right_comm (x : A) (r : R) (y : A) :\n x * algebraMap R A r * y = x * y * algebraMap R A r := by\n rw [mul_assoc]\n rw [commutes]\n rw [← mul_assoc]\n#align algebra.right_comm Algebra.right_comm\n\ninstance _root_.IsScalarTower.right : IsScalarTower R A A :=\n ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩\n#align is_scalar_tower.right IsScalarTower.right\n\n@[simp]\ntheorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A :=\n RingHom.ext fun r => (algebraMap_eq_smul_one r).symm\n\n-- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\n\n/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by\n rw [smul_def]\n rw [smul_def]\n rw [left_comm]\n#align algebra.mul_smul_comm Algebra.mul_smul_comm\n\n/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -/\n@[simp]\nprotected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) :=\n smul_mul_assoc r x y\n#align algebra.smul_mul_assoc Algebra.smul_mul_assoc\n\n@[simp]\ntheorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A]\n [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by\n rw [algebraMap_eq_smul_one]\n rw [smul_comm a r (1 : A)]\n rw [smul_one]\n#align smul_algebra_map smul_algebraMap\n\nsection\n\n#noalign algebra.bit0_smul_one\n#noalign algebra.bit0_smul_one'\n#noalign algebra.bit0_smul_bit0\n#noalign algebra.bit0_smul_bit1\n#noalign algebra.bit1_smul_one\n#noalign algebra.bit1_smul_one'\n#noalign algebra.bit1_smul_bit0\n#noalign algebra.bit1_smul_bit1\n\nend\n\nvariable (R A)\n\n/-- The canonical ring homomorphism `algebraMap R A : R →* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-/\nprotected def linearMap : R →ₗ[R] A :=\n { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] }\n#align algebra.linear_map Algebra.linearMap\n\n@[simp]\ntheorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r :=\n rfl\n#align algebra.linear_map_apply Algebra.linearMap_apply\n\ntheorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A :=\n rfl\n#align algebra.coe_linear_map Algebra.coe_linearMap\n\ninstance id : Algebra R R :=\n (RingHom.id R).toAlgebra\n#align algebra.id Algebra.id\n\nvariable {R A}\n\nnamespace id\n\n@[simp]\ntheorem map_eq_id : algebraMap R R = RingHom.id _ :=\n rfl\n#align algebra.id.map_eq_id Algebra.id.map_eq_id\n\ntheorem map_eq_self (x : R) : algebraMap R R x = x :=\n rfl\n#align algebra.id.map_eq_self Algebra.id.map_eq_self\n\n@[simp]\ntheorem smul_eq_mul (x y : R) : x • y = x * y :=\n rfl\n#align algebra.id.smul_eq_mul Algebra.id.smul_eq_mul\n\nend id\n\nsection PUnit\n\ninstance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where\n toFun _ := PUnit.unit\n map_one' := rfl\n map_mul' _ _ := rfl\n map_zero' := rfl\n map_add' _ _ := rfl\n commutes' _ _ := rfl\n smul_def' _ _ := rfl\n#align punit.algebra PUnit.algebra\n\n@[simp]\ntheorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=\n rfl\n#align algebra.algebra_map_punit Algebra.algebraMap_pUnit\n\nend PUnit\n\nsection ULift\n\ninstance _root_.ULift.algebra : Algebra R (ULift A) :=\n { ULift.module',\n (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with\n toFun := fun r => ULift.up (algebraMap R A r)\n commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down\n smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }\n#align ulift.algebra ULift.algebra\n\ntheorem _root_.ULift.algebraMap_eq (r : R) :\n algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=\n rfl\n#align ulift.algebra_map_eq ULift.algebraMap_eq\n\n@[simp]\ntheorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=\n rfl\n#align ulift.down_algebra_map ULift.down_algebraMap\n\nend ULift\n\n/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/\ninstance ofSubsemiring (S : Subsemiring R) : Algebra S A where\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subsemiring Algebra.ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring (S : Subsemiring R) :\n (algebraMap S R : S →+* R) = Subsemiring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subsemiring Algebra.algebraMap_ofSubsemiring\n\ntheorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subsemiring Algebra.coe_algebraMap_ofSubsemiring\n\ntheorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subsemiring_apply Algebra.algebraMap_ofSubsemiring_apply\n\n/-- Algebra over a subring. This builds upon `Subring.module`. -/\ninstance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :\n Algebra S A where -- porting note: don't use `toSubsemiring` because of a timeout\n toRingHom := (algebraMap R A).comp S.subtype\n smul := (· • ·)\n commutes' r x := Algebra.commutes (r : R) x\n smul_def' r x := Algebra.smul_def (r : R) x\n#align algebra.of_subring Algebra.ofSubring\n\ntheorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S →+* R) = Subring.subtype S :=\n rfl\n#align algebra.algebra_map_of_subring Algebra.algebraMap_ofSubring\n\ntheorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :\n (algebraMap S R : S → R) = Subtype.val :=\n rfl\n#align algebra.coe_algebra_map_of_subring Algebra.coe_algebraMap_ofSubring\n\ntheorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :\n algebraMap S R x = x :=\n rfl\n#align algebra.algebra_map_of_subring_apply Algebra.algebraMap_ofSubring_apply\n\n/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -/\ndef algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=\n M.map (algebraMap R S)\n#align algebra.algebra_map_submonoid Algebra.algebraMapSubmonoid\n\ntheorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}\n (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=\n Set.mem_image_of_mem (algebraMap R S) x.2\n#align algebra.mem_algebra_map_submonoid_of_mem Algebra.mem_algebraMapSubmonoid_of_mem\n\nend Semiring\n\nsection CommSemiring\n\nvariable [CommSemiring R]\n\ntheorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :\n x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]\n#align algebra.mul_sub_algebra_map_commutes Algebra.mul_sub_algebraMap_commutes\n\ntheorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :\n x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by\n induction' n with n ih\n · simp\n · rw [pow_succ, ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]\n#align algebra.mul_sub_algebra_map_pow_commutes Algebra.mul_sub_algebraMap_pow_commutes\n\nend CommSemiring\n\nsection Ring\n\nvariable [CommRing R]\n\nvariable (R)\n\n/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef semiringToRing [Semiring A] [Algebra R A] : Ring A :=\n { Module.addCommMonoidToAddCommGroup R, (inferInstance : Semiring A) with\n intCast := fun z => algebraMap R A z\n intCast_ofNat := fun z => by simp only [Int.cast_ofNat, map_natCast]\n intCast_negSucc := fun z => by simp }\n#align algebra.semiring_to_ring Algebra.semiringToRing\n\nend Ring\n\nend Algebra\n\nopen scoped Algebra\n\nnamespace Module\n\nvariable (R : Type u) (S : Type v) (M : Type w)\nvariable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]\nvariable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]\n\ninstance End.instAlgebra : Algebra R (Module.End S M) :=\n Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm\n\n-- to prove this is a special case of the above\nexample : Algebra R (Module.End R M) := End.instAlgebra _ _ _\n\ntheorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=\n rfl\n\n@[simp]\ntheorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=\n rfl\n#align module.algebra_map_End_apply Module.algebraMap_end_applyₓ\n\n@[simp]\ntheorem ker_algebraMap_end (K : Type u) (V : Type v) [Field K] [AddCommGroup V] [Module K V] (a : K)\n (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=\n LinearMap.ker_smul _ _ ha\n#align module.ker_algebra_map_End Module.ker_algebraMap_end\n\nsection\n\nvariable {R M}\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).symm.trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun ⇑h.unit.val using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff Module.End_algebraMap_isUnit_inv_apply_eq_iff\n\ntheorem End_algebraMap_isUnit_inv_apply_eq_iff' {x : R}\n (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :\n m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' :=\n { mp := fun H => ((congr_arg h.unit H).trans (End_isUnit_apply_inv_apply_of_isUnit h _)).symm\n mpr := fun H =>\n H.symm ▸ by\n apply_fun (↑h.unit : M → M) using ((Module.End_isUnit_iff _).mp h).injective\n erw [End_isUnit_apply_inv_apply_of_isUnit]\n rfl }\n#align module.End_algebra_map_is_unit_inv_apply_eq_iff' Module.End_algebraMap_isUnit_inv_apply_eq_iff'\n\nend\n\nend Module\n\nnamespace LinearMap\n\nvariable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]\n [Algebra R A] [Algebra R B]\n\n/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to\nwork with than `•`. -/\ntheorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :\n f (algebraMap R A r * a) = algebraMap R B r * f a := by\n rw [← Algebra.smul_def]\n rw [← Algebra.smul_def]\n rw [map_smul]\n#align linear_map.map_algebra_map_mul LinearMap.map_algebraMap_mul\n\ntheorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :\n f (a * algebraMap R A r) = f a * algebraMap R B r := by\n rw [← Algebra.commutes]\n rw [← Algebra.commutes]\n rw [map_algebraMap_mul]\n#align linear_map.map_mul_algebra_map LinearMap.map_mul_algebraMap\n\nend LinearMap\n\nsection Nat\n\nvariable {R : Type*} [Semiring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℕ`-algebras. This is only an issue since `Algebra.id` and `algebraNat` are not yet defeq.\n-- TODO: fix this by adding an `ofNat` field to semirings.\n/-- Semiring ⥤ ℕ-Alg -/\ninstance (priority := 99) algebraNat : Algebra ℕ R where\n commutes' := Nat.cast_commute\n smul_def' _ _ := nsmul_eq_mul _ _\n toRingHom := Nat.castRingHom R\n#align algebra_nat algebraNat\n\ninstance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=\n ⟨fun P Q => by ext; simp⟩\n#align nat_algebra_subsingleton nat_algebra_subsingleton\n\nend Nat\n\nnamespace RingHom\n\nvariable {R S : Type*}\n\n-- porting note: changed `[Ring R] [Ring S]` to `[Semiring R] [Semiring S]`\n-- otherwise, Lean failed to find a `Subsingleton (ℚ →+* S)` instance\n@[simp]\ntheorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S)\n (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r :=\n RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r\n#align ring_hom.map_rat_algebra_map RingHom.map_rat_algebraMap\n\nend RingHom\n\nsection Rat\n\ninstance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where\n smul := (· • ·)\n smul_def' := DivisionRing.qsmul_eq_mul'\n toRingHom := Rat.castHom α\n commutes' := Rat.cast_commute\n#align algebra_rat algebraRat\n\n/-- The two `Algebra ℚ ℚ` instances should coincide. -/\nexample : algebraRat = Algebra.id ℚ :=\n rfl\n\n@[simp] theorem algebraMap_rat_rat : algebraMap ℚ ℚ = RingHom.id ℚ := rfl\n#align algebra_map_rat_rat algebraMap_rat_rat\n\ninstance algebra_rat_subsingleton {α} [Semiring α] : Subsingleton (Algebra ℚ α) :=\n ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align algebra_rat_subsingleton algebra_rat_subsingleton\n\nend Rat\n\nsection Int\n\nvariable (R : Type*) [Ring R]\n\n-- Lower the priority so that `Algebra.id` is picked most of the time when working with\n-- `ℤ`-algebras. This is only an issue since `Algebra.id ℤ` and `algebraInt ℤ` are not yet defeq.\n-- TODO: fix this by adding an `ofInt` field to rings.\n/-- Ring ⥤ ℤ-Alg -/\ninstance (priority := 99) algebraInt : Algebra ℤ R where\n commutes' := Int.cast_commute\n smul_def' _ _ := zsmul_eq_mul _ _\n toRingHom := Int.castRingHom R\n#align algebra_int algebraInt\n\n/-- A special case of `eq_intCast'` that happens to be true definitionally -/\n@[simp]\ntheorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=\n rfl\n#align algebra_map_int_eq algebraMap_int_eq\n\nvariable {R}\n\ninstance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=\n ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩\n#align int_algebra_subsingleton int_algebra_subsingleton\n\nend Int\n\nnamespace NoZeroSMulDivisors\n\nvariable {R A : Type*}\n\nopen Algebra\n\n/-- If `algebraMap R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `Injective (algebraMap R A)` typeclass.\n-/\ntheorem of_algebraMap_injective [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A]\n (h : Function.Injective (algebraMap R A)) : NoZeroSMulDivisors R A :=\n ⟨fun hcx => (mul_eq_zero.mp ((smul_def _ _).symm.trans hcx)).imp_left\n (map_eq_zero_iff (algebraMap R A) h).mp⟩\n#align no_zero_smul_divisors.of_algebra_map_injective NoZeroSMulDivisors.of_algebraMap_injective\n\nvariable (R A)\n\ntheorem algebraMap_injective [CommRing R] [Ring A] [Nontrivial A] [Algebra R A]\n [NoZeroSMulDivisors R A] : Function.Injective (algebraMap R A) := by\n -- porting note: todo: drop implicit args\n have := @smul_left_injective R A CommRing.toRing Ring.toAddCommGroup Algebra.toModule\n ‹_› 1 one_ne_zero\n simpa only [algebraMap_eq_smul_one'] using this\n#align no_zero_smul_divisors.algebra_map_injective NoZeroSMulDivisors.algebraMap_injective\n\ntheorem _root_.NeZero.of_noZeroSMulDivisors (n : ℕ) [CommRing R] [NeZero (n : R)] [Ring A]\n [Nontrivial A] [Algebra R A] [NoZeroSMulDivisors R A] : NeZero (n : A) :=\n -- porting note: todo: drop implicit args\n @NeZero.nat_of_injective R A (R →+* A) _ _ n ‹_› _ _ <|\n NoZeroSMulDivisors.algebraMap_injective R A\n#align ne_zero.of_no_zero_smul_divisors NeZero.of_noZeroSMulDivisors\n\nvariable {R A}\n\ntheorem iff_algebraMap_injective [CommRing R] [Ring A] [IsDomain A] [Algebra R A] :\n NoZeroSMulDivisors R A ↔ Function.Injective (algebraMap R A) :=\n ⟨@NoZeroSMulDivisors.algebraMap_injective R A _ _ _ _, NoZeroSMulDivisors.of_algebraMap_injective⟩\n#align no_zero_smul_divisors.iff_algebra_map_injective NoZeroSMulDivisors.iff_algebraMap_injective\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_nat [Semiring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℕ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℕ R).injective_nat\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_nat NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_nat\n\n-- see note [lower instance priority]\ninstance (priority := 100) CharZero.noZeroSMulDivisors_int [Ring R] [NoZeroDivisors R]\n [CharZero R] : NoZeroSMulDivisors ℤ R :=\n NoZeroSMulDivisors.of_algebraMap_injective <| (algebraMap ℤ R).injective_int\n#align no_zero_smul_divisors.char_zero.no_zero_smul_divisors_int NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_int\n\nsection Field\n\nvariable [Field R] [Semiring A] [Algebra R A]\n\n-- see note [lower instance priority]\ninstance (priority := 100) Algebra.noZeroSMulDivisors [Nontrivial A] [NoZeroDivisors A] :\n NoZeroSMulDivisors R A :=\n NoZeroSMulDivisors.of_algebraMap_injective (algebraMap R A).injective\n#align no_zero_smul_divisors.algebra.no_zero_smul_divisors NoZeroSMulDivisors.Algebra.noZeroSMulDivisors\n\nend Field\n\nend NoZeroSMulDivisors\n\nsection IsScalarTower\n\nvariable {R : Type*} [CommSemiring R]\nvariable (A : Type*) [Semiring A] [Algebra R A]\nvariable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]\nvariable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A N]\n\ntheorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by\n rw [← one_smul A m]\n rw [← smul_assoc]\n rw [Algebra.smul_def]\n rw [mul_one]\n rw [one_smul]\n#align algebra_compatible_smul algebra_compatible_smul\n\n@[simp]\ntheorem algebraMap_smul (r : R) (m : M) : (algebraMap R A) r • m = r • m :=\n (algebra_compatible_smul A r m).symm\n#align algebra_map_smul algebraMap_smul\n\ntheorem intCast_smul {k V : Type*} [CommRing k] [AddCommGroup V] [Module k V] (r : ℤ) (x : V) :\n (r : k) • x = r • x :=\n algebraMap_smul k r x\n#align int_cast_smul intCast_smul\n\ntheorem NoZeroSMulDivisors.trans (R A M : Type*) [CommRing R] [Ring A] [IsDomain A] [Algebra R A]\n [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors R A]\n [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M := by\n refine' ⟨fun {r m} h => _⟩\n rw [algebra_compatible_smul A r m] at h\n cases' smul_eq_zero.1 h with H H\n · have : Function.Injective (algebraMap R A) :=\n NoZeroSMulDivisors.iff_algebraMap_injective.1 inferInstance\n left\n exact (injective_iff_map_eq_zero _).1 this _ H\n · right\n exact H\n#align no_zero_smul_divisors.trans NoZeroSMulDivisors.trans\n\nvariable {A}\n\n-- see Note [lower instance priority]\ninstance (priority := 100) IsScalarTower.to_smulCommClass : SMulCommClass R A M :=\n ⟨fun r a m => by\n rw [algebra_compatible_smul A r (a • m), smul_smul, Algebra.commutes, mul_smul, ←\n algebra_compatible_smul]⟩\n#align is_scalar_tower.to_smul_comm_class IsScalarTower.to_smulCommClass\n\n-- see Note [lower instance priority]\ninstance (priority := 100) IsScalarTower.to_smulCommClass' : SMulCommClass A R M :=\n SMulCommClass.symm _ _ _\n#align is_scalar_tower.to_smul_comm_class' IsScalarTower.to_smulCommClass'\n\n-- see Note [lower instance priority]\ninstance (priority := 200) Algebra.to_smulCommClass {R A} [CommSemiring R] [Semiring A]\n [Algebra R A] : SMulCommClass R A A :=\n IsScalarTower.to_smulCommClass\n#align algebra.to_smul_comm_class Algebra.to_smulCommClass\n\ntheorem smul_algebra_smul_comm (r : R) (a : A) (m : M) : a • r • m = r • a • m :=\n smul_comm _ _ _\n#align smul_algebra_smul_comm smul_algebra_smul_comm\n\nnamespace LinearMap\n\nvariable (R)\n\n#align linear_map.coe_restrict_scalars_eq_coe LinearMap.coe_restrictScalars\n#align linear_map.coe_coe_is_scalar_tower LinearMap.coe_restrictScalars\n\n-- porting note: todo: generalize to `CompatibleSMul`\n/-- `A`-linearly coerce an `R`-linear map from `M` to `A` to a function, given an algebra `A` over\na commutative semiring `R` and `M` a module over `R`. -/\ndef ltoFun (R : Type u) (M : Type v) (A : Type w) [CommSemiring R] [AddCommMonoid M] [Module R M]\n [CommSemiring A] [Algebra R A] : (M →ₗ[R] A) →ₗ[A] M → A where\n toFun f := f.toFun\n map_add' _ _ := rfl\n map_smul' _ _ := rfl\n#align linear_map.lto_fun LinearMap.ltoFun\n\nend LinearMap\n\nend IsScalarTower\n\n/-! TODO: The following lemmas no longer involve `Algebra` at all, and could be moved closer\nto `Algebra/Module/Submodule.lean`. Currently this is tricky because `ker`, `range`, `⊤`, and `⊥`\nare all defined in `LinearAlgebra/Basic.lean`. -/\n\nsection Module\n\nvariable (R : Type*) {S M N : Type*} [Semiring R] [Semiring S] [SMul R S]\nvariable [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M]\nvariable [AddCommMonoid N] [Module R N] [Module S N] [IsScalarTower R S N]\n\n@[simp]\ntheorem LinearMap.ker_restrictScalars (f : M →ₗ[S] N) :\n LinearMap.ker (f.restrictScalars R) = f.ker.restrictScalars R :=\n rfl\n#align linear_map.ker_restrict_scalars LinearMap.ker_restrictScalars\n\nend Module\n\nexample {R A} [CommSemiring R] [Semiring A] [Module R A] [SMulCommClass R A A]\n [IsScalarTower R A A] : Algebra R A :=\n Algebra.ofModule smul_mul_assoc mul_smul_comm\n\nsection invertibility\n\nvariable {R A B : Type*}\nvariable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]\n\n/-- If there is a linear map `f : A →ₗ[R] B` that preserves `1`, then `algebraMap R B r` is\ninvertible when `algebraMap R A r` is. -/\nabbrev Invertible.algebraMapOfInvertibleAlgebraMap (f : A →ₗ[R] B) (hf : f 1 = 1) {r : R}\n (h : Invertible (algebraMap R A r)) : Invertible (algebraMap R B r) where\n invOf := f ⅟(algebraMap R A r)\n invOf_mul_self := by rw [← Algebra.commutes, ← Algebra.smul_def, ← map_smul, Algebra.smul_def,\n mul_invOf_self, hf]\n mul_invOf_self := by ","nextTactic":"rw [← Algebra.smul_def, ← map_smul, Algebra.smul_def, mul_invOf_self, hf]","declUpToTactic":"/-- If there is a linear map `f : A →ₗ[R] B` that preserves `1`, then `algebraMap R B r` is\ninvertible when `algebraMap R A r` is. -/\nabbrev Invertible.algebraMapOfInvertibleAlgebraMap (f : A →ₗ[R] B) (hf : f 1 = 1) {r : R}\n (h : Invertible (algebraMap R A r)) : Invertible (algebraMap R B r) where\n invOf := f ⅟(algebraMap R A r)\n invOf_mul_self := by rw [← Algebra.commutes, ← Algebra.smul_def, ← map_smul, Algebra.smul_def,\n mul_invOf_self, hf]\n mul_invOf_self := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Algebra_Basic.951_0.lJPMR9lAgdsHXom","decl":"/-- If there is a linear map `f : A →ₗ[R] B` that preserves `1`, then `algebraMap R B r` is\ninvertible when `algebraMap R A r` is. -/\nabbrev Invertible.algebraMapOfInvertibleAlgebraMap (f : A →ₗ[R] B) (hf : f 1 = 1) {r : R}\n (h : Invertible (algebraMap R A r)) : Invertible (algebraMap R B r) where\n invOf "}