Skip to content

feat(Algebra/BigOperators/Fin): Add finSigmaFinEquiv - #19013

Closed
quangvdao wants to merge 8 commits into
masterfrom
finSigmaFinEquiv
Closed

quangvdao wants to merge 8 commits into
masterfrom
finSigmaFinEquiv

Conversation

@quangvdao

Copy link
Copy Markdown
Collaborator

This PR adds finSigmaFinEquiv which is the equivalence (i : Fin m) × Fin (n i) ≃ Fin (∑ i, n i). This is the dependent version of finProdFinEquiv.

CI should be passing, but there are two things I'd like feedback on:

  1. When defining the mappings, I have to consider m = 0 separately. Is there a more uniform definition?
  2. I'm proving this as a step toward defining Fin.join, which is the analogue of List.join. I can now technically define Fin.join as:
variable {a : Fin n → ℕ} {α : (i : Fin n) → (j : Fin (a i)) → Sort*}

def join (v : (i : Fin n) → (j : Fin (a i)) → α i j) (k : Fin (∑ i, a i)) :
    α (finSigmaFinEquiv.invFun k).1 (finSigmaFinEquiv.invFun k).2 :=
  v (finSigmaFinEquiv.invFun k).1 (finSigmaFinEquiv.invFun k).2

but this looks horrible. This highly motivates refactoring invFun as two new definitions:

def func1 {n : ℕ} (a : Fin n → ℕ) (k : Fin (∑ i, a i)) : Fin n := sorry

def func2 {n : ℕ} (a : Fin n → ℕ) (k : Fin (∑ i, a i)) : Fin (a (func1 a k)) := sorry

I'm not sure what to call these functions. The analogues in the non-dependent case are divNat and modNat.


Open in Gitpod

@github-actions

github-actions Bot commented Nov 14, 2024 •

Copy link
Copy Markdown

PR summary 9a02067e37

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ divSum
+ divSum?
+ divSum?_is_some_iff_lt_sum
+ finSigmaFinEquiv
+ finSigmaFinEquiv_apply
+ finSigmaFinEquiv_pair
+ modSum
+ sum_le_of_divSum?_eq_some

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 script/declarations_diff.sh contains some details about this script.


Changes to technical debt
Current number Change Type
5120 -2 porting notes

Current commit 9a02067e37
Reference commit 8d28d21b27

You can run this locally as

./scripts/technical-debt-metrics.sh pr_summary

@github-actions github-actions Bot added the t-algebra Algebra (groups, rings, fields, etc) label Nov 14, 2024
@quangvdao quangvdao added the help-wanted The author needs attention to resolve issues label Nov 14, 2024

@YaelDillies YaelDillies left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with you that m = 0 has to be treated separately

Comment thread Mathlib/Algebra/BigOperators/Fin.lean Resolved
Comment thread Mathlib/Algebra/BigOperators/Fin.lean Resolved
Comment thread Mathlib/Algebra/BigOperators/Fin.lean Resolved
@YaelDillies YaelDillies added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Nov 14, 2024
@quangvdao

Copy link
Copy Markdown
Collaborator Author

@YaelDillies addressed your comments.

I still think there is a uniform definition (this is what divNat and modNat does), but for now it would be great if the current version makes it into Mathlib.

@quangvdao quangvdao removed help-wanted The author needs attention to resolve issues awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. labels Nov 14, 2024
@eric-wieser

Copy link
Copy Markdown
Member

I agree with you that m = 0 has to be treated separately

I disagree, see the commit I pushed. There is no need to deal with a case separately that is impossible.

Comment thread Mathlib/Algebra/BigOperators/Fin.lean Resolved
@quangvdao

Copy link
Copy Markdown
Collaborator Author

I have refactored finSigmaFinEquiv.invFun into two separate functions:

def Fin.divSum {m : ℕ} {n : Fin m → ℕ} (k : Fin (∑ j, n j)) : Fin m := sorry

def Fin.modSum {m : ℕ} {n : Fin m → ℕ} (k : Fin (∑ j, n j)) : Fin (n (divSum k)) := sorry

The naming takes inspiration from Fin.divNat and Fin.modNat used in finProdFinEquiv.

Comment thread Mathlib/Algebra/BigOperators/Fin.lean Outdated
This is defined en-route to `Fin.divSum`, which is the dependent version of `Fin.divNat`.
-/
def divSum? {m : ℕ} (n : Fin m → ℕ) (k : ℕ) : Option (Fin m) :=
find (fun i => k < ∑ j, n (castLE i.isLt j))

@eric-wieser eric-wieser Nov 15, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks wrong to me; isLt is a proof of <, but castLE is about ≤. Can you make the type j explicit here to make it clearer what is going on?

@quangvdao quangvdao Nov 15, 2024 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Since i.isLt : i.val < n is definitionally equal to i.val.succ <= n, the sum is over j : Fin i.val.succ.

This is defined en-route to `Fin.divSum`, which is the dependent version of `Fin.divNat`.
-/
def divSum? {m : ℕ} (n : Fin m → ℕ) (k : ℕ) : Option (Fin m) :=
find (fun i => k < ∑ j : Fin i.val.succ, n (castLE i.isLt j))

@eric-wieser eric-wieser Nov 16, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Possibly better as

Suggested change
find (fun i => k < ∑ j : Fin i.val.succ, n (castLE i.isLt j))
find (fun i => k < ∑ j ≤ i, n j)

which avoids the .succ and casting

@quangvdao quangvdao Nov 16, 2024 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this is certainly possible and looks nicer. I'd probably want to propagate this change to finPiFinEquiv as well (which a quick search tells me isn't used anywhere else). It also means that I'll need to add more lemmas about sum over Finset.Iic.

If all of this sounds good to you, then I'll make the changes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's check @YaelDillies agrees too

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, makes sense to me

@quangvdao quangvdao added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Nov 18, 2024
@leanprover-community-bot-assistant leanprover-community-bot-assistant added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Mar 19, 2025
@joneugster

Copy link
Copy Markdown
Member

Mathlib has moved to PRs from forks. This PR is still from a branch of the main repository and will soon be closed! Please migrate the content to a fork and reopen a PR from there if you wish to do so. See Zulip topic for more instructions. Thank you for contributing to mathlib!

@joneugster joneugster added the will-close-soon Unless something changes, we will close this PR soon label Sep 19, 2026
@joneugster joneugster closed this Oct 24, 2026
@YaelDillies
YaelDillies deleted the finSigmaFinEquiv branch October 24, 2026 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) t-algebra Algebra (groups, rings, fields, etc) will-close-soon Unless something changes, we will close this PR soon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants