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

Commit 3e2fb4c

Browse files
committed
feat(data/rat/cast): generalize ext lemmas (#16268)
* generalize `monoid_with_zero_hom.ext_rat` to `monoid_with_zero`; * deduce `ext` lemma for `ring_hom`s from `monoid_with_zero_hom` version; * use hom classes.
1 parent 31297bd commit 3e2fb4c

File tree

2 files changed

+24
-36
lines changed

2 files changed

+24
-36
lines changed

src/data/rat/cast.lean

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -300,53 +300,41 @@ by rw [cast_def, map_div₀, map_int_cast, map_nat_cast, cast_def]
300300
@[simp] lemma eq_rat_cast {k} [division_ring k] [ring_hom_class F ℚ k] (f : F) (r : ℚ) : f r = r :=
301301
by rw [← map_rat_cast f, rat.cast_id]
302302

303-
lemma ring_hom.ext_rat {R : Type*} [semiring R] (f g : ℚ →+* R) : f = g :=
304-
begin
305-
ext r,
306-
refine rat.num_denom_cases_on' r _,
307-
intros a b b0,
308-
let φ : ℤ →+* R := f.comp (int.cast_ring_hom ℚ),
309-
let ψ : ℤ →+* R := g.comp (int.cast_ring_hom ℚ),
310-
rw [rat.mk_eq_div, int.cast_coe_nat],
311-
have b0' : (b:ℚ) ≠ 0 := nat.cast_ne_zero.2 b0,
312-
have : ∀ n : ℤ, f n = g n := λ n, show φ n = ψ n, by rw [φ.ext_int ψ],
313-
calc f (a * b⁻¹)
314-
= f a * f b⁻¹ * (g (b:ℤ) * g b⁻¹) :
315-
by rw [int.cast_coe_nat, ← g.map_mul, mul_inv_cancel b0', g.map_one, mul_one, f.map_mul]
316-
... = g a * f b⁻¹ * (f (b:ℤ) * g b⁻¹) : by rw [this a, ← this b]
317-
... = g (a * b⁻¹) :
318-
by rw [int.cast_coe_nat, mul_assoc, ← mul_assoc (f b⁻¹),
319-
← f.map_mul, inv_mul_cancel b0', f.map_one, one_mul, g.map_mul]
320-
end
321-
322-
instance rat.subsingleton_ring_hom {R : Type*} [semiring R] : subsingleton (ℚ →+* R) :=
323-
⟨ring_hom.ext_rat⟩
324-
325303
namespace monoid_with_zero_hom
326304

327-
variables {M : Type*} [group_with_zero M]
305+
variables {M₀ : Type*} [monoid_with_zero M₀] [monoid_with_zero_hom_class F ℚ M₀] {f g : F}
306+
include M₀
307+
308+
/-- If `f` and `g` agree on the integers then they are equal `φ`. -/
309+
theorem ext_rat' (h : ∀ m : ℤ, f m = g m) : f = g :=
310+
fun_like.ext f g $ λ r, by rw [← r.num_div_denom, div_eq_mul_inv, map_mul, map_mul, h,
311+
← int.cast_coe_nat, eq_on_inv₀ f g (h _)]
328312

329313
/-- If `f` and `g` agree on the integers then they are equal `φ`.
330314
331315
See note [partially-applied ext lemmas] for why `comp` is used here. -/
332-
@[ext]
333-
theorem ext_rat {f g : ℚ →*₀ M}
334-
(same_on_int : f.comp (int.cast_ring_hom ℚ).to_monoid_with_zero_hom =
335-
g.comp (int.cast_ring_hom ℚ).to_monoid_with_zero_hom) : f = g :=
336-
begin
337-
have same_on_int' : ∀ k : ℤ, f k = g k := congr_fun same_on_int,
338-
ext x,
339-
rw [← @rat.num_denom x, rat.mk_eq_div, map_div₀ f, map_div₀ g,
340-
same_on_int' x.num, same_on_int' x.denom],
341-
end
316+
@[ext] theorem ext_rat {f g : ℚ →*₀ M₀}
317+
(h : f.comp (int.cast_ring_hom ℚ : ℤ →*₀ ℚ) = g.comp (int.cast_ring_hom ℚ)) : f = g :=
318+
ext_rat' $ congr_fun h
342319

343320
/-- Positive integer values of a morphism `φ` and its value on `-1` completely determine `φ`. -/
344-
theorem ext_rat_on_pnat {f g : ℚ →*₀ M}
321+
theorem ext_rat_on_pnat
345322
(same_on_neg_one : f (-1) = g (-1)) (same_on_pnat : ∀ n : ℕ, 0 < n → f n = g n) : f = g :=
346-
ext_rat $ ext_int' (by simpa) ‹_›
323+
ext_rat' $ fun_like.congr_fun $ show (f : ℚ →*₀ M₀).comp (int.cast_ring_hom ℚ : ℤ →*₀ ℚ) =
324+
(g : ℚ →*₀ M₀).comp (int.cast_ring_hom ℚ : ℤ →*₀ ℚ),
325+
from ext_int' (by simpa) (by simpa)
347326

348327
end monoid_with_zero_hom
349328

329+
/-- Any two ring homomorphisms from `ℚ` to a semiring are equal. If the codomain is a division ring,
330+
then this lemma follows from `eq_rat_cast`. -/
331+
lemma ring_hom.ext_rat {R : Type*} [semiring R] [ring_hom_class F ℚ R] (f g : F) : f = g :=
332+
monoid_with_zero_hom.ext_rat' $ ring_hom.congr_fun $
333+
((f : ℚ →+* R).comp (int.cast_ring_hom ℚ)).ext_int ((g : ℚ →+* R).comp (int.cast_ring_hom ℚ))
334+
335+
instance rat.subsingleton_ring_hom {R : Type*} [semiring R] : subsingleton (ℚ →+* R) :=
336+
⟨ring_hom.ext_rat⟩
337+
350338
namespace mul_opposite
351339

352340
variables [division_ring α]

src/ring_theory/witt_vector/structure_polynomial.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ theorem witt_structure_rat_prop (Φ : mv_polynomial idx ℚ) (n : ℕ) :
133133
calc bind₁ (witt_structure_rat p Φ) (W_ ℚ n)
134134
= bind₁ (λ k, bind₁ (λ i, (rename (prod.mk i)) (W_ ℚ k)) Φ)
135135
(bind₁ (X_in_terms_of_W p ℚ) (W_ ℚ n)) :
136-
by { rw bind₁_bind₁, apply eval₂_hom_congr (ring_hom.ext_rat _ _) rfl rfl }
136+
by { rw bind₁_bind₁, exact eval₂_hom_congr (ring_hom.ext_rat _ _) rfl rfl }
137137
... = bind₁ (λ i, (rename (prod.mk i) (W_ ℚ n))) Φ :
138138
by rw [bind₁_X_in_terms_of_W_witt_polynomial p _ n, bind₁_X_right]
139139

0 commit comments

Comments
 (0)