Skip to content

chore: explicitly specify free universes in TopCat and friends - #40964

Open
grunweg wants to merge 12 commits into
leanprover-community:masterfrom
grunweg:bound-universes
Open

grunweg wants to merge 12 commits into
leanprover-community:masterfrom
grunweg:bound-universes

Conversation

@grunweg

@grunweg grunweg commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Avoid free universe variables, as discussed on Zulip: https://leanprover.zulipchat.com/#narrow/channel/144837-PR-reviews/topic/.2338223.20The.20Category.20of.20C.5En.20Manifolds/near/587824522

Perhaps, we should have a linter for this, such as by

  • extending the pp_universes attribute (TODO fix name) to take a list of universes, and only pretty-print those
  • the linter checks for any universes which are annotated with this attribute: if a declaration has a universe metavariable corresponding to such a universe, we warn

Open in Gitpod

@grunweg grunweg added the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Jun 23, 2026
@grunweg

grunweg commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Jun 23, 2026 •

Copy link
Copy Markdown

Benchmark results for 403fee8 against a83a1c3 are in. No significant results found. @grunweg

  • ✅ build//instructions: -167.9G (-0.11%)

Medium changes (2✅)

  • ✅ build/module/Mathlib.Algebra.Category.ContinuousCohomology.Basic//instructions: -20.5G (-16.49%)
  • ✅ build/module/Mathlib.Algebra.Category.ModuleCat.Topology.Basic//instructions: -9.1G (-12.81%)

Small changes (6🟥)

  • 🟥 build/module/Aesop.RuleTac.GoalDiff//instructions: +147.1M (+3.74%)
  • 🟥 build/module/Batteries.Data.Fin.Lemmas//instructions: +194.0M (+2.34%)
  • 🟥 build/module/Batteries.Data.Nat.Bisect//instructions: +204.8M (+1.49%)
  • 🟥 build/module/Plausible//instructions: +225.1M (+18.16%)
  • 🟥 build/module/ProofWidgets.Component.PenroseDiagram//instructions: +140.4M (+4.17%)
  • 🟥 build/module/Qq.Delab//instructions: +155.8M (+3.04%)

@github-actions github-actions Bot added the t-algebra Algebra (groups, rings, fields, etc) label Jun 23, 2026
@github-actions

github-actions Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

PR summary 1144844f8e

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ Scheme.{u'}
+ forgetToTop_comp_forget.{v}
+ instance (M : TopModuleCat.{v} R) : IsTopologicalAddGroup M := M.3
+ instance (M : TopModuleCat.{v} R) : TopologicalSpace M := M.2
+ instance : (forget₂ (TopModuleCat.{max v u} R) TopCat.{max u v}).IsRightAdjoint := ⟨_, ⟨freeAdj R⟩⟩
+ instance : (forget₂ (TopModuleCat.{v} R) (ModuleCat.{v} R)).IsRightAdjoint
+ instance : (forget₂ (TopModuleCat.{v} R) TopCat.{v}).ReflectsIsomorphisms
+ instance : (withModuleTopology.{v} R).IsLeftAdjoint := ⟨_, ⟨withModuleTopologyAdj R⟩⟩
+ instance : Category (TopModuleCat.{v} R)
+ instance : Category Scheme.{u}
+ instance : CategoryWithHomology (TopModuleCat.{v} R) := by
+ instance : ConcreteCategory (TopModuleCat.{v} R) (· →L[R] ·)
+ instance : EmptyCollection Scheme.{u}
+ instance : HasForget₂ (TopModuleCat.{v} R) (ModuleCat.{v} R)
+ instance : HasForget₂ (TopModuleCat.{v} R) TopCat.{v}
+ instance : Linear S (TopModuleCat.{v} S)
+ instance : Preadditive (TopModuleCat.{v} R)
+ instance {A : CommRingCat.{u}} [Nontrivial A] : Nonempty (Spec A)
+ instance {J : Type*} [Category* J] {F : J ⥤ TopModuleCat.{v} R}
+ instance {R S : CommRingCat.{u}} (f : R ⟶ S) [IsIso f] : IsIso (Spec.map f)
+ instance {X Y : TopModuleCat.{v} R} : AddCommGroup (X ⟶ Y)
+ instance {X Y : TopModuleCat.{v} S} : SMul S (X ⟶ Y)
+ topToPreord.{u}
- Scheme
- forgetToTop_comp_forget
- instance (M : TopModuleCat R) : IsTopologicalAddGroup M := M.3
- instance (M : TopModuleCat R) : TopologicalSpace M := M.2
- instance : (forget₂ (TopModuleCat R) (ModuleCat R)).IsRightAdjoint := ⟨_, ⟨withModuleTopologyAdj R⟩⟩
- instance : (forget₂ (TopModuleCat R) TopCat).ReflectsIsomorphisms
- instance : (forget₂ (TopModuleCat.{max v u} R) TopCat).IsRightAdjoint := ⟨_, ⟨freeAdj R⟩⟩
- instance : (withModuleTopology R).IsLeftAdjoint := ⟨_, ⟨withModuleTopologyAdj R⟩⟩
- instance : Category (TopModuleCat R)
- instance : Category Scheme
- instance : CategoryWithHomology (TopModuleCat R) := by
- instance : ConcreteCategory (TopModuleCat R) (· →L[R] ·)
- instance : EmptyCollection Scheme
- instance : HasForget₂ (TopModuleCat R) (ModuleCat R)
- instance : HasForget₂ (TopModuleCat R) TopCat
- instance : Linear S (TopModuleCat S)
- instance : Preadditive (TopModuleCat R)
- instance {A : CommRingCat} [Nontrivial A] : Nonempty (Spec A)
- instance {J : Type*} [Category* J] {F : J ⥤ TopModuleCat R}
- instance {R S : CommRingCat} (f : R ⟶ S) [IsIso f] : IsIso (Spec.map f)
- instance {X Y : TopModuleCat R} : AddCommGroup (X ⟶ Y)
- instance {X Y : TopModuleCat S} : SMul S (X ⟶ Y)
- topToPreord

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

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

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean)

✅ Lean-aware diff — post-build, computed from the Lean environment (commit 1144844).

  • +0 new declarations
  • −0 removed declarations

No declaration differences.


No changes to strong technical debt.
No changes to weak technical debt.

Current commit 1144844f8e
Reference commit a02a63c210

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.py 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 removed the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Jun 23, 2026
@grunweg grunweg added the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Jun 23, 2026
@grunweg grunweg changed the title chore(Algebra/Category/ModuleCat/Topology): explicit specify universe… chore: explicitly specify free universes in TopCat and friends Jun 23, 2026
@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 Jun 23, 2026
@grunweg

grunweg commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Jun 24, 2026 •

Copy link
Copy Markdown

Benchmark results for 355575a against a83a1c3 are in. There are significant results. @grunweg

  • ✅ build//instructions: -38.3G (-0.03%)

Large changes (1✅)

  • ✅ build/module/Mathlib.Algebra.Category.ContinuousCohomology.Basic//instructions: -24.0G (-19.32%)

Medium changes (1✅)

  • ✅ build/module/Mathlib.Algebra.Category.ModuleCat.Topology.Basic//instructions: -9.2G (-12.95%)

Small changes (1✅)

  • ✅ build/module/Mathlib.RepresentationTheory.Continuous.TopRep//instructions: -1.2G (-3.26%)

@grunweg

grunweg commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

Copy link
Copy Markdown

Benchmark results for 355575a against a83a1c3 are in. (These commits have already been benchmarked in a previous command.) There are significant results. @grunweg

  • ✅ build//instructions: -38.3G (-0.03%)

Large changes (1✅)

  • ✅ build/module/Mathlib.Algebra.Category.ContinuousCohomology.Basic//instructions: -24.0G (-19.32%)

Medium changes (1✅)

  • ✅ build/module/Mathlib.Algebra.Category.ModuleCat.Topology.Basic//instructions: -9.2G (-12.95%)

Small changes (1✅)

  • ✅ build/module/Mathlib.RepresentationTheory.Continuous.TopRep//instructions: -1.2G (-3.26%)

@grunweg grunweg mentioned this pull request Jun 24, 2026
@grunweg
grunweg requested a review from chrisflav June 25, 2026 09:54
@grunweg

grunweg commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@adomani Is there a way to make the Lean declaration diff more helpful? For instance, by flagging all the declarations where the pretty-printed form with universes changes (which in turn implies the others are fine)?

@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@mathlib-merge-conflicts mathlib-merge-conflicts Bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jul 3, 2026
@github-actions github-actions Bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jul 8, 2026
mathlib-bors Bot pushed a commit that referenced this pull request Jul 8, 2026
…icitly (#41483)

This is beneficial for the same reasons as #40964. This particular change matters for #41462; extracted from that PR.

Co-authored-by: felixpernegger <[email protected]>
michaellee94 pushed a commit to michaellee94/mathlib4 that referenced this pull request Jul 11, 2026
…icitly (leanprover-community#41483)

This is beneficial for the same reasons as leanprover-community#40964. This particular change matters for leanprover-community#41462; extracted from that PR.

Co-authored-by: felixpernegger <[email protected]>
mpacholski pushed a commit to mpacholski/mathlib4 that referenced this pull request Jul 16, 2026
…icitly (leanprover-community#41483)

This is beneficial for the same reasons as leanprover-community#40964. This particular change matters for leanprover-community#41462; extracted from that PR.

Co-authored-by: felixpernegger <[email protected]>

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

Going over this and testing a few select occurences. This looks good. However it s hard to check by hand if this doesnt accidentally de-generalise a declaration. I.e. if we replace {X Y: ModuleCat R} {X Y: ModuleCat.{v} R} it is not immediately clear (to me) that X and Y really must have the same universe.
In all cases I checked (maybe 5?) this was indeed required, as there are fields with X.Hom Y etc..

So, from a reviewing point, is there some easier/more automatic way to check nothing gets de-generalised except hand picking each one and/or guessing?

@grunweg

grunweg commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

I think the strategy I sketched to you over lunch should work:

  • make a list of declarations modified in the PR (by hand and/or tooling help)
  • make a test file setting pp.universes to true and containing lots #guard_msgs in #check foo (for every foo that's modified in the PR)
  • run this file both before and after this PR, and
  • compare the output: in many cases, no change (in others, there will be universe names introduces and the diff will change spuriously: those need more scrutiny)

I can try to set up such a file myself. If you'd like to help by making such a file, that's also welcome. (I won't have time for this until Wednesday.)

@mathlib-merge-conflicts mathlib-merge-conflicts Bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jul 17, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

mpacholski pushed a commit to mpacholski/mathlib4 that referenced this pull request Jul 30, 2026
…icitly (leanprover-community#41483)

This is beneficial for the same reasons as leanprover-community#40964. This particular change matters for leanprover-community#41462; extracted from that PR.

Co-authored-by: felixpernegger <[email protected]>
mpacholski pushed a commit to mpacholski/mathlib4 that referenced this pull request Jul 30, 2026
…icitly (leanprover-community#41483)

This is beneficial for the same reasons as leanprover-community#40964. This particular change matters for leanprover-community#41462; extracted from that PR.

Co-authored-by: felixpernegger <[email protected]>
@github-actions github-actions Bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Oct 9, 2026
@mathlib-merge-conflicts mathlib-merge-conflicts Bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Nov 9, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@bryangingechen

bryangingechen commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Here's the output of the prototype declaration diff scripts, as requested by @adomani in a Zulip DM. It's not part of the script yet, but I did check that no universes ended up de-generalized (specialized?); all the changes are just reorders.

"(in the head's names)" might be a bit mysterious: this is just indicating that the names of the universes changed between the base of the PR and the head, and both universe orderings are printed using the names in the head. (Suggestions for better wording here or elsewhere would be greatly appreciated!)


Declarations diff (Lean)

✅ Lean-aware diff — post-build, computed from the Lean environment (commit 1144844).

Shape: universe reorders. 45 declarations with their universes reordered.

  • +0 new declarations
  • −0 removed declarations
universe parameters reordered under the same name (45)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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