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

Commit e48ad0d

Browse files
urkudmergify[bot]
authored andcommitted
chore(*): migrate units.map to bundled homs (#1331)
1 parent 02548ad commit e48ad0d

File tree

8 files changed

+58
-24
lines changed

8 files changed

+58
-24
lines changed

src/algebra/associated.lean

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ def is_unit [monoid α] (a : α) : Prop := ∃u:units α, a = u
1515

1616
@[simp] lemma is_unit_unit [monoid α] (u : units α) : is_unit (u : α) := ⟨u, rfl⟩
1717

18+
theorem is_unit.mk0 [division_ring α] (x : α) (hx : x ≠ 0) : is_unit x := is_unit_unit (units.mk0 x hx)
19+
20+
lemma is_unit.map [monoid α] [monoid β] (f : α →* β) {x : α} (h : is_unit x) : is_unit (f x) :=
21+
by rcases h with ⟨y, rfl⟩; exact is_unit_unit (units.map f y)
22+
23+
lemma is_unit.map' [monoid α] [monoid β] (f : α → β) {x : α} (h : is_unit x) [is_monoid_hom f] :
24+
is_unit (f x) :=
25+
h.map (as_monoid_hom f)
26+
1827
@[simp] theorem is_unit_zero_iff [semiring α] : is_unit (0 : α) ↔ (0:α) = 1 :=
1928
⟨λ ⟨⟨_, a, (a0 : 0 * a = 1), _⟩, rfl⟩, by rwa zero_mul at a0,
2029
λ h, begin

src/algebra/group/hom.lean

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,17 @@ infixr ` →* `:25 := monoid_hom
275275
instance {M : Type*} {N : Type*} [monoid M] [monoid N] : has_coe_to_fun (M →* N) :=
276276
⟨_, monoid_hom.to_fun⟩
277277

278+
/-- Reinterpret a map `f : M → N` as a homomorphism `M →* N` -/
279+
def as_monoid_hom {M : Type u} {N : Type v} [monoid M] [monoid N]
280+
(f : M → N) [h : is_monoid_hom f] : M →* N :=
281+
{ to_fun := f,
282+
map_one' := h.2,
283+
map_mul' := h.1.1 }
284+
285+
@[simp] lemma coe_as_monoid_hom {M : Type u} {N : Type v} [monoid M] [monoid N]
286+
(f : M → N) [is_monoid_hom f] : ⇑ (as_monoid_hom f) = f :=
287+
rfl
288+
278289
/-- Bundled add_monoid homomorphisms; use this for bundled add_group homomorphisms too. -/
279290
structure add_monoid_hom (M : Type*) (N : Type*) [add_monoid M] [add_monoid N] :=
280291
(to_fun : M → N)
@@ -301,6 +312,8 @@ attribute [to_additive add_monoid_hom.rec] monoid_hom.rec
301312
attribute [to_additive add_monoid_hom.rec_on] monoid_hom.rec_on
302313
attribute [to_additive add_monoid_hom.sizeof] monoid_hom.sizeof
303314
attribute [to_additive add_monoid_hom.to_fun] monoid_hom.to_fun
315+
attribute [to_additive as_add_monoid_hom._proof_1] as_monoid_hom._proof_1
316+
attribute [to_additive as_add_monoid_hom] as_monoid_hom
304317

305318
namespace monoid_hom
306319
variables {M : Type*} {N : Type*} {P : Type*} [monoid M] [monoid N] [monoid P]

src/algebra/group/units_hom.lean

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,38 @@ Lift monoid homomorphisms to group homomorphisms of their units subgroups.
77
-/
88
import algebra.group.units algebra.group.hom
99

10+
universes u v w
11+
1012
namespace units
11-
variables {α : Type*} {β : Type*}
13+
variables {α : Type u} {β : Type v} {γ : Type w} [monoid α] [monoid β] [monoid γ]
14+
15+
def map (f : α →* β) : units α →* units β :=
16+
monoid_hom.mk'
17+
(λ u, ⟨f u.val, f u.inv,
18+
by rw [← f.map_mul, u.val_inv, f.map_one],
19+
by rw [← f.map_mul, u.inv_val, f.map_one]⟩)
20+
(λ x y, ext (f.map_mul x y))
21+
22+
@[reducible] def map' (f : α → β) [is_monoid_hom f] : units α →* units β :=
23+
map (as_monoid_hom f)
1224

13-
variables {γ : Type*} [monoid α] [monoid β] [monoid γ] (f : α → β) (g : β → γ)
14-
[is_monoid_hom f] [is_monoid_hom g]
25+
@[simp] lemma coe_map (f : α →* β) (x : units α) : ↑(map f x) = f x := rfl
1526

16-
definition map : units α → units β :=
17-
λ u, ⟨f u.val, f u.inv,
18-
by rw [← is_monoid_hom.map_mul f, u.val_inv, is_monoid_hom.map_one f],
19-
by rw [← is_monoid_hom.map_mul f, u.inv_val, is_monoid_hom.map_one f] ⟩
27+
@[simp] lemma coe_map' (f : α → β) [is_monoid_hom f] (x : units α) :
28+
↑((map' f : units α → units β) x) = f x :=
29+
rfl
2030

21-
instance : is_group_hom (units.map f) :=
22-
{ map_mul := λ a b, by ext; exact is_monoid_hom.map_mul f a b }
31+
@[simp] lemma map_comp (f : α →* β) (g : β →* γ) : map (g.comp f) = (map g).comp (map f) := rfl
2332

24-
instance coe_is_monoid_hom : is_monoid_hom (coe : units α → α) :=
25-
{ map_one := rfl, map_mul := by simp }
33+
variables (α)
34+
@[simp] lemma map_id : map (monoid_hom.id α) = monoid_hom.id (units α) :=
35+
by ext; refl
2636

27-
@[simp] lemma coe_map (u : units α) : (map f u : β) = f u := rfl
37+
/-- Coercion `units α → α` as a monoid homomorphism. -/
38+
def coe_hom : units α →* α := ⟨coe, coe_one, coe_mul⟩
2839

29-
@[simp] lemma map_id : map (id : α → α) = id := by ext; refl
40+
@[simp] lemma coe_hom_apply (x : units α) : coe_hom α x = ↑x := rfl
3041

31-
lemma map_comp : map (g ∘ f) = map g ∘ map f := rfl
42+
instance coe_is_monoid_hom : is_monoid_hom (coe : units α → α) := (coe_hom α).is_monoid_hom
3243

3344
end units

src/data/equiv/algebra.lean

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,10 @@ variables [monoid α] [monoid β] [monoid γ]
434434
(f : α → β) (g : β → γ) [is_monoid_hom f] [is_monoid_hom g]
435435

436436
def map_equiv (h : α ≃* β) : units α ≃* units β :=
437-
{ to_fun := map h,
438-
inv_fun := map h.symm,
437+
{ inv_fun := map h.symm.to_monoid_hom,
439438
left_inv := λ u, ext $ h.left_inv u,
440439
right_inv := λ u, ext $ h.right_inv u,
441-
map_mul' := λ a b, units.ext $ h.map_mul a b}
440+
.. map h.to_monoid_hom }
442441

443442
end units
444443

src/data/polynomial.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,8 @@ lemma is_unit_iff_degree_eq_zero : is_unit p ↔ degree p = 0 :=
18981898
lemma degree_pos_of_ne_zero_of_nonunit (hp0 : p ≠ 0) (hp : ¬is_unit p) :
18991899
0 < degree p :=
19001900
lt_of_not_ge (λ h, by rw [eq_C_of_degree_le_zero h] at hp0 hp;
1901-
exact hp ⟨units.map C (units.mk0 (coeff p 0) (mt C_inj.2 (by simpa using hp0))), rfl⟩)
1901+
exact (hp $ is_unit.map' C $
1902+
is_unit.mk0 (coeff p 0) (mt C_inj.2 (by simpa using hp0))))
19021903

19031904
lemma irreducible_of_degree_eq_one (hp1 : degree p = 1) : irreducible p :=
19041905
⟨mt is_unit_iff_dvd_one.1 (λ ⟨q, hq⟩,

src/field_theory/splitting_field.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ else
136136
(λ p, by simp [@eq_comm _ _ p, -sub_eq_add_neg,
137137
irreducible_of_degree_eq_one (degree_X_sub_C _)] {contextual := tt})
138138
(associated.symm $ calc _ ~ᵤ f.map i :
139-
⟨units.map C (units.mk0 (f.map i).leading_coeff
139+
(units.map' C : units β →* units (polynomial β)) (units.mk0 (f.map i).leading_coeff
140140
(mt leading_coeff_eq_zero.1 (mt (map_eq_zero i).1 hf0))),
141141
by conv_rhs {rw [hs, ← leading_coeff_map i, mul_comm]}; refl⟩
142142
... ~ᵤ _ : associated.symm (unique_factorization_domain.factors_prod (by simpa using hf0))),

src/ring_theory/localization.lean

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,15 @@ by simp [lift', quotient.lift_on_beta, of, mk, this]
282282
@[simp] lemma lift'_apply_coe (f : localization α S → β) [is_ring_hom f]
283283
(g : S → units β) (hg : ∀ s, (g s : β) = f s) :
284284
lift' (λ a : α, f a) g hg = f :=
285-
have g = (λ s, units.map f (to_units s)),
286-
from funext $ λ x, units.ext_iff.2 $ (hg x).symm ▸ rfl,
285+
have g = (λ s, (units.map' f : units (localization α S) → units β) (to_units s)),
286+
from funext $ λ x, units.ext $ (hg x).symm ▸ rfl,
287287
funext $ λ x, localization.induction_on x
288-
(λ r s, by subst this; rw [lift'_mk, ← is_group_hom.map_inv (units.map f), units.coe_map];
288+
(λ r s, by subst this; rw [lift'_mk, ← (units.map' f).map_inv, units.coe_map'];
289289
simp [is_ring_hom.map_mul f])
290290

291291
@[simp] lemma lift_apply_coe (f : localization α S → β) [is_ring_hom f] :
292-
lift (λ a : α, f a) (λ s hs, is_unit_unit (units.map f (to_units ⟨s, hs⟩))) = f :=
292+
lift (λ a : α, f a)
293+
(λ s hs, is_unit.map' f (is_unit_unit (to_units ⟨s, hs⟩))) = f :=
293294
by rw [lift, lift'_apply_coe]
294295

295296
/-- Function extensionality for localisations:

src/ring_theory/power_series.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ instance coeff_zero.is_semiring_hom :
292292
then so is its constant coefficient.-/
293293
lemma is_unit_coeff_zero (φ : mv_power_series σ α) (h : is_unit φ) :
294294
is_unit (coeff 0 φ) :=
295-
by { rcases h with ⟨φ, rfl⟩, exact ⟨units.map (coeff 0) φ, rfl⟩ }
295+
h.map' (coeff 0)
296296

297297
instance : semimodule α (mv_power_series σ α) :=
298298
{ smul := λ a φ, C a * φ,

0 commit comments

Comments
 (0)