[Merged by Bors] - feat(Data/Nat/Choose): Add sum_range_multichoose#33656
[Merged by Bors] - feat(Data/Nat/Choose): Add sum_range_multichoose#33656metakunt wants to merge 3 commits intoleanprover-community:masterfrom
Conversation
PR summary 15f6691e7aImport changes for modified filesNo significant changes to the import graph Import changes for all files
Declarations diff
You can run this locally as follows## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>
## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>The doc-module for No changes to technical debt.You can run this locally as
|
Mathlib/Data/Nat/Choose/Sum.lean
Outdated
| apply Finset.sum_bij' (fun x _ => x + (k - 1)) (fun x _ => x - (k - 1)) | ||
| (by grind) (by grind) (by grind) (by grind) | ||
| intro x | ||
| have _ := choose_symm (k := k - 1) (n := x + (k - 1)) (by lia) | ||
| grind |
There was a problem hiding this comment.
I think you could simplify this slightly by adding the Nat version of Int.Icc_eq_finset_map?
There was a problem hiding this comment.
I'm afraid I don't understand what you mean by that.
There was a problem hiding this comment.
Do you want me to add the Nat version of that https://leanprover-community.github.io/mathlib4_docs/Mathlib/Data/Int/Interval.html#Int.Icc_eq_finset_map
That would then be Nat.Icc_eq_finset_map?
There was a problem hiding this comment.
Yes, exactly! Then you could skip the bij step in this proof
There was a problem hiding this comment.
Sooo, after a few hours I've managed to prove both results in a different way.
open Finset Nat in
lemma Nat.Icc_eq_finset_map (a b : ℕ) : Icc a b =
(Finset.range (b + 1 - a)).map (Nat.castEmbedding.trans <| addLeftEmbedding a) := by
ext x
simp only [mem_Icc, mem_map, mem_range, Function.Embedding.trans_apply, castEmbedding_apply,
cast_id, addLeftEmbedding_apply]
constructor
· intro h
use x - a
grind
· grind
open Nat in
lemma sum_range_multichoose (n k : ℕ) (h : k ≠ 0) :
∑ i ∈ Finset.range (n + 1), k.multichoose i = (n + k).choose k := by
have h1 : k - 1 + 1 = k := by lia
have h2 : n + (k - 1) + 1 = n + k := by lia
simp only [← h1 ▸ h2 ▸ (sum_Icc_choose (n + (k - 1)) (k - 1)), multichoose_eq, range_eq_Ico]
conv_lhs =>
rhs; intro x
rw [← choose_symm (by grind), Nat.sub_right_comm, Nat.add_sub_cancel_right,
add_comm, Nat.add_sub_assoc (by grind)]
convert (sum_map (Ico 0 (n + 1)) (addRightEmbedding (k - 1)) (·.choose (k - 1))).symm using 2
rw [map_add_right_Ico, zero_add, add_right_comm, Ico_add_one_right_eq_Icc]
however I'm completely out of my element in trying to find the most "mathlibby" version of the proof.
It appears that I'm doing something wrong and I don't know what. This new version seems more cumbersome to prove as I can't just grind the hyps away. I have to do a lot of targeted rewrites under conv binders, which by itself is really nasty, just to get the embedding version to apply correctly.
There was a problem hiding this comment.
Thank you @metakunt for taking the time to investigate this!
I've poked a bit and also don't understand how this would be a simplification.
Overall, I don't think it matters that much anyways. The theorem looks good and is in a reasonable place IMO
I suggest
maintainer merge
There was a problem hiding this comment.
I think the Nat.Icc_eq_finset_map lemma is still a good one to have.
There was a problem hiding this comment.
I can add it in the next PR. Could you also suggest a file for that? It doesn't fit in Data/Int/Interval and Data/Nat/Interval does not exist.
There was a problem hiding this comment.
Nevermind, https://leanprover-community.github.io/mathlib4_docs/Mathlib/Order/Interval/Finset/Nat.html exists.
Finding the correct theorems/files in Mathlib is truly a work of art.
There was a problem hiding this comment.
Indeed putting it in a new PR makes sense!
|
🚀 Pull request has been placed on the maintainer queue by joneugster. |
Co-authored-by: Bhavik Mehta <[email protected]>
|
@b-mehta I'd have never come up with that golf. That's seriously impressive. |
I can't speak for Bhavik but I would say:
|
|
bors merge |
|
Pull request successfully merged into master. Build succeeded: |
|
Oliver is correct, and I'd add that when reading |
No description provided.