Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: define
updateFinset
which updates a finite number components …
…of a vector (#7341) * from the Sobolev project (formerly: marginal project) --------- Co-authored-by: Mario Carneiro <di.gama@gmail.com>
- Loading branch information
1 parent
a1f33eb
commit 0eb6b93
Showing
6 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/- | ||
Copyright (c) 2023 Floris van Doorn. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Floris van Doorn | ||
-/ | ||
import Mathlib.Data.Finset.Basic | ||
|
||
/-! | ||
# Update a function on a set of values | ||
This file defines `Function.updateFinset`, the operation that updates a function on a | ||
(finite) set of values. | ||
This is a very specific function used for `MeasureTheory.marginal`, and possibly not that useful | ||
for other purposes. | ||
-/ | ||
variable {ι : Sort _} {π : ι → Sort _} {x : ∀ i, π i} [DecidableEq ι] | ||
|
||
namespace Function | ||
|
||
/-- `updateFinset x s y` is the vector `x` with the coordinates in `s` changed to the values of `y`. | ||
-/ | ||
def updateFinset (x : ∀ i, π i) (s : Finset ι) (y : ∀ i : ↥s, π i) (i : ι) : π i := | ||
if hi : i ∈ s then y ⟨i, hi⟩ else x i | ||
|
||
open Finset Equiv | ||
|
||
@[simp] theorem updateFinset_empty {y} : updateFinset x ∅ y = x := | ||
rfl | ||
|
||
theorem updateFinset_singleton {i y} : | ||
updateFinset x {i} y = Function.update x i (y ⟨i, mem_singleton_self i⟩) := by | ||
congr with j | ||
by_cases hj : j = i | ||
· cases hj | ||
simp only [dif_pos, Finset.mem_singleton, update_same, updateFinset] | ||
· simp [hj, updateFinset] | ||
|
||
theorem update_eq_updateFinset {i y} : | ||
Function.update x i y = updateFinset x {i} (uniqueElim y) := by | ||
congr with j | ||
by_cases hj : j = i | ||
· cases hj | ||
simp only [dif_pos, Finset.mem_singleton, update_same, updateFinset] | ||
exact uniqueElim_default (α := fun j : ({i} : Finset ι) => π j) y | ||
· simp [hj, updateFinset] | ||
|
||
theorem updateFinset_updateFinset {s t : Finset ι} (hst : Disjoint s t) | ||
{y : ∀ i : ↥s, π i} {z : ∀ i : ↥t, π i} : | ||
updateFinset (updateFinset x s y) t z = | ||
updateFinset x (s ∪ t) (Equiv.piFinsetUnion π hst ⟨y, z⟩) := by | ||
set e := Equiv.Finset.union s t hst | ||
congr with i | ||
by_cases his : i ∈ s <;> by_cases hit : i ∈ t <;> | ||
simp only [updateFinset, his, hit, dif_pos, dif_neg, Finset.mem_union, true_or_iff, | ||
false_or_iff, not_false_iff] | ||
· exfalso; exact Finset.disjoint_left.mp hst his hit | ||
· exact piCongrLeft_sum_inl (fun b : ↥(s ∪ t) => π b) e y z ⟨i, his⟩ |>.symm | ||
· exact piCongrLeft_sum_inr (fun b : ↥(s ∪ t) => π b) e y z ⟨i, hit⟩ |>.symm | ||
|
||
end Function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters