@@ -6,6 +6,7 @@ Authors: Floris van Doorn
66module
77
88public import Mathlib.Data.Finset.Pi
9+ public import Mathlib.Data.Fintype.Defs
910public import Mathlib.Logic.Function.DependsOn
1011
1112/-!
@@ -20,6 +21,7 @@ for other purposes.
2021
2122@[expose] public section
2223variable {ι : Sort _} {π : ι → Sort _} {x : ∀ i, π i} [DecidableEq ι]
24+ {s t : Finset ι} {y : ∀ i : s, π i} {z : ∀ i : t, π i} {i : ι}
2325
2426namespace Function
2527
@@ -30,22 +32,22 @@ def updateFinset (x : ∀ i, π i) (s : Finset ι) (y : ∀ i : ↥s, π i) (i :
3032
3133open Finset Equiv
3234
33- theorem updateFinset_def {s : Finset ι} {y} :
35+ theorem updateFinset_def :
3436 updateFinset x s y = fun i ↦ if hi : i ∈ s then y ⟨i, hi⟩ else x i :=
3537 rfl
3638
3739@[simp] theorem updateFinset_empty {y} : updateFinset x ∅ y = x :=
3840 rfl
3941
40- theorem updateFinset_singleton {i y} :
42+ theorem updateFinset_singleton {y} :
4143 updateFinset x {i} y = Function.update x i (y ⟨i, mem_singleton_self i⟩) := by
4244 congr with j
4345 by_cases hj : j = i
4446 · cases hj
4547 simp only [dif_pos, Finset.mem_singleton, update_self, updateFinset]
4648 · simp [hj, updateFinset]
4749
48- theorem update_eq_updateFinset {i y} :
50+ theorem update_eq_updateFinset {y} :
4951 Function.update x i y = updateFinset x {i} (uniqueElim y) := by
5052 congr with j
5153 by_cases hj : j = i
@@ -71,8 +73,7 @@ theorem _root_.DependsOn.update {α : Type*} {f : (Π i, π i) → α} {s : Fins
7173 simp_rw [Function.update_eq_updateFinset, erase_eq, coe_sdiff]
7274 exact hf.updateFinset _
7375
74- theorem updateFinset_updateFinset {s t : Finset ι} (hst : Disjoint s t)
75- {y : ∀ i : ↥s, π i} {z : ∀ i : ↥t, π i} :
76+ theorem updateFinset_updateFinset (hst : Disjoint s t) :
7677 updateFinset (updateFinset x s y) t z =
7778 updateFinset x (s ∪ t) (Equiv.piFinsetUnion π hst ⟨y, z⟩) := by
7879 set e := Equiv.Finset.union s t hst
@@ -107,4 +108,22 @@ lemma updateFinset_restrict {s : Finset ι} (x : Π i, π i) :
107108 ext i
108109 simp [updateFinset]
109110
111+ -- this would be slightly nicer if we had a version of `Equiv.piFinsetUnion` for `insert`.
112+ theorem update_updateFinset {z} (hi : i ∉ s) :
113+ Function.update (updateFinset x s y) i z = updateFinset x (s ∪ {i})
114+ ((Equiv.piFinsetUnion π <| Finset.disjoint_singleton_right.mpr hi) (y, uniqueElim z)) := by
115+ rw [update_eq_updateFinset, updateFinset_updateFinset]
116+
117+ theorem updateFinset_congr (h : s = t) :
118+ updateFinset x s y = updateFinset x t (fun i ↦ y ⟨i, h ▸ i.prop⟩) := by
119+ subst h; rfl
120+
121+ theorem updateFinset_univ [Fintype ι] {y : ∀ i : Finset.univ, π i} :
122+ updateFinset x .univ y = fun i : ι ↦ y ⟨i, Finset.mem_univ i⟩ := by
123+ simp [updateFinset_def]
124+
125+ theorem updateFinset_univ_apply [Fintype ι] {y : ∀ i : Finset.univ, π i} {i : ι} :
126+ updateFinset x .univ y i = y ⟨i, Finset.mem_univ i⟩ := by
127+ simp [updateFinset_def]
128+
110129end Function
0 commit comments