feat: add Function.prod and Function.diag#37631
feat: add Function.prod and Function.diag#37631linesthatinterlace wants to merge 13 commits intoleanprover-community:masterfrom
Function.prod and Function.diag#37631Conversation
PR summary a8913b939bImport changes for modified filesNo significant changes to the import graph Import changes for all files
|
Function.prod and Function.diagFunction.prod and Function.diag
SnirBroshi
left a comment
There was a problem hiding this comment.
This looks very cool!
| variable {α β γ δ : Type*} {ι : Sort*} | ||
|
|
||
| /-- The map into a product type built from maps into each component. -/ | ||
| protected def prod : (ι → α) → (ι → β) → ι → α × β := (· ▽' ·) |
There was a problem hiding this comment.
Question:
I don't understand why we need both Pi.prod and Function.prod. Can't we have just the general version (Pi.prod)? (Related: #36902)
If the issue is dot notation, then it's worth mentioning that leanprover/lean4#1629 had some progress recently.
There was a problem hiding this comment.
Yeah, that is exactly the issue I was concerned about (I also thought it was quite nice to have the dependent and non-dependent versions, in the same way that we have Function.dcomp and Function.comp). I also note that if this does get upstreamed (which I am hopeful for), Batteries and Core seem to make extremely minimal use of the "Pi" namespace. So if we do have the general version and we can make the dot notation work, I would rather call the general one Function.prod - it is more consistent with, say LinearMap.prod.
There was a problem hiding this comment.
Oh, that is the other reason it is quite nice to explictly have a non-dependent version - because Function.comp only works for non-dependent functions, I wanted to avoid future frustration of someone trying to use the non-dependent theorems for the dependent case. Arguably though you could just have the definition be Pi.prod and only separate the theorems by namespace, though.
It's weird because we obviously do differentiate Sigma and Prod despite the fact that in theory we could just define Prod as "Sigma in the non-dependent case". And actually as the links you post say, we also do differentiate Function.swap and flip. It feels more consistent to differentiate these.
There was a problem hiding this comment.
In general - why DO we have the Pi namespace?
There was a problem hiding this comment.
I think that the difference between this situation and Sigma vs Prod (or DMatrix vs Matrix, or DFinsupp vs Finsupp) is that they are type constructors.
This means that if we were to define Prod A B := Sigma fun _ : A ↦ B then both Lean and humans would have a hard time type-checking, since it now involves comparing functions.
Here's an example of Lean getting confused because of using DMatrix with constant functions instead of Matrix.
But for Function.{flip,swap,prod,diag} I don't see any benefit in restricting when the function applies to only allow for non-dependent functions. In #36902 I also support getting rid of the duplication and only keeping the dependent version (but it requires a core PR).
I'm not sure I've articulated it well, but these feel like different situations to me.
There was a problem hiding this comment.
That makes sense to me. Do you see a need to keep the Pi namespace in any instance? That I think for me is the thing I don't quite understand the need for.
There was a problem hiding this comment.
The dot-notation will only work once leanprover/lean4#13244 is merged, so if you want to use dot-notation for now I think you have to have the two separate versions and keep the non-dependent version under Function. Then the Pi namespace is a nice place to keep the dependent version.
But I thought that since you defined notation for everything here you don't use dot-notation, no?
| / ▽ | ||
| c - - - ▷ a | ||
| / ▼ | ||
| c - - - ▶ a |
There was a problem hiding this comment.
This change is surely out of scope
There was a problem hiding this comment.
I was mainly changing it because it seemed confusing to introduce the ▽ as notation and leave it in, but I am happy if you think that isn't an issue.
This PR adds
Function.prodandFunction.diagand develops API for them andPi.prod.