Skip to content

[Merged by Bors] - chore: remove CoeFun instances where FunLike is available#17870

Closed
Vierkantor wants to merge 3 commits intomasterfrom
remove-CoeFun-duplicates
Closed

[Merged by Bors] - chore: remove CoeFun instances where FunLike is available#17870
Vierkantor wants to merge 3 commits intomasterfrom
remove-CoeFun-duplicates

Conversation

@Vierkantor
Copy link
Copy Markdown
Contributor

@Vierkantor Vierkantor commented Oct 17, 2024

During the port we found that FunLike is robust enough not to need an extra CoeFun shortcut. Let's see if that rule can be consistently applied to the whole of the library.

There is still duplication between FunLike and CoeFun for Grp, Mon, CommGrp and CommMon, which will need a more thorough fix. See also #17866.

There is also a shortcut instance that we need for speed reasons: SemilinearIsometry.instCoeFun. I don't know why this is so performance-sensitive but the benchmarks tell us that it is.

See also #17871 for removing porting notes and comments where this change happened earlier on.


Open in Gitpod

@Vierkantor Vierkantor added tech debt Tracking cross-cutting technical debt, see e.g. the "Technical debt counters" stream on zulip awaiting-bench This PR needs to be benchmarked before merging labels Oct 17, 2024
@Vierkantor
Copy link
Copy Markdown
Contributor Author

!bench

@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 17, 2024

PR summary abd00d72e4

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

- instCoeFun
- instance : CoeFun (Π₀ i, β i) fun _ => ∀ i, β i
- instance {μ : YoungDiagram} : CoeFun (SemistandardYoungTableau μ) fun _ ↦ ℕ → ℕ → ℕ

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.

Vierkantor added a commit that referenced this pull request Oct 17, 2024
We prefer `FunLike` over `CoeFun` if possible, so we don't care that we made that change during the port.

See also #17870 for applying the change that was porting noted consistently across the entirety of Mathlib.
Copy link
Copy Markdown
Member

@jcommelin jcommelin left a comment

Choose a reason for hiding this comment

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

Thanks 🎉

If CI passes, please remove the label awaiting-CI and merge this yourself, by adding a comment bors r+.

bors d+

@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Oct 17, 2024

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

@jcommelin jcommelin added the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Oct 17, 2024
@ghost ghost added the delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). label Oct 17, 2024
mathlib-bors bot pushed a commit that referenced this pull request Oct 17, 2024
We prefer `FunLike` over `CoeFun` if possible, so we don't care that we made that change during the port.

See also #17870 for applying the change that was porting noted consistently across the entirety of Mathlib.
@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit 36f0ed3.
The entire run failed.
Found no significant differences.

Vierkantor added a commit that referenced this pull request Oct 17, 2024
These were already unused on the master branch but became exposed to the linter after #17870 changed some `CoeFun` instances.
@Vierkantor
Copy link
Copy Markdown
Contributor Author

!bench

@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 Oct 17, 2024
mathlib-bors bot pushed a commit that referenced this pull request Oct 17, 2024
These were already unused on the master branch but became exposed to the linter after #17870 changed some `CoeFun` instances.
@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit f28c9f5.
There were significant changes against commit dc52856:

  Benchmark                                     Metric         Change
  ===================================================================
- ~Mathlib.Analysis.InnerProductSpace.Adjoint   instructions     8.4%

@Vierkantor
Copy link
Copy Markdown
Contributor Author

Not sure why that one file is so much slower: I didn't touch anything involving LinearMap or ContinuousLinearMap which seem to be the only types of maps that I can find in that file. If there's no simple explanation, I'm willing to eat the slowdown in exchange for cleaner code.

@Vierkantor
Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit ae8a2bd.
There were significant changes against commit dc52856:

  Benchmark                                     Metric         Change
  ===================================================================
- ~Mathlib.Analysis.InnerProductSpace.Adjoint   instructions     8.6%

@Vierkantor
Copy link
Copy Markdown
Contributor Author

Hmm. Binary search to see which subset of lemmas breaks the bench?

mathlib-bors bot pushed a commit that referenced this pull request Oct 18, 2024
During the port we found that `FunLike` is robust enough not to need an extra `CoeFun` shortcut. Let's see if that rule can be consistently applied to the whole of the library.

There is still duplication between `FunLike` and `CoeFun` for `Grp`, `Mon`, `CommGrp` and `CommMon`, which will need a more thorough fix. See also #17866.

This is the second half of #17870, and doesn't affect the benchmarks.
During the port we found that `FunLike` is robust enough not to need an extra `CoeFun` shortcut. Let's see if that rule can be consistently applied to the whole of the library.

There is still duplication between `FunLike` and `CoeFun` for `Grp`, `Mon`, `CommGrp` and `CommMon`, which will need a more thorough fix. See also #17866.

Compared to previous tests, this only preserves the `Finsupp` and `DFinsupp` instances; my guess is that they are the important shortcut instances preventing slowdowns.
@Vierkantor Vierkantor force-pushed the remove-CoeFun-duplicates branch from ae8a2bd to abd00d7 Compare October 21, 2024 14:48
@Vierkantor Vierkantor removed the awaiting-bench This PR needs to be benchmarked before merging label Oct 21, 2024
@Vierkantor
Copy link
Copy Markdown
Contributor Author

See #17921 for the benchmarks proving that SemilinearIsometry.instCoeFun is to blame for the slowdown.

@Vierkantor Vierkantor requested a review from jcommelin October 21, 2024 14:51
@jcommelin
Copy link
Copy Markdown
Member

!bench

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit abd00d7.
There were no significant changes against commit ff1b886.

@jcommelin
Copy link
Copy Markdown
Member

Thanks 🎉

bors merge

@github-actions github-actions bot added the ready-to-merge This PR has been sent to bors. label Oct 22, 2024
mathlib-bors bot pushed a commit that referenced this pull request Oct 22, 2024
During the port we found that `FunLike` is robust enough not to need an extra `CoeFun` shortcut. Let's see if that rule can be consistently applied to the whole of the library.

There is still duplication between `FunLike` and `CoeFun` for `Grp`, `Mon`, `CommGrp` and `CommMon`, which will need a more thorough fix. See also #17866.

There is also a shortcut instance that we need for speed reasons: `SemilinearIsometry.instCoeFun`. I don't know why this is so performance-sensitive but the benchmarks tell us that it is.

See also #17871 for removing porting notes and comments where this change happened earlier on.
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Oct 22, 2024

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title chore: remove CoeFun instances where FunLike is available [Merged by Bors] - chore: remove CoeFun instances where FunLike is available Oct 22, 2024
@mathlib-bors mathlib-bors bot closed this Oct 22, 2024
@mathlib-bors mathlib-bors bot deleted the remove-CoeFun-duplicates branch October 22, 2024 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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. tech debt Tracking cross-cutting technical debt, see e.g. the "Technical debt counters" stream on zulip

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants