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

Commit 168ad7f

Browse files
committed
feat(data/nat/cast): generalize to fun_like (#11128)
1 parent 1533f15 commit 168ad7f

File tree

34 files changed

+118
-103
lines changed

34 files changed

+118
-103
lines changed

archive/100-theorems-list/16_abel_ruffini.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ by simp [Φ]
4141
by simp [Φ, coeff_X_pow]
4242

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

4646
variables [nontrivial R]
4747

src/algebra/algebra/basic.lean

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,9 +582,6 @@ lemma map_finsupp_sum {α : Type*} [has_zero α] {ι : Type*} (f : ι →₀ α)
582582
φ (f.sum g) = f.sum (λ i a, φ (g i a)) :=
583583
φ.map_sum _ _
584584

585-
@[simp] lemma map_nat_cast (n : ℕ) : φ n = n :=
586-
φ.to_ring_hom.map_nat_cast n
587-
588585
lemma map_bit0 (x) : φ (bit0 x) = bit0 (φ x) := map_bit0 _ _
589586
lemma map_bit1 (x) : φ (bit1 x) = bit1 (φ x) := map_bit1 _ _
590587

src/algebra/char_p/basic.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ lemma ring_hom.char_p_iff_char_p {K L : Type*} [division_ring K] [semiring L] [n
216216
begin
217217
split;
218218
{ introI _c, constructor, intro n,
219-
rw [← @char_p.cast_eq_zero_iff _ _ _ p _c n, ← f.injective.eq_iff, f.map_nat_cast, f.map_zero] }
219+
rw [← @char_p.cast_eq_zero_iff _ _ _ p _c n, ← f.injective.eq_iff, map_nat_cast f, f.map_zero] }
220220
end
221221

222222
section frobenius
@@ -278,7 +278,7 @@ theorem frobenius_zero : frobenius R p 0 = 0 := (frobenius R p).map_zero
278278
theorem frobenius_add : frobenius R p (x + y) = frobenius R p x + frobenius R p y :=
279279
(frobenius R p).map_add x y
280280

281-
theorem frobenius_nat_cast (n : ℕ) : frobenius R p n = n := (frobenius R p).map_nat_cast n
281+
theorem frobenius_nat_cast (n : ℕ) : frobenius R p n = n := map_nat_cast (frobenius R p) n
282282

283283
open_locale big_operators
284284
variables {R}

src/algebra/char_p/pi.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ instance pi (ι : Type u) [hi : nonempty ι] (R : Type v) [semiring R] (p : ℕ)
1919
char_p (ι → R) p :=
2020
⟨λ x, let ⟨i⟩ := hi in iff.symm $ (char_p.cast_eq_zero_iff R p x).symm.trans
2121
⟨λ h, funext $ λ j, show pi.eval_ring_hom (λ _, R) j (↑x : ι → R) = 0,
22-
by rw [ring_hom.map_nat_cast, h],
23-
λ h, (pi.eval_ring_hom (λ _: ι, R) i).map_nat_cast x ▸ by rw [h, ring_hom.map_zero]⟩⟩
22+
by rw [map_nat_cast, h],
23+
λ h, map_nat_cast (pi.eval_ring_hom (λ _: ι, R) i) x ▸ by rw [h, ring_hom.map_zero]⟩⟩
2424

2525
-- diamonds
2626
instance pi' (ι : Type u) [hi : nonempty ι] (R : Type v) [comm_ring R] (p : ℕ) [char_p R p] :

src/algebra/char_p/quotient.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace char_p
1818
theorem quotient (R : Type u) [comm_ring R] (p : ℕ) [hp1 : fact p.prime] (hp2 : ↑p ∈ nonunits R) :
1919
char_p (R ⧸ (ideal.span {p} : ideal R)) p :=
2020
have hp0 : (p : R ⧸ (ideal.span {p} : ideal R)) = 0,
21-
from (ideal.quotient.mk (ideal.span {p} : ideal R)).map_nat_cast p ▸
21+
from map_nat_cast (ideal.quotient.mk (ideal.span {p} : ideal R)) p ▸
2222
ideal.quotient.eq_zero_iff_mem.2 (ideal.subset_span $ set.mem_singleton _),
2323
ring_char.of_eq $ or.resolve_left ((nat.dvd_prime hp1.1).1 $ ring_char.dvd hp0) $ λ h1,
2424
hp2 $ is_unit_iff_dvd_one.2 $ ideal.mem_span_singleton.1 $ ideal.quotient.eq_zero_iff_mem.1 $
@@ -30,7 +30,7 @@ lemma quotient' {R : Type*} [comm_ring R] (p : ℕ) [char_p R p] (I : ideal R)
3030
(h : ∀ x : ℕ, (x : R) ∈ I → (x : R) = 0) :
3131
char_p (R ⧸ I) p :=
3232
⟨λ x, begin
33-
rw [←cast_eq_zero_iff R p x, ←(ideal.quotient.mk I).map_nat_cast],
33+
rw [←cast_eq_zero_iff R p x, ←map_nat_cast (ideal.quotient.mk I)],
3434
refine quotient.eq'.trans (_ : ↑x - 0 ∈ I ↔ _),
3535
rw sub_zero,
3636
exact ⟨h x, λ h', h'.symm ▸ I.zero_mem⟩,

src/algebra/char_p/subring.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ namespace char_p
1818
instance subsemiring (R : Type u) [semiring R] (p : ℕ) [char_p R p] (S : subsemiring R) :
1919
char_p S p :=
2020
⟨λ x, iff.symm $ (char_p.cast_eq_zero_iff R p x).symm.trans
21-
⟨λ h, subtype.eq $ show S.subtype x = 0, by rw [ring_hom.map_nat_cast, h],
22-
λ h, S.subtype.map_nat_cast x ▸ by rw [h, ring_hom.map_zero]⟩⟩
21+
⟨λ h, subtype.eq $ show S.subtype x = 0, by rw [map_nat_cast, h],
22+
λ h, map_nat_cast S.subtype x ▸ by rw [h, ring_hom.map_zero]⟩⟩
2323

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

3030
instance subring' (R : Type u) [comm_ring R] (p : ℕ) [char_p R p] (S : subring R) :
3131
char_p S p :=

src/algebra/char_zero.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ section ring_hom
200200
variables {R S : Type*} [semiring R] [semiring S]
201201

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

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

210210
end ring_hom

src/algebra/group_power/lemmas.lean

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ section monoid
2424
variables [monoid M] [monoid N] [add_monoid A] [add_monoid B]
2525

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

3134
@[simp, norm_cast, to_additive]
3235
lemma units.coe_pow (u : Mˣ) (n : ℕ) : ((u ^ n : Mˣ) : M) = u ^ n :=

src/algebra/ne_zero.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ instance char_zero [ne_zero n] [add_monoid M] [has_one M] [char_zero M] : ne_zer
5050
lemma of_map [has_zero R] [has_zero M] [zero_hom_class F R M] (f : F) [ne_zero (f r)] :
5151
ne_zero r := ⟨λ h, ne (f r) $ by convert map_zero f⟩
5252

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

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

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

6666
lemma of_no_zero_smul_divisors [comm_ring R] [ne_zero (n : R)] [ring M] [nontrivial M]
6767
[algebra R M] [no_zero_smul_divisors R M] : ne_zero (n : M) :=
68-
of_injective $ no_zero_smul_divisors.algebra_map_injective R M
68+
nat_of_injective $ no_zero_smul_divisors.algebra_map_injective R M
6969

7070
lemma of_ne_zero_coe [has_zero R] [has_one R] [has_add R] [h : ne_zero (n : R)] : ne_zero n :=
7171
by {casesI h, rintro rfl, contradiction}⟩

src/data/complex/basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ norm_sq.map_div z w
363363
/-! ### Cast lemmas -/
364364

365365
@[simp, norm_cast] theorem of_real_nat_cast (n : ℕ) : ((n : ℝ) : ℂ) = n :=
366-
of_real.map_nat_cast n
366+
map_nat_cast of_real n
367367

368368
@[simp, norm_cast] lemma nat_cast_re (n : ℕ) : (n : ℂ).re = n :=
369369
by rw [← of_real_nat_cast, of_real_re]

0 commit comments

Comments
 (0)