feat: define updateFinset which updates a finite number components of a vector#7341
feat: define updateFinset which updates a finite number components of a vector#7341
updateFinset which updates a finite number components of a vector#7341Conversation
Mathlib/Data/Finset/Update.lean
Outdated
| We should generalize `updateFinset` to `SetLike` instead of restricting to `Finset`. | ||
| However, at the moment `Finset` is not `SetLike`, so we cannot do this yet. | ||
| -/ | ||
| def updateFinset (x : ∀ i, π i) (s : Finset ι) [DecidablePred (· ∈ s)] |
There was a problem hiding this comment.
I assume there's a reason you didn't just use [DecidableEq _] here? If so, can you add it to the docstring?
There was a problem hiding this comment.
DecidablePred generalizes better to other SetLike things. But I was inconsistently using DecidableEq in the rest of the file, so I just use that everywhere.
| /-- `updateFinset x s y` is the vector `x` with the coordinates in `s` changed to the values of `y`. | ||
|
|
||
| We should generalize `updateFinset` to `SetLike` instead of restricting to `Finset`. | ||
| However, at the moment `Finset` is not `SetLike`, so we cannot do this yet. | ||
| -/ | ||
| def updateFinset (x : ∀ i, π i) (s : Finset ι) (y : ∀ i : ↥s, π i) (i : ι) : π i := | ||
| if hi : i ∈ s then y ⟨i, hi⟩ else x i |
There was a problem hiding this comment.
It's not clear to me what the benefit of defining this on Finset is:
| /-- `updateFinset x s y` is the vector `x` with the coordinates in `s` changed to the values of `y`. | |
| We should generalize `updateFinset` to `SetLike` instead of restricting to `Finset`. | |
| However, at the moment `Finset` is not `SetLike`, so we cannot do this yet. | |
| -/ | |
| def updateFinset (x : ∀ i, π i) (s : Finset ι) (y : ∀ i : ↥s, π i) (i : ι) : π i := | |
| if hi : i ∈ s then y ⟨i, hi⟩ else x i | |
| /-- `updateSet x s y` is the vector `x` with the coordinates in `s` changed to the values of `y`. | |
| This is `Set.piecewise` where the left argument `x` is dependently-typed | |
| -/ | |
| def updateSet (x : ∀ i, π i) (s : Set ι) [DecidablePred (· ∈ s)] (y : ∀ i : ↥s, π i) (i : ι) : π i := | |
| if hi : i ∈ s then y ⟨i, hi⟩ else x i |
There was a problem hiding this comment.
I definitely want to apply this to Finset. I need to integrate over a Pi-type over this Finset at some point.
Your suggestion means that I need to coerce the Finset to Set. It also means that all lemmas I want are inconveniently stated in terms of Set-operations instead of Finset-operations. So I need to add a bunch of rewrites commuting coerions with operations. This makes it less convenient to work with.
The proper way to do this is to define this for all SetLike objects, but this is impossible at the moment, as the docstring describes.
There was a problem hiding this comment.
So I need to add a bunch of rewrites commuting coercions with operations.
Shouldn't norm_cast handle this?
The proper way to do this is to define this for all
SetLikeobjects
I'd argue this is much worse, because now you need separate lemmas about updateSet _ (s ∩ t) for Set and Finset, and another seven or so for updateSet _ (s ⊓ t) for Submonoid, Submodule, .... Then you have to repeat this for bot and iInf and sInf.
If you do it for Set you only need to write these once, because simp turns everything into the set operations for you.
There was a problem hiding this comment.
I gave this an honest try to use updateSet in our work. It is in d0aa7ef but it a lot less nice.
In the theorem marginal_union I do the following calculation (s and t are Finsets):
(∫⋯∫_s ∪ t, f ∂μ) x =
∫⁻ (y : (i : ↥(s ∪ t)) → π i), f (updateFinset x (s ∪ t) y) ∂.pi fun i' : ↥(s ∪ t) ↦ μ i'
This is true by definition when using updateFinset.
When using updateSet, I have to be very careful to use Finset-unions. If I use Set-unions, then there are multiple places where the expression becomes type-incorrect (or it becomes nontrivial to prove that it is equal to the Finset-union case).
The rest of the calculation mostly goes through the same, if I'm very careful by explicitly stating where the coercions should be added. Some lemmas I still need to formulate for Finset specifically, and sometimes I can use Set analogues.
I strongly prefer to keep updateFinset. If you don't like this operation, I'd be happy to call it marginalAux or something and move it to the Marginal file, to be PR'd later. (marginalAux was actually the original name, until I thought that this operation might be more generally useful.)
EDIT: "just use norm_cast" isn't very helpful, since updateSet is a dependently typed function: the type of argument y depends on the set s, so rewriting the set s to an equal set s' is already quite painful.
* Also fix the statement of some lemmas of an earlier PR. * From the Sobolev project * There are more that depend on #7341 Co-authored-by: Heather Macbeth 25316162+hrmacbeth@users.noreply.github.com
|
Note: I have pushed an update to the lean toolchain because this PR was on a buggy version of the toolchain. WARNING: checking out old commits of this PR using v4.2.0-rc2 or v4.2.0-rc3 can cause |
|
🚀 Pull request has been placed on the maintainer queue by jcommelin. |
…of a vector (#7341) * from the Sobolev project (formerly: marginal project) --------- Co-authored-by: Mario Carneiro <di.gama@gmail.com>
Uh oh!
There was an error while loading. Please reload this page.