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

Commit 372d294

Browse files
committed
feat(data/finsupp): lift a collection of add_monoid_homs to an add_monoid_hom on α →₀ β (#4395)
1 parent b1d3ef9 commit 372d294

2 files changed

Lines changed: 81 additions & 71 deletions

File tree

src/algebra/module/basic.lean

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ instance : has_coe_to_fun (M →ₗ[R] M₂) := ⟨_, to_fun⟩
267267
@[simp] lemma coe_mk (f : M → M₂) (h₁ h₂) :
268268
((linear_map.mk f h₁ h₂ : M →ₗ[R] M₂) : M → M₂) = f := rfl
269269

270-
271270
/-- Identity map as a `linear_map` -/
272271
def id : M →ₗ[R] M :=
273272
⟨id, λ _ _, rfl, λ _ _, rfl⟩
@@ -334,6 +333,10 @@ def to_add_monoid_hom : M →+ M₂ :=
334333
f (∑ i in t, g i) = (∑ i in t, f (g i)) :=
335334
f.to_add_monoid_hom.map_sum _ _
336335

336+
theorem to_add_monoid_hom_injective [semimodule R M] [semimodule R M₂] :
337+
function.injective (to_add_monoid_hom : (M →ₗ[R] M₂) → (M →+ M₂)) :=
338+
λ f g h, coe_inj $ funext $ add_monoid_hom.congr_fun h
339+
337340
end
338341

339342
section

src/data/finsupp/basic.lean

Lines changed: 77 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Copyright (c) 2017 Johannes Hölzl. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Johannes Hölzl, Scott Morrison
55
-/
6+
import algebra.group.pi
67
import algebra.big_operators.order
78
import algebra.module.basic
89
import data.fintype.card
@@ -451,19 +452,25 @@ def sum [has_zero β] [add_comm_monoid γ] (f : α →₀ β) (g : α → β →
451452
def prod [has_zero β] [comm_monoid γ] (f : α →₀ β) (g : α → β → γ) : γ :=
452453
∏ a in f.support, g a (f a)
453454

455+
@[to_additive]
456+
lemma prod_of_support_subset [has_zero β] [comm_monoid γ] (f : α →₀ β) {s : finset α}
457+
(hs : f.support ⊆ s) (g : α → β → γ) (h : ∀ i ∈ s, g i 0 = 1) :
458+
f.prod g = ∏ x in s, g x (f x) :=
459+
finset.prod_subset hs $ λ x hxs hx, h x hxs ▸ congr_arg (g x) $ not_mem_support_iff.1 hx
460+
454461
@[to_additive]
455462
lemma prod_fintype [fintype α] [has_zero β] [comm_monoid γ]
456463
(f : α →₀ β) (g : α → β → γ) (h : ∀ i, g i 0 = 1) :
457464
f.prod g = ∏ i, g i (f i) :=
458-
begin
459-
classical,
460-
rw [finsupp.prod, ← fintype.prod_extend_by_one, finset.prod_congr rfl],
461-
intros i hi,
462-
split_ifs with hif hif,
463-
{ refl },
464-
{ rw finsupp.not_mem_support_iff at hif,
465-
rw [hif, h] }
466-
end
465+
f.prod_of_support_subset (subset_univ _) g (λ x _, h x)
466+
467+
@[simp, to_additive]
468+
lemma prod_single_index [has_zero β] [comm_monoid γ] {a : α} {b : β} {h : α → β → γ}
469+
(h_zero : h a 0 = 1) :
470+
(single a b).prod h = h a b :=
471+
calc (single a b).prod h = ∏ x in {a}, h x (single a b x) :
472+
prod_of_support_subset _ support_single_subset h $ λ x hx, (mem_singleton.1 hx).symm ▸ h_zero
473+
... = h a b : by simp
467474

468475
@[to_additive]
469476
lemma prod_map_range_index [has_zero β₁] [has_zero β₂] [comm_monoid γ]
@@ -521,15 +528,6 @@ end
521528
section add_monoid
522529
variables [add_monoid β]
523530

524-
@[to_additive]
525-
lemma prod_single_index [comm_monoid γ] {a : α} {b : β} {h : α → β → γ} (h_zero : h a 0 = 1) :
526-
(single a b).prod h = h a b :=
527-
begin
528-
by_cases h : b = 0,
529-
{ simp only [h, h_zero, single_zero]; refl },
530-
{ simp only [finsupp.prod, support_single_ne_zero h, prod_singleton, single_eq_same] }
531-
end
532-
533531
instance : has_add (α →₀ β) := ⟨zip_with (+) (add_zero 0)⟩
534532

535533
@[simp] lemma add_apply {g₁ g₂ : α →₀ β} {a : α} : (g₁ + g₂) a = g₁ a + g₂ a :=
@@ -565,6 +563,10 @@ instance : add_monoid (α →₀ β) :=
565563
zero_add := assume ⟨s, f, hf⟩, ext $ assume a, zero_add _,
566564
add_zero := assume ⟨s, f, hf⟩, ext $ assume a, add_zero _ }
567565

566+
/-- `finsupp.single` as an `add_monoid_hom`. -/
567+
@[simps] def single_add_hom (a : α) : β →+ α →₀ β :=
568+
⟨single a, single_zero, λ _ _, single_add⟩
569+
568570
/-- Evaluation of a function `f : α →₀ β` at a point as an additive monoid homomorphism. -/
569571
def eval_add_hom (a : α) : (α →₀ β) →+ β := ⟨λ g, g a, zero_apply, λ _ _, add_apply⟩
570572

@@ -618,6 +620,22 @@ begin
618620
rw [support_erase, hf, finset.erase_insert has] }
619621
end
620622

623+
@[simp] lemma add_closure_Union_range_single :
624+
add_submonoid.closure (⋃ a : α, set.range (single a : β → α →₀ β)) = ⊤ :=
625+
top_unique $ λ x hx, finsupp.induction x (add_submonoid.zero_mem _) $
626+
λ a b f ha hb hf, add_submonoid.add_mem _
627+
(add_submonoid.subset_closure $ set.mem_Union.2 ⟨a, set.mem_range_self _⟩) hf
628+
629+
@[ext] lemma add_hom_ext [add_monoid γ] ⦃f g : (α →₀ β) →+ γ⦄
630+
(H : ∀ x y, f (single x y) = g (single x y)) :
631+
f = g :=
632+
begin
633+
refine add_monoid_hom.eq_of_eq_on_mdense add_closure_Union_range_single (λ f hf, _),
634+
simp only [set.mem_Union, set.mem_range] at hf,
635+
rcases hf with ⟨x, y, rfl⟩,
636+
apply H
637+
end
638+
621639
lemma map_range_add [add_monoid β₁] [add_monoid β₂]
622640
{f : β₁ → β₂} {hf : f 0 = 0} (hf' : ∀ x y, f (x + y) = f x + f y) (v₁ v₂ : α →₀ β₁) :
623641
map_range f hf (v₁ + v₂) = map_range f hf v₁ + map_range f hf v₂ :=
@@ -749,62 +767,52 @@ f.support.sum_hom (@has_neg.neg γ _)
749767
f.sum (λa b, h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=
750768
by rw [sub_eq_add_neg, ←sum_neg, ←sum_add]; refl
751769

752-
@[simp] lemma sum_single [add_comm_monoid β] (f : α →₀ β) :
753-
f.sum single = f :=
754-
have ∀a:α, f.sum (λa' b, ite (a' = a) b 0) =
755-
∑ a' in {a}, ite (a' = a) (f a') 0,
756-
begin
757-
intro a,
758-
by_cases h : a ∈ f.support,
759-
{ have : ({a} : finset α) ⊆ f.support,
760-
{ simpa only [finset.subset_iff, mem_singleton, forall_eq] },
761-
refine (finset.sum_subset this (λ _ _ H, _)).symm,
762-
exact if_neg (mt mem_singleton.2 H) },
763-
{ transitivity (∑ a in f.support, (0 : β)),
764-
{ refine (finset.sum_congr rfl $ λ a' ha', if_neg _),
765-
rintro rfl, exact h ha' },
766-
{ rw [sum_const_zero, sum_singleton, if_pos rfl, not_mem_support_iff.1 h] } }
767-
end,
768-
ext $ assume a, by simp only [sum_apply, single_apply, this, sum_singleton, if_pos]
769-
770770
@[to_additive]
771771
lemma prod_add_index [add_comm_monoid β] [comm_monoid γ] {f g : α →₀ β}
772772
{h : α → β → γ} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
773773
(f + g).prod h = f.prod h * g.prod h :=
774-
have f_eq : ∏ a in f.support ∪ g.support, h a (f a) = f.prod h,
775-
from (finset.prod_subset (finset.subset_union_left _ _) $
776-
by intros _ _ H; rw [not_mem_support_iff.1 H, h_zero]).symm,
777-
have g_eq : ∏ a in f.support ∪ g.support, h a (g a) = g.prod h,
778-
from (finset.prod_subset (finset.subset_union_right _ _) $
779-
by intros _ _ H; rw [not_mem_support_iff.1 H, h_zero]).symm,
780-
calc ∏ a in (f + g).support, h a ((f + g) a) =
781-
∏ a in f.support ∪ g.support, h a ((f + g) a) :
782-
finset.prod_subset support_add $
783-
by intros _ _ H; rw [not_mem_support_iff.1 H, h_zero]
784-
... = (∏ a in f.support ∪ g.support, h a (f a)) *
785-
(∏ a in f.support ∪ g.support, h a (g a)) :
786-
by simp only [add_apply, h_add, finset.prod_mul_distrib]
787-
... = _ : by rw [f_eq, g_eq]
774+
have hf : f.prod h = ∏ a in f.support ∪ g.support, h a (f a),
775+
from f.prod_of_support_subset (subset_union_left _ _) _ $ λ a ha, h_zero a,
776+
have hg : g.prod h = ∏ a in f.support ∪ g.support, h a (g a),
777+
from g.prod_of_support_subset (subset_union_right _ _) _ $ λ a ha, h_zero a,
778+
have hfg : (f + g).prod h = ∏ a in f.support ∪ g.support, h a ((f + g) a),
779+
from (f + g).prod_of_support_subset support_add _ $ λ a ha, h_zero a,
780+
by simp only [*, add_apply, prod_mul_distrib]
781+
782+
/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (β →+ γ)`
783+
and monoid homomorphisms `(α →₀ β) →+ γ`. -/
784+
def lift_add_hom [add_comm_monoid β] [add_comm_monoid γ] : (α → β →+ γ) ≃+ ((α →₀ β) →+ γ) :=
785+
{ to_fun := λ F,
786+
{ to_fun := λ f, f.sum (λ x, F x),
787+
map_zero' := finset.sum_empty,
788+
map_add' := λ _ _, sum_add_index (λ x, (F x).map_zero) (λ x, (F x).map_add) },
789+
inv_fun := λ F x, F.comp $ single_add_hom x,
790+
left_inv := λ F, by { ext, simp },
791+
right_inv := λ F, by { ext, simp },
792+
map_add' := λ F G, by { ext, simp } }
793+
794+
@[simp] lemma lift_add_hom_apply [add_comm_monoid β] [add_comm_monoid γ]
795+
(F : α → β →+ γ) (f : α →₀ β) :
796+
lift_add_hom F f = f.sum (λ x, F x) :=
797+
rfl
798+
799+
@[simp] lemma lift_add_hom_symm_apply [add_comm_monoid β] [add_comm_monoid γ]
800+
(F : (α →₀ β) →+ γ) (x : α) :
801+
lift_add_hom.symm F x = F.comp (single_add_hom x) :=
802+
rfl
803+
804+
@[simp] lemma lift_add_hom_single_add_hom [add_comm_monoid β] :
805+
lift_add_hom (single_add_hom : α → β →+ α →₀ β) = add_monoid_hom.id _ :=
806+
lift_add_hom.to_equiv.apply_eq_iff_eq_symm_apply.2 rfl
807+
808+
@[simp] lemma sum_single [add_comm_monoid β] (f : α →₀ β) :
809+
f.sum single = f :=
810+
add_monoid_hom.congr_fun lift_add_hom_single_add_hom f
788811

789812
lemma sum_sub_index [add_comm_group β] [add_comm_group γ] {f g : α →₀ β}
790813
{h : α → β → γ} (h_sub : ∀a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) :
791814
(f - g).sum h = f.sum h - g.sum h :=
792-
have h_zero : ∀a, h a 0 = 0,
793-
from assume a,
794-
have h a (0 - 0) = h a 0 - h a 0, from h_sub a 0 0,
795-
by simpa only [sub_self] using this,
796-
have h_neg : ∀a b, h a (- b) = - h a b,
797-
from assume a b,
798-
have h a (0 - b) = h a 0 - h a b, from h_sub a 0 b,
799-
by simpa only [h_zero, zero_sub] using this,
800-
have h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ + h a b₂,
801-
from assume a b₁ b₂,
802-
have h a (b₁ - (- b₂)) = h a b₁ - h a (- b₂), from h_sub a b₁ (-b₂),
803-
by simpa only [h_neg, sub_neg_eq_add] using this,
804-
calc (f - g).sum h = (f + - g).sum h : rfl
805-
... = f.sum h + - g.sum h : by simp only [sum_add_index h_zero h_add, sum_neg_index h_zero,
806-
h_neg, sum_neg]
807-
... = f.sum h - g.sum h : rfl
815+
(lift_add_hom (λ a, add_monoid_hom.of_map_sub (h a) (h_sub a))).map_sub f g
808816

809817
@[to_additive]
810818
lemma prod_finset_sum_index [add_comm_monoid β] [comm_monoid γ]
@@ -1524,11 +1532,10 @@ lemma smul_single_one [semiring β] (a : α) (b : β) : b • single a 1 = singl
15241532
by rw [smul_single, smul_eq_mul, mul_one]
15251533

15261534
/-- Two `R`-linear maps from `finsupp X R` which agree on `single x 1` agree everywhere. -/
1527-
lemma hom_ext [semiring β] [add_comm_monoid γ] [semimodule β γ] (φ ψ : (α →₀ β) →ₗ[β] γ)
1535+
@[ext] lemma hom_ext [semiring β] [add_comm_monoid γ] [semimodule β γ] φ ψ : (α →₀ β) →ₗ[β] γ
15281536
(h : ∀ a : α, φ (single a 1) = ψ (single a 1)) : φ = ψ :=
1529-
linear_map.ext $ λ x, finsupp.induction x (by rw [φ.map_zero, ψ.map_zero]) $
1530-
λ _ _ _ _ _ hgh,
1531-
by rw [φ.map_add, ψ.map_add, hgh, ←smul_single_one, φ.map_smul, ψ.map_smul, h]
1537+
linear_map.to_add_monoid_hom_injective $ add_hom_ext $ λ x y,
1538+
by simp only [← smul_single_one x y, linear_map.to_add_monoid_hom_coe, linear_map.map_smul, h]
15321539

15331540
end
15341541

0 commit comments

Comments
 (0)