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

Commit 0dca20a

Browse files
committed
feat(data/(d)finsupp): update_eq_sub_add_single (#9184)
Also with `erase_eq_sub_single`. Co-authored-by: Yakov Pechersky <pechersky@users.noreply.github.com>
1 parent 8ec7fcf commit 0dca20a

File tree

3 files changed

+76
-6
lines changed

3 files changed

+76
-6
lines changed

src/algebra/group/pi.lean

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,15 @@ lemma pi.single_mul [Π i, mul_zero_class $ f i] (i : I) (x y : f i) :
234234
single i (x * y) = single i x * single i y :=
235235
(mul_hom.single f i).map_mul x y
236236

237+
lemma pi.update_eq_sub_add_single [Π i, add_group $ f i] (g : Π (i : I), f i) (x : f i) :
238+
function.update g i x = g - single i (g i) + single i x :=
239+
begin
240+
ext j,
241+
rcases eq_or_ne i j with rfl|h,
242+
{ simp },
243+
{ simp [function.update_noteq h.symm, h] }
244+
end
245+
237246
end single
238247

239248
section piecewise

src/data/dfinsupp.lean

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,15 @@ by simp
546546
lemma erase_ne {i i' : ι} {f : Π₀ i, β i} (h : i' ≠ i) : (f.erase i) i' = f i' :=
547547
by simp [h]
548548

549+
lemma erase_eq_sub_single {β : ι → Type*} [Π i, add_group (β i)] (f : Π₀ i, β i) (i : ι) :
550+
f.erase i = f - single i (f i) :=
551+
begin
552+
ext j,
553+
rcases eq_or_ne i j with rfl|h,
554+
{ simp },
555+
{ simp [erase_ne h.symm, single_eq_of_ne h] }
556+
end
557+
549558
@[simp] lemma erase_zero (i : ι) : erase i (0 : Π₀ i, β i) = 0 :=
550559
ext $ λ _, if_t_t _ _
551560

@@ -614,6 +623,31 @@ begin
614623
{ simp [hi.symm] }
615624
end
616625

626+
lemma update_eq_single_add_erase {β : ι → Type*} [Π i, add_zero_class (β i)] (f : Π₀ i, β i) (i : ι)
627+
(b : β i) [decidable (b = 0)] :
628+
f.update i b = single i b + f.erase i :=
629+
begin
630+
ext j,
631+
rcases eq_or_ne i j with rfl|h,
632+
{ simp },
633+
{ simp [function.update_noteq h.symm, h, erase_ne, h.symm] }
634+
end
635+
636+
lemma update_eq_erase_add_single {β : ι → Type*} [Π i, add_zero_class (β i)] (f : Π₀ i, β i) (i : ι)
637+
(b : β i) [decidable (b = 0)] :
638+
f.update i b = f.erase i + single i b :=
639+
begin
640+
ext j,
641+
rcases eq_or_ne i j with rfl|h,
642+
{ simp },
643+
{ simp [function.update_noteq h.symm, h, erase_ne, h.symm] }
644+
end
645+
646+
lemma update_eq_sub_add_single {β : ι → Type*} [Π i, add_group (β i)] (f : Π₀ i, β i) (i : ι)
647+
(b : β i) [decidable (b = 0)] :
648+
f.update i b = f - single i (f i) + single i b :=
649+
by rw [update_eq_erase_add_single f i b, erase_eq_sub_single f i]
650+
617651
end update
618652

619653
end basic

src/data/finsupp/basic.lean

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -815,15 +815,29 @@ See `finsupp.lapply` for the stronger version as a linear map. -/
815815
@[simps apply]
816816
def apply_add_hom (a : α) : (α →₀ M) →+ M := ⟨λ g, g a, zero_apply, λ _ _, add_apply _ _ _⟩
817817

818+
lemma update_eq_single_add_erase (f : α →₀ M) (a : α) (b : M) :
819+
f.update a b = single a b + f.erase a :=
820+
begin
821+
ext j,
822+
rcases eq_or_ne a j with rfl|h,
823+
{ simp },
824+
{ simp [function.update_noteq h.symm, single_apply, h, erase_ne, h.symm] }
825+
end
826+
827+
lemma update_eq_erase_add_single (f : α →₀ M) (a : α) (b : M) :
828+
f.update a b = f.erase a + single a b :=
829+
begin
830+
ext j,
831+
rcases eq_or_ne a j with rfl|h,
832+
{ simp },
833+
{ simp [function.update_noteq h.symm, single_apply, h, erase_ne, h.symm] }
834+
end
835+
818836
lemma single_add_erase (a : α) (f : α →₀ M) : single a (f a) + f.erase a = f :=
819-
ext $ λ a',
820-
if h : a = a' then by subst h; simp only [add_apply, single_eq_same, erase_same, add_zero]
821-
else by simp only [add_apply, single_eq_of_ne h, zero_add, erase_ne (ne.symm h)]
837+
by rw [←update_eq_single_add_erase, update_self]
822838

823839
lemma erase_add_single (a : α) (f : α →₀ M) : f.erase a + single a (f a) = f :=
824-
ext $ λ a',
825-
if h : a = a' then by subst h; simp only [add_apply, single_eq_same, erase_same, zero_add]
826-
else by simp only [add_apply, single_eq_of_ne h, add_zero, erase_ne (ne.symm h)]
840+
by rw [←update_eq_erase_add_single, update_self]
827841

828842
@[simp] lemma erase_add (a : α) (f f' : α →₀ M) : erase a (f + f') = erase a f + erase a f' :=
829843
begin
@@ -1089,6 +1103,19 @@ finset.subset.antisymm
10891103
(calc support f = support (- (- f)) : congr_arg support (neg_neg _).symm
10901104
... ⊆ support (- f) : support_map_range)
10911105

1106+
lemma erase_eq_sub_single [add_group G] (f : α →₀ G) (a : α) :
1107+
f.erase a = f - single a (f a) :=
1108+
begin
1109+
ext a',
1110+
rcases eq_or_ne a a' with rfl|h,
1111+
{ simp },
1112+
{ simp [erase_ne h.symm, single_eq_of_ne h] }
1113+
end
1114+
1115+
lemma update_eq_sub_add_single [add_group G] (f : α →₀ G) (a : α) (b : G) :
1116+
f.update a b = f - single a (f a) + single a b :=
1117+
by rw [update_eq_erase_add_single, erase_eq_sub_single]
1118+
10921119
@[simp] lemma sum_apply [has_zero M] [add_comm_monoid N]
10931120
{f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :
10941121
(f.sum g) a₂ = f.sum (λa₁ b, g a₁ b a₂) :=

0 commit comments

Comments
 (0)