Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Algebra/Category): ConcreteCategory instances for rings #20815

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Vierkantor
Copy link
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

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 basic support for `ConcreteCategory` to the `elementwise` attribute and elaborator: it still uses `HasForget` when a fresh instance is needed, but now will replace the `forget`-based operations with `ConcreteCategory`-based ones. So as long as there is only a `HasForget` instance, or no instance at all, in scope, `elementwise` will behave the same. But when there is a `ConcreteCategory` instance, all the `(forget C).obj X`es turn into `ToType X` and `(forget C).map f`s turn into `hom f`.

In the future, when we have replaced enough `HasForget` instances with `ConcreteCategory`, we can apply the changes from the branch `redesign-ConcreteCategory` to make `elementwise` use `ConcreteCategory` when it creates fresh instances.
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 added t-category-theory Category theory t-algebra Algebra (groups, rings, fields, etc) labels Jan 17, 2025
Copy link

github-actions bot commented Jan 17, 2025

PR summary b0815d4c32

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ bar
+ bar'
+ bar''
+ bar'''
+ coe_toHasForget_instFunLike
+ ex1
+ ex2
+ ex3
+ f
+ fh
+ foo
+ foo'
+ g
+ gh
+ h
+ 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.


Increase in tech debt: (relative, absolute) = (0.98, 0.08)
Current number Change Type
4618 3 porting notes
1412 -2 erw
12 1 maxHeartBeats modifications

Current commit b0815d4c32
Reference commit 9ca037a451

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

@@ -787,6 +787,7 @@ theorem self_le_basicOpen_union_iff (s : Set Γ(X, U)) :

end IsAffineOpen

set_option maxHeartbeats 400000 in
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This proof needs heavy cleanup, specifically it seems we should get rid of the second show statement, but I couldn't figure out how to get that done...

@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 the blocked-by-other-PR This PR depends on another PR to Mathlib (this label is automatically managed by a bot) label Jan 17, 2025
@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot removed the blocked-by-other-PR This PR depends on another PR to Mathlib (this label is automatically managed by a bot) label Jan 17, 2025
@mathlib4-dependent-issues-bot
Copy link
Collaborator

@mattrobball
Copy link
Collaborator

!bench

@leanprover-bot
Copy link
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%

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-wanted The author needs attention to resolve issues 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.

4 participants