Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - feat(Data/Finsupp): make toMultiset and antidiagonal computable #6331

Closed
wants to merge 9 commits into from

Conversation

eric-wieser
Copy link
Member

@eric-wieser eric-wieser commented Aug 3, 2023

In Lean 3, the computability of Finsupp.toMultiset was poisoned by the AddMonoid (α →₀ ℕ) instance, even though this was not used in computation. This is no longer the case in Lean 4, so we can make this computable by adding a DecidableEq α argument.

We loosely follow the pattern used with DFinsupp, where we split the declaration in two, as only one direction needs DecidableEq α. As a result, Finsupp.toMultiset is now only an AddMonoidHom, though Multiset.toFinset remains an equiv.

We're missing some of the formatting infrastructure for this to be pretty, but this now works:

#eval ((Finsupp.mk Finset.univ ![1, 2, 3] sorry).antidiagonal).image
  fun x : _ × _ => (x.1.toFun, x.2.toFun)

Open in Gitpod

In Lean 3, the comptubility of `Finsupp.toMultiset` was poisoned by the `AddMonoid (α →₀ ℕ)` instance, even though this was not used in computation.
This is no longer the case in Lean 4, so we can make this computable by adding a `DecidableEq α` argument.
@eric-wieser eric-wieser added awaiting-review The author would like community review of the PR awaiting-CI t-combinatorics Combinatorics labels Aug 3, 2023
@eric-wieser eric-wieser changed the title feat(Data/Finsupp): make toMultiset and Antidiagonal computable feat(Data/Finsupp): make toMultiset and antidiagonal computable Aug 3, 2023
Copy link
Collaborator

@ericrbg ericrbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, I like the way to avoid a naming clash whilst still having short names

@ericrbg
Copy link
Collaborator

ericrbg commented Aug 4, 2023

maintainer merge

@github-actions
Copy link

github-actions bot commented Aug 4, 2023

🚀 Pull request has been placed on the maintainer queue by ericrbg.

@Vierkantor Vierkantor self-assigned this Aug 7, 2023
@@ -1473,6 +1474,7 @@ theorem coeff_zero_one : coeff R 0 (1 : PowerSeries R) = 1 :=
theorem coeff_mul (n : ℕ) (φ ψ : PowerSeries R) :
coeff R n (φ * ψ) = ∑ p in Finset.Nat.antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ := by
symm
erw [MvPowerSeries.coeff_mul]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain (in a comment?) why a normal rw doesn't work here?

Copy link
Contributor

@Vierkantor Vierkantor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

bors d+

@bors
Copy link

bors bot commented Aug 7, 2023

✌️ eric-wieser can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added delegated and removed awaiting-review The author would like community review of the PR labels Aug 7, 2023
@@ -1473,6 +1474,7 @@ theorem coeff_zero_one : coeff R 0 (1 : PowerSeries R) = 1 :=
theorem coeff_mul (n : ℕ) (φ ψ : PowerSeries R) :
coeff R n (φ * ψ) = ∑ p in Finset.Nat.antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ := by
symm
erw [MvPowerSeries.coeff_mul] -- `rw` can't see that `PowerSeries = MvPowerSeries Unit`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not to be a nitpicker but in this case shouldn't we just have a lemma to this effect and normal rw it? [or does that cause motive issues]

the defeq abuse before wasn't great either though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lemma is the place where we're building that lemma! The problem would go away if we made PowerSeries reducible, or introduced a function to convert between it and MvPowerSeries

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make a follow-up PR to golf this proof

@eric-wieser
Copy link
Member Author

bors merge

@github-actions github-actions bot added the ready-to-merge This PR has been sent to bors. label Aug 7, 2023
bors bot pushed a commit that referenced this pull request Aug 7, 2023
In Lean 3, the computability of `Finsupp.toMultiset` was poisoned by the `AddMonoid (α →₀ ℕ)` instance, even though this was not used in computation. This is no longer the case in Lean 4, so we can make this computable by adding a `DecidableEq α` argument.

We loosely follow the pattern used with `DFinsupp`, where we split the declaration in two, as only one direction needs `DecidableEq α`. As a result, `Finsupp.toMultiset` is now only an `AddMonoidHom`, though `Multiset.toFinset` remains an equiv.


We're missing some of the formatting infrastructure for this to be pretty, but this now works:
```lean
#eval ((Finsupp.mk Finset.univ ![1, 2, 3] sorry).antidiagonal).image
  fun x : _ × _ => (x.1.toFun, x.2.toFun)
```
@bors
Copy link

bors bot commented Aug 7, 2023

Pull request successfully merged into master.

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot changed the title feat(Data/Finsupp): make toMultiset and antidiagonal computable [Merged by Bors] - feat(Data/Finsupp): make toMultiset and antidiagonal computable Aug 7, 2023
@bors bors bot closed this Aug 7, 2023
@bors bors bot deleted the eric-wieser/finsupp.toMultiset-computable branch August 7, 2023 13:56
semorrison pushed a commit that referenced this pull request Aug 14, 2023
In Lean 3, the computability of `Finsupp.toMultiset` was poisoned by the `AddMonoid (α →₀ ℕ)` instance, even though this was not used in computation. This is no longer the case in Lean 4, so we can make this computable by adding a `DecidableEq α` argument.

We loosely follow the pattern used with `DFinsupp`, where we split the declaration in two, as only one direction needs `DecidableEq α`. As a result, `Finsupp.toMultiset` is now only an `AddMonoidHom`, though `Multiset.toFinset` remains an equiv.


We're missing some of the formatting infrastructure for this to be pretty, but this now works:
```lean
#eval ((Finsupp.mk Finset.univ ![1, 2, 3] sorry).antidiagonal).image
  fun x : _ × _ => (x.1.toFun, x.2.toFun)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
delegated ready-to-merge This PR has been sent to bors. t-combinatorics Combinatorics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants