Skip to content

Commit

Permalink
feat(data/nat/cast): generalize to fun_like (#11128)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericrbg committed Jan 10, 2022
1 parent 1533f15 commit 168ad7f
Show file tree
Hide file tree
Showing 34 changed files with 118 additions and 103 deletions.
2 changes: 1 addition & 1 deletion archive/100-theorems-list/16_abel_ruffini.lean
Expand Up @@ -41,7 +41,7 @@ by simp [Φ]
by simp [Φ, coeff_X_pow]

@[simp] lemma coeff_five_Phi : (Φ R a b).coeff 5 = 1 :=
by simp [Φ, coeff_X, coeff_C, -C_eq_nat_cast, -ring_hom.map_nat_cast]
by simp [Φ, coeff_X, coeff_C, -C_eq_nat_cast, -map_nat_cast]

variables [nontrivial R]

Expand Down
3 changes: 0 additions & 3 deletions src/algebra/algebra/basic.lean
Expand Up @@ -582,9 +582,6 @@ lemma map_finsupp_sum {α : Type*} [has_zero α] {ι : Type*} (f : ι →₀ α)
φ (f.sum g) = f.sum (λ i a, φ (g i a)) :=
φ.map_sum _ _

@[simp] lemma map_nat_cast (n : ℕ) : φ n = n :=
φ.to_ring_hom.map_nat_cast n

lemma map_bit0 (x) : φ (bit0 x) = bit0 (φ x) := map_bit0 _ _
lemma map_bit1 (x) : φ (bit1 x) = bit1 (φ x) := map_bit1 _ _

Expand Down
4 changes: 2 additions & 2 deletions src/algebra/char_p/basic.lean
Expand Up @@ -216,7 +216,7 @@ lemma ring_hom.char_p_iff_char_p {K L : Type*} [division_ring K] [semiring L] [n
begin
split;
{ introI _c, constructor, intro n,
rw [← @char_p.cast_eq_zero_iff _ _ _ p _c n, ← f.injective.eq_iff, f.map_nat_cast, f.map_zero] }
rw [← @char_p.cast_eq_zero_iff _ _ _ p _c n, ← f.injective.eq_iff, map_nat_cast f, f.map_zero] }
end

section frobenius
Expand Down Expand Up @@ -278,7 +278,7 @@ theorem frobenius_zero : frobenius R p 0 = 0 := (frobenius R p).map_zero
theorem frobenius_add : frobenius R p (x + y) = frobenius R p x + frobenius R p y :=
(frobenius R p).map_add x y

theorem frobenius_nat_cast (n : ℕ) : frobenius R p n = n := (frobenius R p).map_nat_cast n
theorem frobenius_nat_cast (n : ℕ) : frobenius R p n = n := map_nat_cast (frobenius R p) n

open_locale big_operators
variables {R}
Expand Down
4 changes: 2 additions & 2 deletions src/algebra/char_p/pi.lean
Expand Up @@ -19,8 +19,8 @@ instance pi (ι : Type u) [hi : nonempty ι] (R : Type v) [semiring R] (p : ℕ)
char_p (ι → R) p :=
⟨λ x, let ⟨i⟩ := hi in iff.symm $ (char_p.cast_eq_zero_iff R p x).symm.trans
⟨λ h, funext $ λ j, show pi.eval_ring_hom (λ _, R) j (↑x : ι → R) = 0,
by rw [ring_hom.map_nat_cast, h],
λ h, (pi.eval_ring_hom (λ _: ι, R) i).map_nat_cast x ▸ by rw [h, ring_hom.map_zero]⟩⟩
by rw [map_nat_cast, h],
λ h, map_nat_cast (pi.eval_ring_hom (λ _: ι, R) i) x ▸ by rw [h, ring_hom.map_zero]⟩⟩

-- diamonds
instance pi' (ι : Type u) [hi : nonempty ι] (R : Type v) [comm_ring R] (p : ℕ) [char_p R p] :
Expand Down
4 changes: 2 additions & 2 deletions src/algebra/char_p/quotient.lean
Expand Up @@ -18,7 +18,7 @@ namespace char_p
theorem quotient (R : Type u) [comm_ring R] (p : ℕ) [hp1 : fact p.prime] (hp2 : ↑p ∈ nonunits R) :
char_p (R ⧸ (ideal.span {p} : ideal R)) p :=
have hp0 : (p : R ⧸ (ideal.span {p} : ideal R)) = 0,
from (ideal.quotient.mk (ideal.span {p} : ideal R)).map_nat_cast p ▸
from map_nat_cast (ideal.quotient.mk (ideal.span {p} : ideal R)) p ▸
ideal.quotient.eq_zero_iff_mem.2 (ideal.subset_span $ set.mem_singleton _),
ring_char.of_eq $ or.resolve_left ((nat.dvd_prime hp1.1).1 $ ring_char.dvd hp0) $ λ h1,
hp2 $ is_unit_iff_dvd_one.2 $ ideal.mem_span_singleton.1 $ ideal.quotient.eq_zero_iff_mem.1 $
Expand All @@ -30,7 +30,7 @@ lemma quotient' {R : Type*} [comm_ring R] (p : ℕ) [char_p R p] (I : ideal R)
(h : ∀ x : ℕ, (x : R) ∈ I → (x : R) = 0) :
char_p (R ⧸ I) p :=
⟨λ x, begin
rw [←cast_eq_zero_iff R p x, ←(ideal.quotient.mk I).map_nat_cast],
rw [←cast_eq_zero_iff R p x, ←map_nat_cast (ideal.quotient.mk I)],
refine quotient.eq'.trans (_ : ↑x - 0 ∈ I ↔ _),
rw sub_zero,
exact ⟨h x, λ h', h'.symm ▸ I.zero_mem⟩,
Expand Down
8 changes: 4 additions & 4 deletions src/algebra/char_p/subring.lean
Expand Up @@ -18,14 +18,14 @@ namespace char_p
instance subsemiring (R : Type u) [semiring R] (p : ℕ) [char_p R p] (S : subsemiring R) :
char_p S p :=
⟨λ x, iff.symm $ (char_p.cast_eq_zero_iff R p x).symm.trans
⟨λ h, subtype.eq $ show S.subtype x = 0, by rw [ring_hom.map_nat_cast, h],
λ h, S.subtype.map_nat_cast x ▸ by rw [h, ring_hom.map_zero]⟩⟩
⟨λ h, subtype.eq $ show S.subtype x = 0, by rw [map_nat_cast, h],
λ h, map_nat_cast S.subtype x ▸ by rw [h, ring_hom.map_zero]⟩⟩

instance subring (R : Type u) [ring R] (p : ℕ) [char_p R p] (S : subring R) :
char_p S p :=
⟨λ x, iff.symm $ (char_p.cast_eq_zero_iff R p x).symm.trans
⟨λ h, subtype.eq $ show S.subtype x = 0, by rw [ring_hom.map_nat_cast, h],
λ h, S.subtype.map_nat_cast x ▸ by rw [h, ring_hom.map_zero]⟩⟩
⟨λ h, subtype.eq $ show S.subtype x = 0, by rw [map_nat_cast, h],
λ h, map_nat_cast S.subtype x ▸ by rw [h, ring_hom.map_zero]⟩⟩

instance subring' (R : Type u) [comm_ring R] (p : ℕ) [char_p R p] (S : subring R) :
char_p S p :=
Expand Down
4 changes: 2 additions & 2 deletions src/algebra/char_zero.lean
Expand Up @@ -200,11 +200,11 @@ section ring_hom
variables {R S : Type*} [semiring R] [semiring S]

lemma ring_hom.char_zero (ϕ : R →+* S) [hS : char_zero S] : char_zero R :=
⟨λ a b h, char_zero.cast_injective (by rw [←ϕ.map_nat_cast, ←ϕ.map_nat_cast, h])⟩
⟨λ a b h, char_zero.cast_injective (by rw [←map_nat_cast ϕ, ←map_nat_cast ϕ, h])⟩

lemma ring_hom.char_zero_iff {ϕ : R →+* S} (hϕ : function.injective ϕ) :
char_zero R ↔ char_zero S :=
⟨λ hR, ⟨λ a b h, by rwa [←@nat.cast_inj R _ _ hR, ←hϕ.eq_iff, ϕ.map_nat_cast, ϕ.map_nat_cast]⟩,
⟨λ hR, ⟨λ a b h, by rwa [←@nat.cast_inj R _ _ hR, ←hϕ.eq_iff, map_nat_cast ϕ, map_nat_cast ϕ]⟩,
λ hS, by exactI ϕ.char_zero⟩

end ring_hom
9 changes: 6 additions & 3 deletions src/algebra/group_power/lemmas.lean
Expand Up @@ -24,9 +24,12 @@ section monoid
variables [monoid M] [monoid N] [add_monoid A] [add_monoid B]

@[simp] theorem nsmul_one [has_one A] : ∀ n : ℕ, n • (1 : A) = n :=
add_monoid_hom.eq_nat_cast
⟨λ n, n • (1 : A), zero_nsmul _, λ _ _, add_nsmul _ _ _⟩
(one_nsmul _)
begin
refine eq_nat_cast' (⟨_, _, _⟩ : ℕ →+ A) _,
{ simp [zero_nsmul] },
{ simp [add_nsmul] },
{ simp }
end

@[simp, norm_cast, to_additive]
lemma units.coe_pow (u : Mˣ) (n : ℕ) : ((u ^ n : Mˣ) : M) = u ^ n :=
Expand Down
8 changes: 4 additions & 4 deletions src/algebra/ne_zero.lean
Expand Up @@ -50,12 +50,12 @@ instance char_zero [ne_zero n] [add_monoid M] [has_one M] [char_zero M] : ne_zer
lemma of_map [has_zero R] [has_zero M] [zero_hom_class F R M] (f : F) [ne_zero (f r)] :
ne_zero r := ⟨λ h, ne (f r) $ by convert map_zero f⟩

lemma of_injective' {r : R} [has_zero R] [h : ne_zero r] [has_zero M] [zero_hom_class F R M]
lemma of_injective {r : R} [has_zero R] [h : ne_zero r] [has_zero M] [zero_hom_class F R M]
{f : F} (hf : function.injective f) : ne_zero (f r) :=
by { rw ←map_zero f, exact hf.ne (ne r) }⟩

lemma of_injective [non_assoc_semiring M] [non_assoc_semiring R] [h : ne_zero (n : R)]
{f : R →+* M} (hf : function.injective f) : ne_zero (n : M) :=
lemma nat_of_injective [non_assoc_semiring M] [non_assoc_semiring R] [h : ne_zero (n : R)]
[ring_hom_class F R M] {f : F} (hf : function.injective f) : ne_zero (n : M) :=
⟨λ h, (ne_zero.ne' n R) $ hf $ by simpa⟩

variables (R M)
Expand All @@ -65,7 +65,7 @@ lemma of_not_dvd [add_monoid M] [has_one M] [char_p M p] (h : ¬ p ∣ n) : ne_z

lemma of_no_zero_smul_divisors [comm_ring R] [ne_zero (n : R)] [ring M] [nontrivial M]
[algebra R M] [no_zero_smul_divisors R M] : ne_zero (n : M) :=
of_injective $ no_zero_smul_divisors.algebra_map_injective R M
nat_of_injective $ no_zero_smul_divisors.algebra_map_injective R M

lemma of_ne_zero_coe [has_zero R] [has_one R] [has_add R] [h : ne_zero (n : R)] : ne_zero n :=
by {casesI h, rintro rfl, contradiction}⟩
Expand Down
2 changes: 1 addition & 1 deletion src/data/complex/basic.lean
Expand Up @@ -363,7 +363,7 @@ norm_sq.map_div z w
/-! ### Cast lemmas -/

@[simp, norm_cast] theorem of_real_nat_cast (n : ℕ) : ((n : ℝ) : ℂ) = n :=
of_real.map_nat_cast n
map_nat_cast of_real n

@[simp, norm_cast] lemma nat_cast_re (n : ℕ) : (n : ℂ).re = n :=
by rw [← of_real_nat_cast, of_real_re]
Expand Down
2 changes: 1 addition & 1 deletion src/data/complex/is_R_or_C.lean
Expand Up @@ -362,7 +362,7 @@ by simp only [←sqrt_norm_sq_eq_norm, norm_sq_conj]
/-! ### Cast lemmas -/

@[simp, norm_cast, priority 900] theorem of_real_nat_cast (n : ℕ) : ((n : ℝ) : K) = n :=
of_real_hom.map_nat_cast n
show (algebra_map ℝ K) n = n, from map_nat_cast of_real_hom n

@[simp, norm_cast] lemma nat_cast_re (n : ℕ) : re (n : K) = n :=
by rw [← of_real_nat_cast, of_real_re]
Expand Down
2 changes: 1 addition & 1 deletion src/data/int/cast.lean
Expand Up @@ -224,7 +224,7 @@ variables {A : Type*}
/-- Two additive monoid homomorphisms `f`, `g` from `ℤ` to an additive monoid are equal
if `f 1 = g 1`. -/
@[ext] theorem ext_int [add_monoid A] {f g : ℤ →+ A} (h1 : f 1 = g 1) : f = g :=
have f.comp (int.of_nat_hom : ℕ →+ ℤ) = g.comp (int.of_nat_hom : ℕ →+ ℤ) := ext_nat h1,
have f.comp (int.of_nat_hom : ℕ →+ ℤ) = g.comp (int.of_nat_hom : ℕ →+ ℤ) := ext_nat' _ _ h1,
have ∀ n : ℕ, f n = g n := ext_iff.1 this,
ext $ λ n, int.cases_on n this $ λ n, eq_on_neg (this $ n + 1)

Expand Down
2 changes: 1 addition & 1 deletion src/data/matrix/char_p.lean
Expand Up @@ -16,6 +16,6 @@ instance matrix.char_p [decidable_eq n] [nonempty n] (p : ℕ) [char_p R p] :
char_p (matrix n n R) p :=
begin
intro k,
rw [← char_p.cast_eq_zero_iff R p k, ← nat.cast_zero, ← (scalar n).map_nat_cast],
rw [← char_p.cast_eq_zero_iff R p k, ← nat.cast_zero, ← map_nat_cast $ scalar n],
convert scalar_inj, {simp}, {assumption}
end
88 changes: 50 additions & 38 deletions src/data/nat/cast.lean
Expand Up @@ -82,7 +82,7 @@ by { split_ifs; refl, }

end

@[simp, norm_cast] theorem cast_one [add_monoid α] [has_one α] : ((1 : ℕ) : α) = 1 := zero_add _
@[simp, norm_cast] theorem cast_one [add_zero_class α] [has_one α] : ((1 : ℕ) : α) = 1 := zero_add _

@[simp, norm_cast] theorem cast_add [add_monoid α] [has_one α] (m) : ∀ n, ((m + n : ℕ) : α) = m + n
| 0 := (add_zero _).symm
Expand Down Expand Up @@ -116,7 +116,8 @@ def cast_add_monoid_hom (α : Type*) [add_monoid α] [has_one α] : ℕ →+ α
((bit1 n : ℕ) : α) = bit1 n :=
by rw [bit1, cast_add_one, cast_bit0]; refl

lemma cast_two {α : Type*} [add_monoid α] [has_one α] : ((2 : ℕ) : α) = 2 := by simp
lemma cast_two {α : Type*} [add_zero_class α] [has_one α] : ((2 : ℕ) : α) = 2 :=
by rw [cast_add_one, cast_one, bit0]

@[simp, norm_cast] theorem cast_pred [add_group α] [has_one α] :
∀ {n}, 0 < n → ((n - 1 : ℕ) : α) = n - 1
Expand Down Expand Up @@ -155,7 +156,7 @@ nat.rec_on n (commute.zero_left x) $ λ n ihn, ihn.add_left $ commute.one_left x
lemma cast_comm [non_assoc_semiring α] (n : ℕ) (x : α) : (n : α) * x = x * n :=
(cast_commute n x).eq

lemma commute_cast [semiring α] (x : α) (n : ℕ) : commute x n :=
lemma commute_cast [non_assoc_semiring α] (x : α) (n : ℕ) : commute x n :=
(n.cast_commute x).symm

section
Expand Down Expand Up @@ -214,9 +215,8 @@ end
|(a : α)| = a :=
abs_of_nonneg (cast_nonneg a)

lemma coe_nat_dvd [comm_semiring α] {m n : ℕ} (h : m ∣ n) :
(m : α) ∣ (n : α) :=
ring_hom.map_dvd (nat.cast_ring_hom α) h
lemma coe_nat_dvd [semiring α] {m n : ℕ} (h : m ∣ n) : (m : α) ∣ (n : α) :=
(nat.cast_ring_hom α).map_dvd h

alias coe_nat_dvd ← has_dvd.dvd.nat_cast

Expand Down Expand Up @@ -262,73 +262,85 @@ by induction n; simp *

end prod

namespace add_monoid_hom
section add_monoid_hom_class

variables {A B : Type*} [add_monoid A]
variables {A B F : Type*} [add_monoid A] [add_monoid B] [has_one B]

@[ext] lemma ext_nat {f g : ℕ →+ A} (h : f 1 = g 1) : f = g :=
ext $ λ n, nat.rec_on n (f.map_zero.trans g.map_zero.symm) $ λ n ihn,
by simp only [nat.succ_eq_add_one, *, map_add]
lemma ext_nat' [add_monoid_hom_class F ℕ A] (f g : F) (h : f 1 = g 1) : f = g :=
fun_like.ext f g $ begin
apply nat.rec,
{ simp only [nat.nat_zero_eq_zero, map_zero] },
simp [nat.succ_eq_add_one, h] {contextual := tt}
end

@[ext] lemma add_monoid_hom.ext_nat : ∀ {f g : ℕ →+ A}, ∀ h : f 1 = g 1, f = g := ext_nat'

variables [has_one A] [add_monoid B] [has_one B]
variable [has_one A]

lemma eq_nat_cast (f : ℕ →+ A) (h1 : f 1 = 1) :
∀ n : ℕ, f n = n :=
congr_fun $ show f = nat.cast_add_monoid_hom A, from ext_nat (h1.trans nat.cast_one.symm)
-- these versions are primed so that the `ring_hom_class` versions aren't
lemma eq_nat_cast' [add_monoid_hom_class F ℕ A] (f : F) (h1 : f 1 = 1) :
∀ n : ℕ, f n = n
| 0 := by simp
| (n+1) := by rw [map_add, h1, eq_nat_cast' n, nat.cast_add_one]

lemma map_nat_cast (f : A →+ B) (h1 : f 1 = 1) (n : ℕ) : f n = n :=
(f.comp (nat.cast_add_monoid_hom A)).eq_nat_cast (by simp [h1]) _
lemma map_nat_cast' [add_monoid_hom_class F A B] (f : F) (h : f 1 = 1) : ∀ (n : ℕ), f n = n
| 0 := by simp
| (n+1) := by rw [nat.cast_add, map_add, nat.cast_add, map_nat_cast', nat.cast_one, h, nat.cast_one]

end add_monoid_hom
end add_monoid_hom_class

namespace monoid_with_zero_hom
section monoid_with_zero_hom_class

variables {A : Type*} [monoid_with_zero A]
variables {A F : Type*} [monoid_with_zero A]

/-- If two `monoid_with_zero_hom`s agree on the positive naturals they are equal. -/
@[ext] theorem ext_nat {f g : monoid_with_zero_hom ℕ A}
theorem ext_nat'' [monoid_with_zero_hom_class F ℕ A] (f g : F)
(h_pos : ∀ {n : ℕ}, 0 < n → f n = g n) : f = g :=
begin
ext (_ | n),
{ rw [f.map_zero, g.map_zero] },
{ exact h_pos n.zero_lt_succ, },
apply fun_like.ext,
rintro (_|n),
{ simp },
exact h_pos n.succ_pos
end

end monoid_with_zero_hom
@[ext] theorem monoid_with_zero_hom.ext_nat :
∀ {f g : monoid_with_zero_hom ℕ A}, (∀ {n : ℕ}, 0 < n → f n = g n) → f = g := ext_nat''

end monoid_with_zero_hom_class

namespace ring_hom
section ring_hom_class

variables {R : Type*} {S : Type*} [non_assoc_semiring R] [non_assoc_semiring S]
variables {R S F : Type*} [non_assoc_semiring R] [non_assoc_semiring S]

@[simp] lemma eq_nat_cast (f :→+* R) (n : ) : f n = n :=
f.to_add_monoid_hom.eq_nat_cast f.map_one n
@[simp] lemma eq_nat_cast [ring_hom_class FR] (f : F) : ∀ n, f n = n :=
eq_nat_cast' f $ map_one f

@[simp] lemma map_nat_cast (f : R →+* S) (n : ℕ) :
f n = n :=
(f.comp (nat.cast_ring_hom R)).eq_nat_cast n
@[simp] lemma map_nat_cast [ring_hom_class F R S] (f : F) : ∀ n : ℕ, f (n : R) = n :=
map_nat_cast' f $ map_one f

lemma ext_nat (f g : ℕ →+* R) : f = g :=
coe_add_monoid_hom_injective $ add_monoid_hom.ext_nat $ f.map_one.trans g.map_one.symm
lemma ext_nat [ring_hom_class F ℕ R] (f g : F) : f = g :=
ext_nat' f g $ by simp only [map_one]

end ring_hom
end ring_hom_class

@[simp, norm_cast] theorem nat.cast_id (n : ℕ) : ↑n = n :=
((ring_hom.id ℕ).eq_nat_cast n).symm
(eq_nat_cast (ring_hom.id ℕ) n).symm

@[simp] theorem nat.cast_with_bot : ∀ (n : ℕ),
@coe ℕ (with_bot ℕ) (@coe_to_lift _ _ nat.cast_coe) n = n
| 0 := rfl
| (n+1) := by rw [with_bot.coe_add, nat.cast_add, nat.cast_with_bot n]; refl

-- I don't think `ring_hom_class` is good here, because of the `subsingleton` TC slowness
instance nat.subsingleton_ring_hom {R : Type*} [non_assoc_semiring R] : subsingleton (ℕ →+* R) :=
ring_hom.ext_nat⟩
⟨ext_nat⟩

namespace with_top
variables {α : Type*}

variables [has_zero α] [has_one α] [has_add α]

@[simp, norm_cast] lemma coe_nat : ∀(n : nat), ((n : α) : with_top α) = n
@[simp, norm_cast] lemma coe_nat : ∀ (n : ), ((n : α) : with_top α) = n
| 0 := rfl
| (n+1) := by { push_cast, rw [coe_nat n] }

Expand Down
2 changes: 1 addition & 1 deletion src/data/polynomial/algebra_map.lean
Expand Up @@ -189,7 +189,7 @@ alg_hom.map_bit0 _ _
alg_hom.map_bit1 _ _

@[simp] lemma aeval_nat_cast (n : ℕ) : aeval x (n : polynomial R) = n :=
alg_hom.map_nat_cast _ _
map_nat_cast _ _

lemma aeval_mul : aeval x (p * q) = aeval x p * aeval x q :=
alg_hom.map_mul _ _ _
Expand Down
2 changes: 1 addition & 1 deletion src/data/polynomial/basic.lean
Expand Up @@ -291,7 +291,7 @@ lemma C_pow : C (a ^ n) = C a ^ n := C.map_pow a n

@[simp]
lemma C_eq_nat_cast (n : ℕ) : C (n : R) = (n : polynomial R) :=
C.map_nat_cast n
map_nat_cast C n

@[simp] lemma C_mul_monomial : C a * monomial n b = monomial n (a * b) :=
by simp only [←monomial_zero_left, monomial_mul_monomial, zero_add]
Expand Down
11 changes: 6 additions & 5 deletions src/data/polynomial/derivative.lean
Expand Up @@ -214,10 +214,11 @@ theorem derivative_map [comm_semiring S] (p : polynomial R) (f : R →+* S) :
polynomial.induction_on p
(λ r, by rw [map_C, derivative_C, derivative_C, map_zero])
(λ p q ihp ihq, by rw [map_add, derivative_add, ihp, ihq, derivative_add, map_add])
(λ n r ih, by rw [map_mul, map_C, polynomial.map_pow, map_X,
derivative_mul, derivative_pow_succ, derivative_C, zero_mul, zero_add, derivative_X, mul_one,
derivative_mul, derivative_pow_succ, derivative_C, zero_mul, zero_add, derivative_X, mul_one,
map_mul, map_C, map_mul, polynomial.map_pow, map_add, map_nat_cast, map_one, map_X])
(λ n r ih, by rw [map_mul, map_C, polynomial.map_pow, map_X, derivative_mul, derivative_pow_succ,
derivative_C, zero_mul, zero_add, derivative_X, mul_one, derivative_mul,
derivative_pow_succ, derivative_C, zero_mul, zero_add, derivative_X, mul_one,
map_mul, map_C, map_mul, polynomial.map_pow, map_add,
polynomial.map_nat_cast, map_one, map_X])

@[simp]
theorem iterate_derivative_map [comm_semiring S] (p : polynomial R) (f : R →+* S) (k : ℕ):
Expand Down Expand Up @@ -293,7 +294,7 @@ rfl

@[simp] lemma derivative_cast_nat {n : ℕ} : derivative (n : polynomial R) = 0 :=
begin
rw ← C.map_nat_cast n,
rw ← map_nat_cast C n,
exact derivative_C,
end

Expand Down
7 changes: 4 additions & 3 deletions src/data/polynomial/eval.lean
Expand Up @@ -505,8 +505,9 @@ def map_ring_hom (f : R →+* S) : polynomial R →+* polynomial S :=

@[simp] lemma coe_map_ring_hom (f : R →+* S) : ⇑(map_ring_hom f) = map f := rfl

@[simp] theorem map_nat_cast (n : ℕ) : (n : polynomial R).map f = n :=
(map_ring_hom f).map_nat_cast n
-- todo: this will be removed in #11161, so `protecting` is a reasonable temporary strat
@[simp] protected theorem map_nat_cast (n : ℕ) : (n : polynomial R).map f = n :=
map_nat_cast (map_ring_hom f) n

@[simp]
lemma coeff_map (n : ℕ) : coeff (p.map f) n = f (coeff p n) :=
Expand Down Expand Up @@ -668,7 +669,7 @@ lemma eval_nat_cast_map (f : R →+* S) (p : polynomial R) (n : ℕ) :
begin
apply polynomial.induction_on' p,
{ intros p q hp hq, simp only [hp, hq, map_add, ring_hom.map_add, eval_add] },
{ intros n r, simp only [f.map_nat_cast, eval_monomial, map_monomial, f.map_pow, f.map_mul] }
{ intros n r, simp only [map_nat_cast f, eval_monomial, map_monomial, f.map_pow, f.map_mul] }
end

@[simp]
Expand Down

0 comments on commit 168ad7f

Please sign in to comment.