Skip to content

[Merged by Bors] - perf(RingTheory/Ideal/Quotient/HasFiniteQuotients): fix the HasFiniteQuotients instance - #36535

Closed
JovanGerb wants to merge 5 commits into
leanprover-community:masterfrom
JovanGerb:Jovan-instOfIsDomainOfFiniteInt
Closed

JovanGerb wants to merge 5 commits into
leanprover-community:masterfrom
JovanGerb:Jovan-instOfIsDomainOfFiniteInt

Conversation

@JovanGerb

@JovanGerb JovanGerb commented Mar 12, 2026 •

Copy link
Copy Markdown
Contributor

This instance was removed in #36395 for performance reasons. This PR restores the instance in a form that is more performant.


Open in Gitpod

@github-actions

github-actions Bot commented Mar 12, 2026 •

Copy link
Copy Markdown

PR summary 316a0377d0

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] [AddGroup.FG 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.


No changes to technical debt.

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

@github-actions github-actions Bot added the t-ring-theory Ring theory label Mar 12, 2026
@JovanGerb

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Mar 12, 2026 •

Copy link
Copy Markdown

Benchmark results for 6d1376f against e06b88a are in. There are no significant changes. @JovanGerb

  • ✅ build//instructions: -17.5G (-0.01%)

Small changes (1✅)

  • ✅ build/module/Mathlib.Util.PrintSorries//instructions: -132.5M (-3.03%) (reduced significance based on absolute threshold)

@JovanGerb JovanGerb changed the title perf(Rintheory/Ideal/Quotient/HasFiniteQuotients): scope instance perf(Rintheory/Ideal/Quotient/HasFiniteQuotients): remove unused instance Mar 15, 2026
@Vierkantor Vierkantor changed the title perf(Rintheory/Ideal/Quotient/HasFiniteQuotients): remove unused instance perf(RingTheory/Ideal/Quotient/HasFiniteQuotients): remove unused instance Mar 17, 2026

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

Please note that the instance still appears in the module doc (instOfIsDomainOfFiniteInt).

Since this file is quite new, I don't think we should delete the instance just because no merged code uses is. @xroblot, could you indicate what you need it for?

exact inferInstanceAs <| Finite (ℤ ⧸ Ideal.span {n})

/-- A domain that is also a finite `ℤ`-module has finite quotients. -/
instance [IsDomain R] [Module.Finite ℤ R] : HasFiniteQuotients R :=

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.

Module.Finite ℤ R is just AddGroup.FG, no? So I agree that this instance is a bit weird and might need to be restated.

@Vierkantor
Vierkantor requested a review from xroblot March 17, 2026 13:26
@xroblot

xroblot commented Mar 17, 2026

Copy link
Copy Markdown
Collaborator

One of the main use cases for the Ring.HasFiniteQuotients class is for rings of integers of number fields, and with this instance it works out of the box:

import Mathlib.RingTheory.Ideal.Quotient.HasFiniteQuotients
import Mathlib.NumberTheory.NumberField.Basic

open NumberField

variable {K : Type*} [Field K] [NumberField K]

#synth Ring.HasFiniteQuotients (𝓞 K)

It is quite possible that this instance is not optimally stated. Also, if it causes a slowdown, it should be refactored or turned into a theorem, and then I can just add Ring.HasFiniteQuotients (𝓞 K) directly as an instance. Still, I thought it was nice that this gets inferred automatically.

@Vierkantor

Copy link
Copy Markdown
Contributor

I suspected that it had to do with rings of integers :) What do you think about the following approach: check if replacing Module.Finite ℤ R with AddGroup.FG R is enough to fix the slowdowns. If that is the case, then this should still work well with rings of integers. If not, then we'll have to specialize this instance to RingOfIntegers.

@xroblot

xroblot commented Mar 17, 2026 •

Copy link
Copy Markdown
Collaborator

Sure. That's a nice solution. Then, we just need to add an instance, say:

instance : AddGroup.FG (𝓞 K) := Finite.iff_addGroup_fg.mp <| IsNoetherian.finite ℤ (𝓞 K)

somewhere in Mathlib.NumberTheory.NumberField.Basic so that Ring.HasFiniteQuotients (𝓞 K) is automatically inferred.

@Vierkantor Vierkantor added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Mar 17, 2026
@JovanGerb

Copy link
Copy Markdown
Contributor Author

(I sent the other PR to bors before I noticed this conversation)

A little test shows that trying to synthesize Module.Finite ℤ F for a Field F has about 220 nodes in the trace, while AddGroup.FG F has about 30 trace nodes. So this does indeed make a big difference.

@JovanGerb

Copy link
Copy Markdown
Contributor Author

Oh and the measured performance improvement is small enough that it may well be noise. I guess that this is too niche of an instance to have a significant global performance effect.

@JovanGerb JovanGerb changed the title perf(RingTheory/Ideal/Quotient/HasFiniteQuotients): remove unused instance perf(RingTheory/Ideal/Quotient/HasFiniteQuotients): fix the HasFiniteQuotients instance Mar 18, 2026
@JovanGerb

Copy link
Copy Markdown
Contributor Author

bors r+

@mathlib-bors

mathlib-bors Bot commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

🔒 Permission denied

Existing reviewers: click here to make JovanGerb a reviewer

@JovanGerb JovanGerb removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Mar 18, 2026

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

Thanks!

bors r+

@mathlib-triage mathlib-triage Bot added the ready-to-merge This PR has been sent to bors. label 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.
@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 perf(RingTheory/Ideal/Quotient/HasFiniteQuotients): fix the HasFiniteQuotients instance [Merged by Bors] - perf(RingTheory/Ideal/Quotient/HasFiniteQuotients): fix the HasFiniteQuotients instance 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 21, 2026
…ing of integers (#36899)

This PR adds the instance `AddGroup.FG` for the ring of integers of a number field. 

This is a companion to #36535, which changed the `HasFiniteQuotients` instance for domains to use `AddGroup.FG` rather than `Module.Finite ℤ`. With this PR, `HasFiniteQuotients (𝓞 K)` can again be synthesized automatically for a number field `K`.
justus-springer pushed a commit to justus-springer/mathlib4 that referenced this pull request Mar 28, 2026
…ing of integers (leanprover-community#36899)

This PR adds the instance `AddGroup.FG` for the ring of integers of a number field. 

This is a companion to leanprover-community#36535, which changed the `HasFiniteQuotients` instance for domains to use `AddGroup.FG` rather than `Module.Finite ℤ`. With this PR, `HasFiniteQuotients (𝓞 K)` can again be synthesized automatically for a number field `K`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge This PR has been sent to bors. t-ring-theory Ring theory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants