Skip to content

[Merged by Bors] - perf: speed up Finset.toLeft and Finset.toRight#23079

Closed
eric-wieser wants to merge 4 commits intomasterfrom
eric-wieser/bind-split
Closed

[Merged by Bors] - perf: speed up Finset.toLeft and Finset.toRight#23079
eric-wieser wants to merge 4 commits intomasterfrom
eric-wieser/bind-split

Conversation

@eric-wieser
Copy link
Copy Markdown
Member

@eric-wieser eric-wieser commented Mar 19, 2025

This is about 10% faster than master, but also avoids stackoverflows:

#eval ((Finset.Icc 0 100000).map (.inl (β := ℕ))).toLeft.card

would previously fail.

aesop is somehow capturing an unused local variable here, but clear sets it straight.

As a bonus, this reduces the imports needed for this file.


This is a more minimal version of #23020 that is also twice as fast.

Open in Gitpod

This is about 10% faster, but also avoids stackoverflows:
```
\#eval ((Finset.Icc 0 100000).map (.inl (β := ℕ))).toLeft.card
```
would previously fail.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 19, 2025

PR summary 1d68d2735c

Import changes for modified files

Dependency changes

File Base Count Head Count Change
Mathlib.Data.Finset.Sum 466 427 -39 (-8.37%)
Import changes for all files
Files Import difference
Mathlib.Data.Finset.Sum -39
Mathlib.Data.Finite.Sum Mathlib.Data.Fintype.Sum -38

Declarations diff

No declarations were harmed in the making of this PR! 🐙

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.


No changes to technical debt.

You can run this locally as

./scripts/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions github-actions bot added the t-data Data (lists, quotients, numbers, etc) label Mar 19, 2025
@b-mehta
Copy link
Copy Markdown
Contributor

b-mehta commented Mar 19, 2025

Ha, this is clearly the better definition - Yaël and I were saying how we'd both prefer it if Finset.filterMap existed for this; turns out it does!

def toLeft (s : Finset (α ⊕ β)) : Finset α :=
s.disjiUnion (Sum.elim singleton (fun _ => ∅)) <| by
simp [Set.PairwiseDisjoint, Set.Pairwise, Function.onFun, eq_comm]
s.filterMap (Sum.elim some fun _ => none) (by clear x; aesop)
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.

Is there a tracking issue for aesop pulling in x here?

If aesop changes (fixes) its behaviour, this might error, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

A fix to aesop would make this clear unnecessary, but it wouldn't make it an error

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

@b-mehta b-mehta left a comment

Choose a reason for hiding this comment

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

bors d+

@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Mar 19, 2025

✌️ 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.

@b-mehta b-mehta added the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Mar 19, 2025
@ghost ghost added the delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). label Mar 19, 2025
@eric-wieser eric-wieser added the auto-merge-after-CI Please do not add manually. Requests for a bot to merge automatically once CI is done. label Mar 19, 2025
@ghost
Copy link
Copy Markdown

ghost commented Mar 19, 2025

As this PR is labelled auto-merge-after-CI, we are now sending it to bors:

bors merge

@github-actions github-actions bot removed the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Mar 19, 2025
@ghost ghost added the ready-to-merge This PR has been sent to bors. label Mar 19, 2025
mathlib-bors bot pushed a commit that referenced this pull request Mar 19, 2025
This is about 10% faster than master, but also avoids stackoverflows:
```lean
#eval ((Finset.Icc 0 100000).map (.inl (β := ℕ))).toLeft.card
```
would previously fail.

`aesop` is somehow capturing an unused local variable here, but `clear` sets it straight.

As a bonus, this reduces the imports needed for this file.
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Mar 19, 2025

Build failed:

@ghost
Copy link
Copy Markdown

ghost commented Mar 19, 2025

As this PR is labelled auto-merge-after-CI, we are now sending it to bors:

bors merge

mathlib-bors bot pushed a commit that referenced this pull request Mar 19, 2025
This is about 10% faster than master, but also avoids stackoverflows:
```lean
#eval ((Finset.Icc 0 100000).map (.inl (β := ℕ))).toLeft.card
```
would previously fail.

`aesop` is somehow capturing an unused local variable here, but `clear` sets it straight.

As a bonus, this reduces the imports needed for this file.
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Mar 19, 2025

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title perf: speed up Finset.toLeft and Finset.toRight [Merged by Bors] - perf: speed up Finset.toLeft and Finset.toRight Mar 19, 2025
@mathlib-bors mathlib-bors bot closed this Mar 19, 2025
@mathlib-bors mathlib-bors bot deleted the eric-wieser/bind-split branch March 19, 2025 02:32
tukamilano pushed a commit that referenced this pull request Mar 20, 2025
This is about 10% faster than master, but also avoids stackoverflows:
```lean
#eval ((Finset.Icc 0 100000).map (.inl (β := ℕ))).toLeft.card
```
would previously fail.

`aesop` is somehow capturing an unused local variable here, but `clear` sets it straight.

As a bonus, this reduces the imports needed for this file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merge-after-CI Please do not add manually. Requests for a bot to merge automatically once CI is done. delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). ready-to-merge This PR has been sent to bors. t-data Data (lists, quotients, numbers, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants