Skip to content

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

Open
quangvdao wants to merge 8 commits intomasterfrom
finSigmaFinEquiv
Open

feat(Algebra/BigOperators/Fin): Add finSigmaFinEquiv#19013
quangvdao wants to merge 8 commits intomasterfrom
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
Copy link
Copy Markdown

github-actions bot commented Nov 14, 2024

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
Copy link
Copy Markdown
Contributor

@YaelDillies YaelDillies left a comment

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

@YaelDillies YaelDillies added the awaiting-author A reviewer has asked the author a question or requested changes. 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 A reviewer has asked the author a question or requested changes. 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.

@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.

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))
Copy link
Copy Markdown
Member

@eric-wieser eric-wieser Nov 15, 2024

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?

Copy link
Copy Markdown
Collaborator Author

@quangvdao quangvdao Nov 15, 2024

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))
Copy link
Copy Markdown
Member

@eric-wieser eric-wieser Nov 16, 2024

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

Copy link
Copy Markdown
Collaborator Author

@quangvdao quangvdao Nov 16, 2024

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 A reviewer has asked the author a question or requested changes. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author A reviewer has asked the author a question or requested changes. 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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants