Skip to content

[Merged by Bors] - chore: mark toSubfield, toSubmodule, toSubring as reducible - #36395

Closed
JovanGerb wants to merge 9 commits into
leanprover-community:masterfrom
JovanGerb:Jovan-substructure-projections
Closed

JovanGerb wants to merge 9 commits into
leanprover-community:masterfrom
JovanGerb:Jovan-substructure-projections

Conversation

@JovanGerb

Copy link
Copy Markdown
Contributor

This PR marks IntermediateField.toSubfield, Subalgebra.toSubring and Subalgebra.toSubmodule as implicit_reducible, because these are all used to construct instances on substructures, and hence need to be reducible when unifying type classes.

This allows removing at least 100 backwards compatability flags (possibly more because I haven't checked these exhaustively)


Open in Gitpod

@github-actions

github-actions Bot commented Mar 9, 2026 •

Copy link
Copy Markdown

PR summary 58f63c64f7

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

- instance [IsDomain R] [Module.Finite ℤ R] : HasFiniteQuotients R

You can run this locally as follows
## summary with just the declaration names:
./scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh contains some details about this script.


Increase in tech debt: (relative, absolute) = (1.74, 0.07)
Current number Change Type
25 2 disabled simpNF lints
9408 -97 backward.isDefEq

Current commit ed5db5469a
Reference commit 58f63c64f7

You can run this locally as

./scripts/reporting/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).

@riccardobrasca

Copy link
Copy Markdown
Member

!radar

@leanprover-radar

leanprover-radar commented Mar 9, 2026 •

Copy link
Copy Markdown

Benchmark results for a243064 against c287e21 are in! @riccardobrasca

  • 🟥 build//instructions: +26.5G (+0.01%)

Medium changes (1🟥)

  • 🟥 build/module/Mathlib.FieldTheory.Relrank//instructions: +5.6G (+7.16%)

Small changes (9🟥)

  • 🟥 build/module/Mathlib.FieldTheory.AlgebraicClosure//instructions: +929.8M (+4.08%)
  • 🟥 build/module/Mathlib.FieldTheory.Galois.Infinite//instructions: +809.8M (+1.74%)
  • 🟥 build/module/Mathlib.FieldTheory.Galois.Profinite//instructions: +952.1M (+1.22%)
  • 🟥 build/module/Mathlib.FieldTheory.IntermediateField.Adjoin.Algebra//instructions: +4.4G (+11.11%)
  • 🟥 build/module/Mathlib.FieldTheory.IntermediateField.Adjoin.Basic//instructions: +2.5G (+2.42%)
  • 🟥 build/module/Mathlib.FieldTheory.IntermediateField.Algebraic//instructions: +1.3G (+2.60%)
  • 🟥 build/module/Mathlib.FieldTheory.RatFunc.Luroth//instructions: +1.3G (+0.96%)
  • 🟥 build/module/Mathlib.FieldTheory.SeparableClosure//instructions: +1.9G (+2.31%)
  • 🟥 build/module/Mathlib.NumberTheory.NumberField.Discriminant.Different//instructions: +1.1G (+1.37%)

@riccardobrasca

Copy link
Copy Markdown
Member

Not sure I understand all the details, but LGTM, and the bench looks reasonable.

@eric-wieser

Copy link
Copy Markdown
Member

Shouldn't these be actually reducible, to match toBaseStruct functions created with extends ToBaseStruct?

@JovanGerb

Copy link
Copy Markdown
Contributor Author

That seems reasonable

@eric-wieser

Copy link
Copy Markdown
Member

I think that was what @kim-em decided to do on a previous very similar PR. Perhaps we should find and link that before reiewing further.

@JovanGerb

Copy link
Copy Markdown
Contributor Author

I think #35761 is the PR you are talking about. It indeed seems to be doint a similar thing as I'm doing here, and there it was decided to make these projections reducible.

I've now made two of the definitions reducible. I've left Subalgebra.toSubmodule as implicit_reducible, because it has more structure than just a projection (it is an order embedding).

@JovanGerb JovanGerb changed the title chore: mark toSubfield, toSubmodule, toSubring with implicit_reducible chore: mark toSubfield, toSubmodule, toSubring as reducible Mar 10, 2026
@JovanGerb

Copy link
Copy Markdown
Contributor Author

!bench

Let's see how the performance is with these as reducible.

@leanprover-radar

leanprover-radar commented Mar 10, 2026 •

Copy link
Copy Markdown

Benchmark results for 22ac88b against c287e21 are in. There are no significant changes. @JovanGerb

  • 🟥 build//instructions: +31.5G (+0.02%)

Medium changes (1🟥)

  • 🟥 build/module/Mathlib.FieldTheory.Relrank//instructions: +5.4G (+6.87%)

Small changes (1✅, 8🟥)

  • 🟥 build/module/Mathlib.FieldTheory.AlgebraicClosure//instructions: +898.4M (+3.94%)
  • 🟥 build/module/Mathlib.FieldTheory.Galois.Infinite//instructions: +897.3M (+1.93%)
  • 🟥 build/module/Mathlib.FieldTheory.Galois.Profinite//instructions: +1.0G (+1.30%)
  • 🟥 build/module/Mathlib.FieldTheory.IntermediateField.Adjoin.Algebra//instructions: +4.3G (+10.77%)
  • 🟥 build/module/Mathlib.FieldTheory.IntermediateField.Adjoin.Basic//instructions: +2.5G (+2.38%)
  • 🟥 build/module/Mathlib.FieldTheory.IntermediateField.Algebraic//instructions: +1.2G (+2.54%)
  • 🟥 build/module/Mathlib.FieldTheory.SeparableClosure//instructions: +1.8G (+2.12%)
  • 🟥 build/module/Mathlib.NumberTheory.NumberField.Discriminant.Different//instructions: +999.5M (+1.28%)
  • ✅ build/module/Mathlib.Topology.Sheaves.Over//instructions: -573.6M (-6.03%)

@kim-em

kim-em commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

bors merge

mathlib-bors Bot pushed a commit that referenced this pull request Mar 12, 2026
…36395)

This PR marks `IntermediateField.toSubfield`, `Subalgebra.toSubring` and `Subalgebra.toSubmodule` as `implicit_reducible`, because these are all used to construct instances on substructures, and hence need to be reducible when unifying type classes.

This allows removing at least 100 backwards compatability flags (possibly more because I haven't checked these exhaustively)
@mathlib-triage mathlib-triage Bot added the ready-to-merge This PR has been sent to bors. label Mar 12, 2026
@mathlib-bors

mathlib-bors Bot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Build failed:

@JovanGerb

Copy link
Copy Markdown
Contributor Author

bors retry

mathlib-bors Bot pushed a commit that referenced this pull request Mar 12, 2026
…36395)

This PR marks `IntermediateField.toSubfield`, `Subalgebra.toSubring` and `Subalgebra.toSubmodule` as `implicit_reducible`, because these are all used to construct instances on substructures, and hence need to be reducible when unifying type classes.

This allows removing at least 100 backwards compatability flags (possibly more because I haven't checked these exhaustively)
@mathlib-bors

mathlib-bors Bot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Build failed:

@JovanGerb

JovanGerb commented Mar 12, 2026 •

Copy link
Copy Markdown
Contributor Author

I don't understand why this was not an issue a few days ago, but after merging master, I hit a couple of "(deterministic) timeout at typeclass" errors. These are caused by the fact that toSubfield is now reducible, which causes some unifications to now succeed, and hence certain instances can now apply, which causes type class search to do more work.

I could improve the situation a bit by removing one globally unused instance (which I separated in #36535). But for the remaining 2 timeouts there is no clear fix. So as a last resort, I've just left a noling simpNF.

@kim-em, do you think this is an acceptable solution?

@Vierkantor Vierkantor added t-algebra Algebra (groups, rings, fields, etc) and removed ready-to-merge This PR has been sent to bors. labels Mar 17, 2026
@Vierkantor

Copy link
Copy Markdown
Contributor

Note that #36097 does a lot of the same changes, and is experiencing similar build issues.

@Vierkantor

Copy link
Copy Markdown
Contributor

bors d+

@mathlib-bors

mathlib-bors Bot commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

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

@mathlib-triage mathlib-triage Bot added the delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). label Mar 17, 2026
@JovanGerb

Copy link
Copy Markdown
Contributor Author

bors r+

mathlib-bors Bot pushed a commit that referenced this pull request Mar 17, 2026
…36395)

This PR marks `IntermediateField.toSubfield`, `Subalgebra.toSubring` and `Subalgebra.toSubmodule` as `implicit_reducible`, because these are all used to construct instances on substructures, and hence need to be reducible when unifying type classes.

This allows removing at least 100 backwards compatability flags (possibly more because I haven't checked these exhaustively)
@mathlib-bors

mathlib-bors Bot commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Build failed:

@JovanGerb

Copy link
Copy Markdown
Contributor Author

looks like a spurious grind failure :(

bors retry

mathlib-bors Bot pushed a commit that referenced this pull request Mar 17, 2026
…36395)

This PR marks `IntermediateField.toSubfield`, `Subalgebra.toSubring` and `Subalgebra.toSubmodule` as `implicit_reducible`, because these are all used to construct instances on substructures, and hence need to be reducible when unifying type classes.

This allows removing at least 100 backwards compatability flags (possibly more because I haven't checked these exhaustively)
@mathlib-bors

mathlib-bors Bot commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors Bot changed the title chore: mark toSubfield, toSubmodule, toSubring as reducible [Merged by Bors] - chore: mark toSubfield, toSubmodule, toSubring as reducible Mar 18, 2026
@mathlib-bors mathlib-bors Bot closed this Mar 18, 2026
mathlib-bors Bot pushed a commit that referenced this pull request Mar 18, 2026
…eQuotients` instance (#36535)

This instance was removed in #36395 for performance reasons. This PR restores the instance in a form that is more performant.
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). t-algebra Algebra (groups, rings, fields, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants