Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit e26b459

Browse files
committed
feat(data/polynomial): some lemmas about eval2 and algebra_map (#3382)
Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
1 parent 792faae commit e26b459

File tree

2 files changed

+87
-2
lines changed

2 files changed

+87
-2
lines changed

src/data/polynomial.lean

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,6 @@ end ring
572572
section comm_semiring
573573
variables [comm_semiring R] {p q r : polynomial R}
574574

575-
local attribute [instance] coeff_coe_to_fun
576-
577575
instance : comm_semiring (polynomial R) := add_monoid_algebra.comm_semiring
578576

579577
section
@@ -586,8 +584,51 @@ lemma algebra_map_apply (r : R) :
586584
algebra_map R (polynomial A) r = C (algebra_map R A r) :=
587585
rfl
588586

587+
/--
588+
When we have `[comm_ring R]`, the function `C` is the same as `algebra_map R (polynomial R)`.
589+
590+
(But note that `C` is defined when `R` is not necessarily commutative, in which case
591+
`algebra_map` is not available.)
592+
-/
593+
lemma C_eq_algebra_map {R : Type*} [comm_ring R] (r : R) :
594+
C r = algebra_map R (polynomial R) r :=
595+
rfl
596+
589597
end
590598

599+
@[simp]
600+
lemma alg_hom_eval₂_algebra_map
601+
{R A B : Type*} [comm_ring R] [ring A] [ring B] [algebra R A] [algebra R B]
602+
(p : polynomial R) (f : A →ₐ[R] B) (a : A) :
603+
f (eval₂ (algebra_map R A) a p) = eval₂ (algebra_map R B) (f a) p :=
604+
begin
605+
dsimp [eval₂, finsupp.sum],
606+
simp only [f.map_sum, f.map_mul, f.map_pow, ring_hom.eq_int_cast, ring_hom.map_int_cast, alg_hom.commutes],
607+
end
608+
609+
@[simp]
610+
lemma eval₂_algebra_map_X {R A : Type*} [comm_ring R] [ring A] [algebra R A]
611+
(p : polynomial R) (f : polynomial R →ₐ[R] A) :
612+
eval₂ (algebra_map R A) (f X) p = f p :=
613+
begin
614+
conv_rhs { rw [←polynomial.sum_C_mul_X_eq p], },
615+
dsimp [eval₂, finsupp.sum],
616+
simp only [f.map_sum, f.map_mul, f.map_pow, ring_hom.eq_int_cast, ring_hom.map_int_cast],
617+
simp [polynomial.C_eq_algebra_map],
618+
end
619+
620+
@[simp]
621+
lemma ring_hom_eval₂_algebra_map_int {R S : Type*} [ring R] [ring S]
622+
(p : polynomial ℤ) (f : R →+* S) (r : R) :
623+
f (eval₂ (algebra_map ℤ R) r p) = eval₂ (algebra_map ℤ S) (f r) p :=
624+
alg_hom_eval₂_algebra_map p f.to_int_alg_hom r
625+
626+
@[simp]
627+
lemma eval₂_algebra_map_int_X {R : Type*} [ring R] (p : polynomial ℤ) (f : polynomial ℤ →+* R) :
628+
eval₂ (algebra_map ℤ R) (f X) p = f p :=
629+
-- Unfortunately `f.to_int_alg_hom` doesn't work here, as typeclasses don't match up correctly.
630+
eval₂_algebra_map_X p { commutes' := λ n, by simp, .. f }
631+
591632
section eval
592633
variable {x : R}
593634

src/ring_theory/algebra.lean

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,28 @@ variables [comm_semiring R] [comm_semiring S] [semiring A] [algebra R A]
9595
lemma smul_def'' (r : R) (x : A) : r • x = algebra_map R A r * x :=
9696
algebra.smul_def' r x
9797

98+
/--
99+
To prove two algebra structures on a fixed `[comm_semiring R] [semiring A]` agree,
100+
it suffices to check the `algebra_map`s agree.
101+
-/
102+
-- We'll later use this to show `algebra ℤ M` is a subsingleton.
103+
@[ext]
104+
lemma algebra_ext {R : Type*} [comm_semiring R] {A : Type*} [semiring A] (P Q : algebra R A)
105+
(w : ∀ (r : R), by { haveI := P, exact algebra_map R A r } = by { haveI := Q, exact algebra_map R A r }) :
106+
P = Q :=
107+
begin
108+
unfreezingI { rcases P with ⟨⟨P⟩⟩, rcases Q with ⟨⟨Q⟩⟩ },
109+
congr,
110+
{ funext r a,
111+
replace w := congr_arg (λ s, s * a) (w r),
112+
simp only [←algebra.smul_def''] at w,
113+
apply w, },
114+
{ ext r,
115+
exact w r, },
116+
{ apply proof_irrel_heq, },
117+
{ apply proof_irrel_heq, },
118+
end
119+
98120
@[priority 200] -- see Note [lower instance priority]
99121
instance to_semimodule : semimodule R A :=
100122
{ one_smul := by simp [smul_def''],
@@ -939,6 +961,13 @@ instance algebra_int : algebra ℤ R :=
939961
smul_def' := λ _ _, gsmul_eq_mul _ _,
940962
.. int.cast_ring_hom R }
941963

964+
/--
965+
Promote a ring homomorphisms to a `ℤ`-algebra homomorphism.
966+
-/
967+
def ring_hom.to_int_alg_hom {R S : Type*} [ring R] [ring S] (f : R →+* S) : R →ₐ[ℤ] S :=
968+
{ commutes' := λ n, by simp,
969+
.. f }
970+
942971
variables {R}
943972
/-- A subring is a `ℤ`-subalgebra. -/
944973
def subalgebra_of_subring (S : set R) [is_subring S] : subalgebra ℤ R :=
@@ -953,6 +982,21 @@ def subalgebra_of_subring (S : set R) [is_subring S] : subalgebra ℤ R :=
953982
(λ i ih, show ((-i - 1 : ℤ) : R) ∈ S, by { rw [int.cast_sub, int.cast_one],
954983
exact is_add_subgroup.sub_mem S _ _ ih is_submonoid.one_mem }) }
955984

985+
986+
section
987+
variables {S : Type*} [ring S]
988+
989+
instance int_algebra_subsingleton : subsingleton (algebra ℤ S) :=
990+
⟨λ P Q, by { ext, simp, }⟩
991+
end
992+
993+
section
994+
variables {S : Type*} [semiring S]
995+
996+
instance nat_algebra_subsingleton : subsingleton (algebra ℕ S) :=
997+
⟨λ P Q, by { ext, simp, }⟩
998+
end
999+
9561000
@[simp] lemma mem_subalgebra_of_subring {x : R} {S : set R} [is_subring S] :
9571001
x ∈ subalgebra_of_subring S ↔ x ∈ S :=
9581002
iff.rfl

0 commit comments

Comments
 (0)