Skip to content

[Merged by Bors] - feat(Algebra/Category): ConcreteCategory instances for rings#20815

Closed
Vierkantor wants to merge 5 commits intomasterfrom
concrete-CommRingCat
Closed

[Merged by Bors] - feat(Algebra/Category): ConcreteCategory instances for rings#20815
Vierkantor wants to merge 5 commits intomasterfrom
concrete-CommRingCat

Conversation

@Vierkantor
Copy link
Copy Markdown
Contributor

@Vierkantor Vierkantor commented Jan 17, 2025

This is a step towards a concrete category redesign, as outlined in this Zulip post: https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Concrete.20category.20class.20redesign/near/493903980

This PR adds a ConcreteCategory instance for the categories of rings: SemiRingCat, RingCat, CommSemiRingCat and CommRingCat. It also replaces the Hom.hom structure projection with an alias for ConcreteCategory.hom. The latter requires a few fixes downstream where things get mistakenly unfolded (especially involving ModuleCat.restrictScalars) or where rw doesn't see through the definitional equality ConcreteCategory.hom (ConcreteCategory.ofHom f) = f. Finally, a few places where the proof works around the old forget <-> FunLike mismatch, and needs updating.

I have not tried to look for code that can be cleaned up now, only at what broke. I want to get started on cleanup when the other concrete category instances are in.


Open in Gitpod

@Vierkantor Vierkantor added t-category-theory Category theory t-algebra Algebra (groups, rings, fields, etc) labels Jan 17, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 17, 2025

PR summary fa7c15f855

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ instance : ConcreteCategory.{u} CommRingCat (fun R S => R →+* S)
+ instance : ConcreteCategory.{u} CommSemiRingCat (fun R S => R →+* S)
+ instance : ConcreteCategory.{u} RingCat (fun R S => R →+* S)
+ instance : ConcreteCategory.{u} SemiRingCat (fun R S => R →+* S)
++++ Hom.Simps.hom
++++ Hom.hom
- instance : HasForget.{u} CommRingCat
- instance : HasForget.{u} CommSemiRingCat
- instance : HasForget.{u} RingCat
- instance : HasForget.{u} SemiRingCat
- instance {R S : CommRingCat.{u}} : CoeFun (R ⟶ S) (fun _ ↦ R → S)
- instance {R S : CommSemiRingCat.{u}} : CoeFun (R ⟶ S) (fun _ ↦ R → S)
- instance {R S : RingCat.{u}} : CoeFun (R ⟶ S) (fun _ ↦ R → S)
- instance {R S : SemiRingCat.{u}} : CoeFun (R ⟶ S) (fun _ ↦ R → S)
-+-+-+-+ Hom

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.


Decrease in tech debt: (relative, absolute) = (2.00, 0.00)
Current number Change Type
1415 -2 erw

Current commit fa7c15f855
Reference commit c33fe046f6

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

@Vierkantor Vierkantor added the help-wanted The author needs attention to resolve issues label Jan 17, 2025
@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot added blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) and removed blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) labels Jan 17, 2025
@mathlib4-dependent-issues-bot
Copy link
Copy Markdown
Collaborator

@mattrobball
Copy link
Copy Markdown
Contributor

!bench

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit b0815d4.
There were significant changes against commit 9ca037a:

  Benchmark                                                    Metric         Change
  ==================================================================================
- ~Mathlib.Algebra.Category.Grp.Biproducts                     instructions   136.0%
- ~Mathlib.Algebra.Category.ModuleCat.Biproducts               instructions    82.5%
- ~Mathlib.Algebra.Category.ModuleCat.Differentials.Presheaf   instructions    66.9%
- ~Mathlib.Algebra.Category.ModuleCat.Images                   instructions    85.2%
- ~Mathlib.Algebra.Category.ModuleCat.Kernels                  instructions   119.4%
- ~Mathlib.Algebra.Category.ModuleCat.Presheaf                 instructions    17.7%
- ~Mathlib.Algebra.Category.ModuleCat.Presheaf.Monoidal        instructions    25.3%
- ~Mathlib.Algebra.Category.ModuleCat.Products                 instructions   127.5%
- ~Mathlib.Algebra.Category.Ring.Limits                        instructions    42.3%
- ~Mathlib.Algebra.Homology.ShortComplex.ModuleCat             instructions   137.3%
- ~Mathlib.AlgebraicGeometry.AffineScheme                      instructions    15.7%
- ~Mathlib.AlgebraicGeometry.AffineSpace                       instructions     7.6%
- ~Mathlib.AlgebraicGeometry.Modules.Tilde                     instructions    17.0%
- ~Mathlib.AlgebraicGeometry.Morphisms.QuasiSeparated          instructions    12.2%
- ~Mathlib.CategoryTheory.ConcreteCategory.Elementwise         instructions   502.3%
- ~Mathlib.CategoryTheory.Sites.LocallySurjective              instructions   103.1%
- ~Mathlib.CategoryTheory.Subobject.Limits                     instructions    48.2%
- ~Mathlib.Geometry.Manifold.Sheaf.Smooth                      instructions    60.2%
- ~Mathlib.Geometry.RingedSpace.OpenImmersion                  instructions    13.0%
- ~Mathlib.Geometry.RingedSpace.Stalks                         instructions    64.3%
+ ~Mathlib.Topology.Sheaves.CommRingCat                        instructions   -16.0%
- ~Mathlib.Topology.Sheaves.SheafCondition.EqualizerProducts   instructions    10.8%
- ~Mathlib.Topology.Sheaves.Stalks                             instructions    30.1%

@github-actions
Copy link
Copy Markdown

File Instructions %
build +723.532⬝10⁹ (+0.47%)
lint -1.153⬝10⁹ (-0.01%)
Mathlib.Algebra.Homology.ShortComplex.ModuleCat +80.284⬝10⁹ (+137.29%)
Mathlib.Algebra.Category.ModuleCat.Differentials.Presheaf +48.271⬝10⁹ (+66.94%)
2 files, Instructions +40.0⬝10⁹
File Instructions %
Mathlib.Algebra.Category.Ring.Limits +40.680⬝10⁹ (+42.30%)
Mathlib.Geometry.Manifold.Sheaf.Smooth +40.154⬝10⁹ (+60.19%)
File Instructions %
Mathlib.Algebra.Category.ModuleCat.Presheaf +37.404⬝10⁹ (+17.65%)
Mathlib.AlgebraicGeometry.AffineScheme +32.520⬝10⁹ (+15.65%)
Mathlib.Topology.Sheaves.Stalks +31.709⬝10⁹ (+30.14%)
Mathlib.Geometry.RingedSpace.OpenImmersion +29.195⬝10⁹ (+12.99%)
Mathlib.Geometry.RingedSpace.Stalks +27.867⬝10⁹ (+64.30%)
Mathlib.AlgebraicGeometry.Modules.Tilde +26.64⬝10⁹ (+17.01%)
Mathlib.CategoryTheory.ConcreteCategory.Elementwise +24.299⬝10⁹ (+502.34%)
Mathlib.CategoryTheory.Sites.LocallySurjective +23.102⬝10⁹ (+103.12%)
Mathlib.Algebra.Category.ModuleCat.Products +22.706⬝10⁹ (+127.50%)
Mathlib.Algebra.Category.ModuleCat.Kernels +21.216⬝10⁹ (+119.41%)
Mathlib.Algebra.Category.ModuleCat.Presheaf.Monoidal +18.856⬝10⁹ (+25.30%)
Mathlib.AlgebraicGeometry.AffineSpace +17.755⬝10⁹ (+7.60%)
Mathlib.Algebra.Category.ModuleCat.Biproducts +16.303⬝10⁹ (+82.52%)
Mathlib.Algebra.Category.Grp.Biproducts +15.251⬝10⁹ (+136.02%)
2 files, Instructions +13.0⬝10⁹
File Instructions %
Mathlib.AlgebraicGeometry.Morphisms.QuasiSeparated +13.834⬝10⁹ (+12.23%)
Mathlib.CategoryTheory.Subobject.Limits +13.253⬝10⁹ (+48.24%)
File Instructions %
Mathlib.Topology.Sheaves.SheafCondition.EqualizerProducts +12.486⬝10⁹ (+10.82%)
Mathlib.Algebra.Category.ModuleCat.Images +10.815⬝10⁹ (+85.17%)
2 files, Instructions +8.0⬝10⁹
File Instructions %
Mathlib.CategoryTheory.Limits.Shapes.Types +8.957⬝10⁹ (+20.35%)
Mathlib.Topology.Category.TopCat.Limits.Products +8.587⬝10⁹ (+20.95%)
2 files, Instructions +7.0⬝10⁹
File Instructions %
Mathlib.CategoryTheory.Elementwise +7.505⬝10⁹ (+271.52%)
Mathlib.Algebra.Homology.HomologicalComplex +7.187⬝10⁹ (+18.11%)
2 files, Instructions +6.0⬝10⁹
File Instructions %
Mathlib.CategoryTheory.GlueData +6.206⬝10⁹ (+8.07%)
Mathlib.Algebra.Category.Ring.FilteredColimits +6.85⬝10⁹ (+17.04%)
2 files, Instructions +5.0⬝10⁹
File Instructions %
Mathlib.AlgebraicGeometry.StructureSheaf +5.922⬝10⁹ (+3.48%)
Mathlib.CategoryTheory.Limits.ConcreteCategory.WithAlgebraicStructures +5.567⬝10⁹ (+40.14%)
3 files, Instructions +4.0⬝10⁹
File Instructions %
Mathlib.Algebra.Category.ModuleCat.Presheaf.Pushforward +4.625⬝10⁹ (+3.97%)
Mathlib.AlgebraicGeometry.Spec +4.388⬝10⁹ (+4.56%)
Mathlib.Topology.Gluing +4.228⬝10⁹ (+9.35%)
4 files, Instructions +3.0⬝10⁹
File Instructions %
Mathlib.CategoryTheory.Sites.Subsheaf +3.817⬝10⁹ (+25.92%)
Mathlib.Algebra.Category.Ring.Basic +3.600⬝10⁹ (+8.53%)
Mathlib.Algebra.Category.ModuleCat.Presheaf.Sheafify +3.452⬝10⁹ (+4.88%)
Mathlib.AlgebraicGeometry.OpenImmersion +3.258⬝10⁹ (+4.74%)
10 files, Instructions +2.0⬝10⁹
File Instructions %
Mathlib.Geometry.RingedSpace.Basic +2.892⬝10⁹ (+8.76%)
Mathlib.CategoryTheory.Comma.Presheaf.Basic +2.824⬝10⁹ (+1.93%)
Mathlib.Algebra.Category.Ring.Adjunctions +2.792⬝10⁹ (+20.61%)
Mathlib.AlgebraicGeometry.Morphisms.ClosedImmersion +2.723⬝10⁹ (+6.82%)
Mathlib.CategoryTheory.Subobject.Basic +2.672⬝10⁹ (+5.11%)
Mathlib.AlgebraicGeometry.Morphisms.RingHomProperties +2.257⬝10⁹ (+2.79%)
Mathlib.Algebra.Category.AlgebraCat.Limits +2.140⬝10⁹ (+3.56%)
Mathlib.AlgebraicGeometry.SpreadingOut +2.108⬝10⁹ (+6.02%)
Mathlib.CategoryTheory.Subpresheaf.Basic +2.106⬝10⁹ (+18.70%)
Mathlib.Geometry.RingedSpace.LocallyRingedSpace.ResidueField +2.20⬝10⁹ (+9.28%)
7 files, Instructions +1.0⬝10⁹
File Instructions %
Mathlib.AlgebraicGeometry.ProjectiveSpectrum.StructureSheaf +1.864⬝10⁹ (+2.34%)
Mathlib.AlgebraicGeometry.Scheme +1.695⬝10⁹ (+1.83%)
Mathlib.RingTheory.Etale.Field +1.382⬝10⁹ (+1.95%)
Mathlib.Algebra.Category.Ring.Under.Limits +1.355⬝10⁹ (+1.08%)
Mathlib.AlgebraicGeometry.Morphisms.QuasiCompact +1.305⬝10⁹ (+2.89%)
Mathlib.Algebra.Category.Ring.Under.Basic +1.212⬝10⁹ (+3.11%)
Mathlib.Geometry.RingedSpace.LocallyRingedSpace +1.193⬝10⁹ (+2.14%)
File Instructions %
Mathlib.RingTheory.RingHomProperties -2.388⬝10⁹ (-8.82%)
Mathlib.AlgebraicGeometry.Restrict -3.227⬝10⁹ (-2.70%)
Mathlib.Topology.Sheaves.CommRingCat -13.308⬝10⁹ (-15.98%)
CI run

@Vierkantor
Copy link
Copy Markdown
Contributor Author

Ouch, that's a disappointing outcome... But I suspect quite some changes come from elementwise doing double work to support HasForget and ConcreteCategory simultaneously (especially since some of those files should not be importing Category.Ring.Basic. Let me rebase to check what the impact of this PR specifically is.

I'll also open a branch adding only the ConcreteCategory instance, without redefining hom and ofHom.

@Vierkantor Vierkantor force-pushed the concrete-CommRingCat branch from b0815d4 to b6cb4d9 Compare January 18, 2025 09:58
Vierkantor added a commit that referenced this pull request Jan 18, 2025
This changes nothing about the definition of ring categories except upgrading the `HasForget` instance to `ConcreteCategory`. This PR is intended mostly as an experiment to contrast with #20815 and figure out why that one has a disappointing benchmark outcome.
@Vierkantor
Copy link
Copy Markdown
Contributor Author

!bench

@Vierkantor Vierkantor added the awaiting-bench This PR needs to be benchmarked before merging label Jan 18, 2025
@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit b6cb4d9.
There were significant changes against commit 7365868:

  Benchmark                                                    Metric         Change
  ==================================================================================
- ~Mathlib.Algebra.Category.ModuleCat.Differentials.Presheaf   instructions    66.9%
- ~Mathlib.Algebra.Category.ModuleCat.Presheaf                 instructions    17.6%
- ~Mathlib.Algebra.Category.ModuleCat.Presheaf.Monoidal        instructions    25.3%
- ~Mathlib.Algebra.Category.Ring.Limits                        instructions    42.2%
- ~Mathlib.AlgebraicGeometry.AffineSpace                       instructions     7.6%
- ~Mathlib.AlgebraicGeometry.Modules.Tilde                     instructions     6.9%
- ~Mathlib.AlgebraicGeometry.Morphisms.QuasiSeparated          instructions    12.2%
+ ~Mathlib.AlgebraicGeometry.OpenImmersion                     instructions   -41.7%
+ ~Mathlib.AlgebraicGeometry.Spec                              instructions   -21.7%
+ ~Mathlib.AlgebraicGeometry.StructureSheaf                    instructions   -31.7%
+ ~Mathlib.Geometry.Manifold.Sheaf.Smooth                      instructions   -43.1%
+ ~Mathlib.Geometry.RingedSpace.OpenImmersion                  instructions   -10.5%
+ ~Mathlib.Topology.Sheaves.CommRingCat                        instructions   -16.0%

@github-actions
Copy link
Copy Markdown

File Instructions %
build -45.364⬝10⁹ (-0.02%)
lint -1.175⬝10⁹ (-0.01%)
Mathlib.Algebra.Category.ModuleCat.Differentials.Presheaf +48.261⬝10⁹ (+66.92%)
Mathlib.Algebra.Category.Ring.Limits +40.532⬝10⁹ (+42.19%)
Mathlib.Algebra.Category.ModuleCat.Presheaf +37.397⬝10⁹ (+17.64%)
Mathlib.Algebra.Category.ModuleCat.Presheaf.Monoidal +18.870⬝10⁹ (+25.32%)
Mathlib.AlgebraicGeometry.AffineSpace +17.749⬝10⁹ (+7.60%)
Mathlib.AlgebraicGeometry.Morphisms.QuasiSeparated +13.851⬝10⁹ (+12.24%)
Mathlib.AlgebraicGeometry.Modules.Tilde +11.628⬝10⁹ (+6.93%)
Mathlib.Algebra.Category.Ring.FilteredColimits +6.358⬝10⁹ (+17.84%)
Mathlib.Algebra.Category.ModuleCat.Presheaf.Pushforward +4.682⬝10⁹ (+4.02%)
2 files, Instructions +3.0⬝10⁹
File Instructions %
Mathlib.Algebra.Category.Ring.Basic +3.442⬝10⁹ (+8.12%)
Mathlib.Algebra.Category.ModuleCat.Presheaf.Sheafify +3.404⬝10⁹ (+4.82%)
7 files, Instructions +2.0⬝10⁹
File Instructions %
Mathlib.Geometry.RingedSpace.Basic +2.812⬝10⁹ (+8.50%)
Mathlib.Algebra.Category.Ring.Adjunctions +2.793⬝10⁹ (+20.62%)
Mathlib.AlgebraicGeometry.Morphisms.ClosedImmersion +2.725⬝10⁹ (+6.82%)
Mathlib.AlgebraicGeometry.Morphisms.RingHomProperties +2.259⬝10⁹ (+2.80%)
Mathlib.AlgebraicGeometry.ProjectiveSpectrum.StructureSheaf +2.226⬝10⁹ (+2.81%)
Mathlib.AlgebraicGeometry.SpreadingOut +2.111⬝10⁹ (+6.03%)
Mathlib.Geometry.RingedSpace.LocallyRingedSpace.ResidueField +2.63⬝10⁹ (+9.50%)
9 files, Instructions +1.0⬝10⁹
File Instructions %
Mathlib.Algebra.Category.AlgebraCat.Limits +1.733⬝10⁹ (+2.87%)
Mathlib.AlgebraicGeometry.Scheme +1.690⬝10⁹ (+1.82%)
Mathlib.Data.Array.Lemmas +1.606⬝10⁹ (+53.18%)
Mathlib.RingTheory.Etale.Field +1.473⬝10⁹ (+2.08%)
Mathlib.AlgebraicGeometry.AffineScheme +1.319⬝10⁹ (+0.55%)
Mathlib.AlgebraicGeometry.Morphisms.QuasiCompact +1.311⬝10⁹ (+2.90%)
Mathlib.Algebra.Category.Ring.Under.Basic +1.206⬝10⁹ (+3.11%)
Mathlib.Geometry.RingedSpace.LocallyRingedSpace +1.194⬝10⁹ (+2.15%)
Mathlib.Algebra.Category.Ring.Under.Limits +1.162⬝10⁹ (+0.93%)
File Instructions %
Mathlib.RingTheory.RingHomProperties -2.390⬝10⁹ (-8.83%)
Mathlib.AlgebraicGeometry.Restrict -3.221⬝10⁹ (-2.70%)
Mathlib.Topology.Sheaves.CommRingCat -13.306⬝10⁹ (-15.98%)
Mathlib.AlgebraicGeometry.Spec -27.795⬝10⁹ (-21.68%)
Mathlib.Geometry.RingedSpace.OpenImmersion -29.714⬝10⁹ (-10.47%)
Mathlib.AlgebraicGeometry.OpenImmersion -51.539⬝10⁹ (-41.72%)
Mathlib.Geometry.Manifold.Sheaf.Smooth -80.813⬝10⁹ (-43.05%)
Mathlib.AlgebraicGeometry.StructureSheaf -81.466⬝10⁹ (-31.66%)
CI run

@Vierkantor
Copy link
Copy Markdown
Contributor Author

So it looks like sheaves of modules get slower, but sheaves of rings get faster, and the two cancel out quite neatly. Interesting!

@Vierkantor
Copy link
Copy Markdown
Contributor Author

The benchmark results on the other version that does not touch hom and ofHom look similar, just not as much impact. Some things get slower, others get faster and it all balances out quite nicely.

@leanprover-community-bot-assistant leanprover-community-bot-assistant added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jan 21, 2025
This is a step towards a concrete category redesign, as outlined in this Zulip post: https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Concrete.20category.20class.20redesign/near/493903980

This PR adds a `ConcreteCategory` instance for the categories of rings: `SemiRingCat`, `RingCat`, `CommSemiRingCat` and `CommRingCat`. It also replaces the `Hom.hom` structure projection with an alias for `ConcreteCategory.hom`. The latter requires a few fixes downstream where things get mistakenly unfolded (especially involving `ModuleCat.restrictScalars`) or where `rw` doesn't see through the definitional equality `ConcreteCategory.hom (ConcreteCategory.ofHom f) = f`. Finally, a few places where the proof works around the old `forget` <-> `FunLike` mismatch, and needs updating.

I have not tried to look for code that can be cleaned up now, only at what broke. Better do that when the other concrete categories are in.
@Vierkantor Vierkantor force-pushed the concrete-CommRingCat branch from b6cb4d9 to 10bacfb Compare January 22, 2025 10:55
@leanprover-community-bot-assistant leanprover-community-bot-assistant removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jan 22, 2025
@Vierkantor Vierkantor removed the help-wanted The author needs attention to resolve issues label Jan 23, 2025
@Vierkantor
Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit dec48d2.
There were significant changes against commit aaf3fad:

  Benchmark                                                    Metric         Change
  ==================================================================================
- ~Mathlib.Algebra.Category.ModuleCat.Differentials.Presheaf   instructions    66.8%
- ~Mathlib.Algebra.Category.ModuleCat.Presheaf                 instructions    17.7%
- ~Mathlib.Algebra.Category.ModuleCat.Presheaf.Monoidal        instructions    25.4%
- ~Mathlib.Algebra.Category.Ring.Limits                        instructions    42.3%
+ ~Mathlib.AlgebraicGeometry.AffineScheme                      instructions   -19.4%
- ~Mathlib.AlgebraicGeometry.AffineSpace                       instructions     6.9%
- ~Mathlib.AlgebraicGeometry.Modules.Tilde                     instructions     6.9%
- ~Mathlib.AlgebraicGeometry.Morphisms.QuasiSeparated          instructions    12.2%
+ ~Mathlib.AlgebraicGeometry.OpenImmersion                     instructions   -41.7%
+ ~Mathlib.AlgebraicGeometry.Spec                              instructions   -21.7%
+ ~Mathlib.AlgebraicGeometry.StructureSheaf                    instructions   -31.7%
+ ~Mathlib.Geometry.Manifold.Sheaf.Smooth                      instructions   -43.1%
+ ~Mathlib.Geometry.RingedSpace.OpenImmersion                  instructions   -10.4%
+ ~Mathlib.Topology.Sheaves.CommRingCat                        instructions   -16.0%

@github-actions
Copy link
Copy Markdown

File Instructions %
build -94.554⬝10⁹ (-0.06%)
lint -1.567⬝10⁹ (-0.02%)
Mathlib.Algebra.Category.ModuleCat.Differentials.Presheaf +48.136⬝10⁹ (+66.75%)
Mathlib.Algebra.Category.Ring.Limits +40.677⬝10⁹ (+42.32%)
Mathlib.Algebra.Category.ModuleCat.Presheaf +37.407⬝10⁹ (+17.65%)
2 files, Instructions +18.0⬝10⁹
File Instructions %
Mathlib.Algebra.Category.ModuleCat.Presheaf.Monoidal +18.938⬝10⁹ (+25.44%)
Mathlib.AlgebraicGeometry.AffineSpace +18.49⬝10⁹ (+6.85%)
File Instructions %
Mathlib.AlgebraicGeometry.Morphisms.QuasiSeparated +13.838⬝10⁹ (+12.23%)
Mathlib.AlgebraicGeometry.Modules.Tilde +11.582⬝10⁹ (+6.90%)
Mathlib.Algebra.Category.Ring.FilteredColimits +6.153⬝10⁹ (+17.26%)
Mathlib.Algebra.Category.ModuleCat.Presheaf.Pushforward +4.824⬝10⁹ (+4.14%)
2 files, Instructions +3.0⬝10⁹
File Instructions %
Mathlib.Algebra.Category.ModuleCat.Presheaf.Sheafify +3.467⬝10⁹ (+4.90%)
Mathlib.Algebra.Category.Ring.Basic +3.451⬝10⁹ (+8.14%)
5 files, Instructions +2.0⬝10⁹
File Instructions %
Mathlib.Geometry.RingedSpace.Basic +2.965⬝10⁹ (+9.02%)
Mathlib.Algebra.Category.Ring.Adjunctions +2.793⬝10⁹ (+20.61%)
Mathlib.AlgebraicGeometry.Morphisms.ClosedImmersion +2.561⬝10⁹ (+6.66%)
Mathlib.AlgebraicGeometry.Morphisms.RingHomProperties +2.276⬝10⁹ (+2.64%)
Mathlib.AlgebraicGeometry.SpreadingOut +2.111⬝10⁹ (+6.02%)
10 files, Instructions +1.0⬝10⁹
File Instructions %
Mathlib.Geometry.RingedSpace.LocallyRingedSpace.ResidueField +1.903⬝10⁹ (+8.70%)
Mathlib.AlgebraicGeometry.ProjectiveSpectrum.StructureSheaf +1.795⬝10⁹ (+2.26%)
Mathlib.AlgebraicGeometry.Scheme +1.635⬝10⁹ (+1.75%)
Mathlib.Algebra.Category.AlgebraCat.Limits +1.593⬝10⁹ (+2.63%)
Mathlib.AlgebraicGeometry.Morphisms.QuasiCompact +1.323⬝10⁹ (+2.93%)
Mathlib.Algebra.Category.Ring.Under.Basic +1.286⬝10⁹ (+3.31%)
Mathlib.Algebra.Category.Ring.Under.Limits +1.273⬝10⁹ (+1.02%)
Mathlib.Geometry.RingedSpace.LocallyRingedSpace +1.201⬝10⁹ (+2.16%)
Mathlib.RingTheory.Etale.Field +1.181⬝10⁹ (+1.66%)
Mathlib.Algebra.Category.ModuleCat.Presheaf.Sheafification +1.97⬝10⁹ (+1.61%)
File Instructions %
Mathlib.RingTheory.RingHomProperties -2.313⬝10⁹ (-8.50%)
Mathlib.AlgebraicGeometry.Restrict -3.301⬝10⁹ (-2.64%)
Mathlib.Topology.Sheaves.CommRingCat -13.354⬝10⁹ (-16.02%)
Mathlib.AlgebraicGeometry.Spec -27.725⬝10⁹ (-21.66%)
Mathlib.Geometry.RingedSpace.OpenImmersion -29.542⬝10⁹ (-10.41%)
Mathlib.AlgebraicGeometry.AffineScheme -46.316⬝10⁹ (-19.38%)
Mathlib.AlgebraicGeometry.OpenImmersion -51.536⬝10⁹ (-41.72%)
Mathlib.Geometry.Manifold.Sheaf.Smooth -80.819⬝10⁹ (-43.06%)
Mathlib.AlgebraicGeometry.StructureSheaf -81.468⬝10⁹ (-31.67%)
CI run

@Vierkantor
Copy link
Copy Markdown
Contributor Author

Huh, apart from that one slowdown, this PR apparently was quite good for timings in AffineScheme!

@Vierkantor Vierkantor removed the awaiting-bench This PR needs to be benchmarked before merging label Jan 23, 2025
@mattrobball
Copy link
Copy Markdown
Contributor

Let's merge master and re-bench. This was a motivation for pushing through #11521. I'm curious to see the effects.

@Vierkantor
Copy link
Copy Markdown
Contributor Author

Ok! So should I just merge master, or also add fast_instance% to some declarations?

@mattrobball
Copy link
Copy Markdown
Contributor

Merging master should be sufficient. It might be the case that we have some more mismatched instance shapes but I don't know.

@Vierkantor
Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit fa7c15f.
There were significant changes against commit c33fe04:

  Benchmark                                                    Metric         Change
  ==================================================================================
- ~Mathlib.Algebra.Category.ModuleCat.Differentials.Presheaf   instructions    67.0%
- ~Mathlib.Algebra.Category.ModuleCat.Presheaf                 instructions    17.6%
- ~Mathlib.Algebra.Category.ModuleCat.Presheaf.Monoidal        instructions    25.5%
- ~Mathlib.Algebra.Category.Ring.Limits                        instructions    46.5%
+ ~Mathlib.AlgebraicGeometry.AffineScheme                      instructions   -18.3%
- ~Mathlib.AlgebraicGeometry.AffineSpace                       instructions     7.0%
- ~Mathlib.AlgebraicGeometry.Modules.Tilde                     instructions     8.7%
- ~Mathlib.AlgebraicGeometry.Morphisms.QuasiSeparated          instructions    11.9%
+ ~Mathlib.AlgebraicGeometry.OpenImmersion                     instructions   -41.0%
+ ~Mathlib.AlgebraicGeometry.Spec                              instructions   -27.1%
+ ~Mathlib.AlgebraicGeometry.StructureSheaf                    instructions   -32.6%
+ ~Mathlib.Geometry.Manifold.Sheaf.Smooth                      instructions   -43.0%
+ ~Mathlib.Geometry.RingedSpace.OpenImmersion                  instructions   -10.1%
+ ~Mathlib.Topology.Sheaves.CommRingCat                        instructions   -16.2%

@github-actions
Copy link
Copy Markdown

File Instructions %
build -84.656⬝10⁹ (-0.05%)
lint -1.353⬝10⁹ (-0.01%)
Mathlib.Algebra.Category.ModuleCat.Differentials.Presheaf +48.279⬝10⁹ (+67.01%)
Mathlib.Algebra.Category.Ring.Limits +40.744⬝10⁹ (+46.51%)
Mathlib.Algebra.Category.ModuleCat.Presheaf +37.297⬝10⁹ (+17.60%)
Mathlib.Algebra.Category.ModuleCat.Presheaf.Monoidal +18.947⬝10⁹ (+25.45%)
Mathlib.AlgebraicGeometry.AffineSpace +16.140⬝10⁹ (+6.98%)
Mathlib.AlgebraicGeometry.Morphisms.QuasiSeparated +13.383⬝10⁹ (+11.86%)
Mathlib.AlgebraicGeometry.Modules.Tilde +11.529⬝10⁹ (+8.73%)
Mathlib.Algebra.Category.Ring.FilteredColimits +6.32⬝10⁹ (+16.88%)
Mathlib.Algebra.Category.ModuleCat.Presheaf.Pushforward +4.815⬝10⁹ (+4.13%)
3 files, Instructions +3.0⬝10⁹
File Instructions %
Mathlib.Algebra.Category.Ring.Basic +3.525⬝10⁹ (+8.32%)
Mathlib.Algebra.Category.ModuleCat.Presheaf.Sheafify +3.462⬝10⁹ (+4.90%)
Mathlib.Geometry.RingedSpace.Basic +3.13⬝10⁹ (+9.11%)
6 files, Instructions +2.0⬝10⁹
File Instructions %
Mathlib.Algebra.Category.Ring.Adjunctions +2.765⬝10⁹ (+20.56%)
Mathlib.AlgebraicGeometry.Morphisms.ClosedImmersion +2.619⬝10⁹ (+7.93%)
Mathlib.AlgebraicGeometry.Morphisms.RingHomProperties +2.264⬝10⁹ (+2.63%)
Mathlib.AlgebraicGeometry.Scheme +2.246⬝10⁹ (+2.09%)
Mathlib.Geometry.RingedSpace.LocallyRingedSpace.ResidueField +2.15⬝10⁹ (+9.27%)
Mathlib.AlgebraicGeometry.SpreadingOut +2.4⬝10⁹ (+5.87%)
6 files, Instructions +1.0⬝10⁹
File Instructions %
Mathlib.AlgebraicGeometry.ProjectiveSpectrum.StructureSheaf +1.678⬝10⁹ (+2.17%)
Mathlib.Algebra.Category.AlgebraCat.Limits +1.657⬝10⁹ (+2.91%)
Mathlib.RingTheory.Etale.Field +1.388⬝10⁹ (+2.31%)
Mathlib.AlgebraicGeometry.Morphisms.QuasiCompact +1.297⬝10⁹ (+2.86%)
Mathlib.Geometry.RingedSpace.LocallyRingedSpace +1.209⬝10⁹ (+2.17%)
Mathlib.Algebra.Category.Ring.Under.Basic +1.195⬝10⁹ (+3.07%)
File Instructions %
Mathlib.RingTheory.RingHomProperties -2.566⬝10⁹ (-9.39%)
Mathlib.AlgebraicGeometry.Restrict -3.364⬝10⁹ (-2.69%)
Mathlib.Topology.Sheaves.CommRingCat -13.445⬝10⁹ (-16.18%)
2 files, Instructions -29.0⬝10⁹
File Instructions %
Mathlib.AlgebraicGeometry.Spec -28.225⬝10⁹ (-27.07%)
Mathlib.Geometry.RingedSpace.OpenImmersion -28.466⬝10⁹ (-10.07%)
File Instructions %
Mathlib.AlgebraicGeometry.AffineScheme -46.46⬝10⁹ (-18.30%)
Mathlib.AlgebraicGeometry.OpenImmersion -51.487⬝10⁹ (-40.99%)
Mathlib.Geometry.Manifold.Sheaf.Smooth -80.799⬝10⁹ (-42.95%)
Mathlib.AlgebraicGeometry.StructureSheaf -81.662⬝10⁹ (-32.63%)
CI run

@mattrobball
Copy link
Copy Markdown
Contributor

Net positive. I want to poke at the regressions but that can be done from master.

bors merge

@ghost ghost added the ready-to-merge This PR has been sent to bors. label Jan 27, 2025
mathlib-bors bot pushed a commit that referenced this pull request Jan 27, 2025
This is a step towards a concrete category redesign, as outlined in this Zulip post: https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Concrete.20category.20class.20redesign/near/493903980

This PR adds a `ConcreteCategory` instance for the categories of rings: `SemiRingCat`, `RingCat`, `CommSemiRingCat` and `CommRingCat`. It also replaces the `Hom.hom` structure projection with an alias for `ConcreteCategory.hom`. The latter requires a few fixes downstream where things get mistakenly unfolded (especially involving `ModuleCat.restrictScalars`) or where `rw` doesn't see through the definitional equality `ConcreteCategory.hom (ConcreteCategory.ofHom f) = f`. Finally, a few places where the proof works around the old `forget` <-> `FunLike` mismatch, and needs updating.

I have not tried to look for code that can be cleaned up now, only at what broke. I want to get started on cleanup when the other concrete category instances are in.



Co-authored-by: Anne Baanen <Vierkantor@users.noreply.github.com>
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Jan 27, 2025

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title feat(Algebra/Category): ConcreteCategory instances for rings [Merged by Bors] - feat(Algebra/Category): ConcreteCategory instances for rings Jan 27, 2025
@mathlib-bors mathlib-bors bot closed this Jan 27, 2025
@mathlib-bors mathlib-bors bot deleted the concrete-CommRingCat branch January 27, 2025 14:51
Julian added a commit that referenced this pull request Jan 28, 2025
* origin/master: (294 commits)
  feat: equalizers and coequalizers in the category of ind-objects (#21139)
  doc: turn more links to Stacks into `@[stacks]` tags (#21135)
  feat(Asymptotics): prove `IsLittleOTVS.add` (#20578)
  feat(Algebra/Polynomial): `Polynomial.aeval` for product algebras (#21062)
  chore: import Std in Mathlib.lean (#21126)
  feat(Data/Matroid/Circuit): fundamental circuits and extensionality  (#21145)
  feat(CategoryTheory/Endofunctor): prove the dual form of Lambek's Lemma on terminal coalgebra (#21140)
  feat(SetTheory/Game/PGame): rewrite left moves of `-x` as right moves of `x` under binders (#21109)
  feat(RingTheory/Localization/Pi): localization of a finite direct product is a product of localizations (#19042)
  doc: fixed notation error in customizing category composition (#21132)
  feat(Matrix): more lemmas for `PEquiv.toMatrix` (#21143)
  chore(SupIndep): speedup the `Decidable` instance (#21114)
  fix(CI): use `Elab.async=false` for late importers workflow (#21147)
  feat(Topology/Algebra/Indicator): indicator of a clopen is continuous (#20687)
  feat(Data/Matroid/Rank/Cardinal): Cardinality-valued rank function (#20921)
  feat(Algebra): `Pi.single_induction` (#21141)
  chore(BigOperators/Fin): golf a proof (#21131)
  feat: generalize tangent cone lemmas to TVS (#20859)
  feat(CategoryTheory): `Comma.snd L R` is final if `R` is final and domains are filtered (#21136)
  refactor: unapply matrix lemmas (#21091)
  chore(Algebra/Category): `erw` -> `rw` (#21130)
  feat(CategoryTheory): filteredness of Comma catgories given finality of one of the functors (#21128)
  feat(Algebra/Category): `ConcreteCategory` instance for `ModuleCat` (#21125)
  feat: PSum of finite sorts is finite (#20285)
  feat: inequality on the integral of a convex function of a RN derivative (#21093)
  feat: `(v +ᵥ s) -ᵥ (v +ᵥ t) = s -ᵥ t` (#21058)
  chore: rename the fact that `(∀ a < a₁, a ≤ a₂) ↔ a₁ ≤ a₂` in a dense order (#20317)
  feat: a `RelHom` preserves directedness (#20080)
  feat(Combinatorics/SimpleGraph): add definitions and theorems about the coloring of sum graphs (#18677)
  chore(Data/Matrix/PEquiv): clean up names (#21108)
  feat(Algebra/Category): `ConcreteCategory` instances for rings (#20815)
  feat: define Descriptive.Tree (#18763)
  chore(Data/Complex/Exponential): split trig functions to new file (#21075)
  feat(Logic/IsEmpty/Relator): empty on sides (#20319)
  feat(Algebra/Category): `ConcreteCategory` instance for `AlgebraCat` (#21121)
  feat(NumberTheory/LSeries): results involving partial sums of coefficients (part 1) (#20661)
  feat(RingTheory/LaurentSeries): add algebraEquiv (#21004)
  chore(SetTheory/Game/Impartial): golf two proofs (#21074)
  feat(CategoryTheory/Subpresheaf): preimage/image/range of subpresheaves (#21047)
  feat(RingTheory/IntegralClosure): `Algebra.IsIntegral` transfers via surjective homomorphisms (#21023)
  feat(`InformationTheory/Hamming`): Add AddGroup instances (#20994)
  feat(RingTheory/IntegralClosure): prove `Module.Finite R (adjoin R S)` for finite set `S` of integral elements (#20970)
  feat(RingTheory/Artinian): `IsUnit a` iff `a ∈ R⁰` for an artinian ring `R` (#21084)
  feat: separating set in the category of ind-objects (#21082)
  feat: derivWithin lemmas (#21092)
  chore(Fintype): golf a proof (#21113)
  chore: golf using `funext₂` (#21106)
  chore(Algebra/Group/Submonoid/Operations): move instances to new file (#21067)
  doc(Algebra/BigOperators/Fin): change 'product' to 'sum' in doc-string of additivised declarations (#21101)
  doc(ComputeDegree): typos (#21095)
  ...
Julian added a commit that referenced this pull request Feb 1, 2025
* polynomial-sequences: (308 commits)
  Use the lemma we already added.
  Minor reordering.
  This is true even for the trivial ring.
  Also add the lt versions and the other inj lemma.
  Also add the basis ne versions.
  This seems also like it should be simp.
  Back to sorry free.
  And the natDegree version.
  feat: equalizers and coequalizers in the category of ind-objects (#21139)
  doc: turn more links to Stacks into `@[stacks]` tags (#21135)
  feat(Asymptotics): prove `IsLittleOTVS.add` (#20578)
  feat(Algebra/Polynomial): `Polynomial.aeval` for product algebras (#21062)
  chore: import Std in Mathlib.lean (#21126)
  feat(Data/Matroid/Circuit): fundamental circuits and extensionality  (#21145)
  feat(CategoryTheory/Endofunctor): prove the dual form of Lambek's Lemma on terminal coalgebra (#21140)
  feat(SetTheory/Game/PGame): rewrite left moves of `-x` as right moves of `x` under binders (#21109)
  feat(RingTheory/Localization/Pi): localization of a finite direct product is a product of localizations (#19042)
  doc: fixed notation error in customizing category composition (#21132)
  feat(Matrix): more lemmas for `PEquiv.toMatrix` (#21143)
  chore(SupIndep): speedup the `Decidable` instance (#21114)
  fix(CI): use `Elab.async=false` for late importers workflow (#21147)
  feat(Topology/Algebra/Indicator): indicator of a clopen is continuous (#20687)
  feat(Data/Matroid/Rank/Cardinal): Cardinality-valued rank function (#20921)
  feat(Algebra): `Pi.single_induction` (#21141)
  chore(BigOperators/Fin): golf a proof (#21131)
  feat: generalize tangent cone lemmas to TVS (#20859)
  feat(CategoryTheory): `Comma.snd L R` is final if `R` is final and domains are filtered (#21136)
  refactor: unapply matrix lemmas (#21091)
  chore(Algebra/Category): `erw` -> `rw` (#21130)
  feat(CategoryTheory): filteredness of Comma catgories given finality of one of the functors (#21128)
  feat(Algebra/Category): `ConcreteCategory` instance for `ModuleCat` (#21125)
  feat: PSum of finite sorts is finite (#20285)
  feat: inequality on the integral of a convex function of a RN derivative (#21093)
  feat: `(v +ᵥ s) -ᵥ (v +ᵥ t) = s -ᵥ t` (#21058)
  chore: rename the fact that `(∀ a < a₁, a ≤ a₂) ↔ a₁ ≤ a₂` in a dense order (#20317)
  feat: a `RelHom` preserves directedness (#20080)
  feat(Combinatorics/SimpleGraph): add definitions and theorems about the coloring of sum graphs (#18677)
  chore(Data/Matrix/PEquiv): clean up names (#21108)
  feat(Algebra/Category): `ConcreteCategory` instances for rings (#20815)
  feat: define Descriptive.Tree (#18763)
  chore(Data/Complex/Exponential): split trig functions to new file (#21075)
  feat(Logic/IsEmpty/Relator): empty on sides (#20319)
  feat(Algebra/Category): `ConcreteCategory` instance for `AlgebraCat` (#21121)
  feat(NumberTheory/LSeries): results involving partial sums of coefficients (part 1) (#20661)
  feat(RingTheory/LaurentSeries): add algebraEquiv (#21004)
  chore(SetTheory/Game/Impartial): golf two proofs (#21074)
  feat(CategoryTheory/Subpresheaf): preimage/image/range of subpresheaves (#21047)
  feat(RingTheory/IntegralClosure): `Algebra.IsIntegral` transfers via surjective homomorphisms (#21023)
  feat(`InformationTheory/Hamming`): Add AddGroup instances (#20994)
  feat(RingTheory/IntegralClosure): prove `Module.Finite R (adjoin R S)` for finite set `S` of integral elements (#20970)
  ...
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-algebra Algebra (groups, rings, fields, etc) t-category-theory Category theory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants