Skip to content

[Merged by Bors] - refactor(Algebra/Category/Ring): make morphisms a structure#19757

Closed
chrisflav wants to merge 40 commits intomasterfrom
chrisflav-commringcat.2
Closed

[Merged by Bors] - refactor(Algebra/Category/Ring): make morphisms a structure#19757
chrisflav wants to merge 40 commits intomasterfrom
chrisflav-commringcat.2

Conversation

@chrisflav
Copy link
Copy Markdown
Member

@chrisflav chrisflav commented Dec 5, 2024

Following the pattern of #19065, we introduce a Hom structure for morphisms in SemiRingCat, CommSemiRingCat, RingCat and CommRingCat allowing for many simplified proofs and reducing the need of erw.

Besides the additional explicitness in form of ofHom and Hom.hom, the main regression is friction with the FunLike instance from the general ConcreteCategory API, causing the need for explicit rws between f.hom x and (forget RingCat).map f x. This regression can be fixed by replacing the general ConcreteCategory.instFunLike by a CoeFun (or FunLike) instance that is part of the ConcreteCategory data.

Co-authored-by: Anne Baanen anne@anne.mx


Open in Gitpod

@chrisflav chrisflav added WIP Work in progress t-category-theory Category theory t-algebra Algebra (groups, rings, fields, etc) labels Dec 5, 2024
@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 5, 2024

PR summary d16e6d6e6c

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ CommRingCat.forget_map_apply
+ RingCat.forget_map_apply
+ _root_.CommRingCat.germ_res_apply
+ _root_.CommRingCat.germ_res_apply'
+ _root_.CommRingCat.presheaf_restrict_restrict
+ _root_.RingEquiv.toCommRingCatIso
+ _root_.RingEquiv.toRingCatIso
+ appIso_inv_app_apply'
+ commRingCatIsoToRingEquiv_toRingHom
+ commSemiRingCatIsoToRingEquiv
+ commSemiRingCatIsoToRingEquiv_toRingHom
+ forgetToRingCat_map_hom
+ hasForgetToAddCommMonCat
+ instance (A : Under R) : Algebra R A := RingHom.toAlgebra A.hom.hom
+ instance (U) : Algebra (F.obj U) (G.localizationPresheaf.obj U)
+ instance (X : CommRingCat.{u}) : Unique (X ⟶ CommRingCat.of.{u} PUnit)
+ instance (X : TopCat.{v}ᵒᵖ) (R : TopCommRingCat.{v}) :
+ instance (x : PrimeSpectrum R) : IsLocalHom (localizationToStalk R x).hom
+ instance (x : PrimeSpectrum R) : IsLocalHom (stalkToFiberRingHom R x).hom
+ instance (x) : IsLocalHom (f.stalkMap x).hom
+ instance : Category BoolRing
+ instance : Category CommRingCat
+ instance : Category CommSemiRingCat
+ instance : Category RingCat
+ instance : Category SemiRingCat
+ instance : CoeSort (CommRingCat) (Type u)
+ instance : CoeSort (CommSemiRingCat) (Type u)
+ instance : CoeSort (RingCat) (Type u)
+ instance : CoeSort (SemiRingCat) (Type u)
+ instance : ConcreteCategory BoolRing
+ instance : ConcreteCategory.{u} CommRingCat
+ instance : ConcreteCategory.{u} CommSemiRingCat
+ instance : ConcreteCategory.{u} RingCat
+ instance : ConcreteCategory.{u} SemiRingCat
+ instance : HasAffineProperty @IsFinite
+ instance : IsLocalHom (equalizerFork f g).ι.hom := by
+ instance {R : CommRingCat} : CommRing ((forget CommRingCat).obj R)
+ instance {R : CommSemiRingCat} : CommSemiring ((forget CommSemiRingCat).obj R)
+ instance {R : RingCat} : Ring ((forget RingCat).obj R)
+ instance {R : SemiRingCat} : Semiring ((forget SemiRingCat).obj R)
+ instance {R : Type u} [BooleanRing R] :
+ instance {R S : CommRingCat.{u}} : CoeFun (R ⟶ S) (fun _ ↦ R → S)
+ instance {R S : CommRingCat} (e : R ≅ S) : IsLocalHom e.hom.hom
+ 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)
+ instance {X : LocallyRingedSpace.{u}} : Unique (∅ ⟶ X)
+ isLocalHom_stalkClosedPointTo'
+ localRingHom_comp_stalkIso_apply'
+ restrictOpenCommRingCat
+ restrictOpenCommRingCat_apply
+ ringCatIsoToRingEquiv_toRingHom
+ semiRingCatIsoToRingEquiv
+ semiRingCatIsoToRingEquiv_toRingHom
++ forgetReflectIsos
++++ hom_comp
++++ hom_id
++++ hom_inv_apply
++++ hom_ofHom
++++ inv_hom_apply
++++ ofHom_comp
++++ ofHom_hom
++++ ofHom_id
++++ of_carrier
+++++ Hom
+++++ hom_ext
+++++---- ofHom
+++++----- of
++++- comp_apply
++++- forget_obj
++++---- coe_of
++++---- forget_map
++++---- ofHom_apply
++-- coconeMorphism
++-- descMorphism
+-+++ id_apply
- AssocRingHom
- CommRingCat.comp_eq_ring_hom_comp
- CommRingCat.forget_reflects_isos
- CommRingCat.ringHom_comp_eq_comp
- RingCat.forget_reflects_isos
- RingHom.comp_id_commRingCat
- RingHom.comp_id_commSemiringCat
- RingHom.comp_id_ringCat
- RingHom.comp_id_semiringCat
- RingHom.id_commRingCat_comp
- RingHom.id_commSemiringCat_comp
- RingHom.id_ringCat_comp
- RingHom.id_semiringCat_comp
- bundledHom
- commRingIsoToRingEquiv_apply
- commRingIsoToRingEquiv_symm_apply
- commRingIsoToRingEquiv_symm_toRingHom
- commRingIsoToRingEquiv_toRingHom
- forgetToRingCat_map_apply
- hasForgetToCommSemiRingCat
- instCommRing
- instCommRing'
- instCommSemiring
- instCommSemiring'
- instFunLike'
- instFunLike''
- instFunLike'''
- instRing
- instSemiring
- instance (A : Under R) : Algebra R A := RingHom.toAlgebra A.hom
- instance (R : CommRingCat) : CommRing R
- instance (R : CommSemiRingCat) : CommSemiring R
- instance (R : RingCat) : Ring R
- instance (U) : Algebra ((forget CommRingCat).obj (F.obj U)) (G.localizationPresheaf.obj U)
- instance (X : BoolRing) : BooleanRing X
- instance (X : CommSemiRingCat) : CommSemiring X := X.str
- instance (X : RingCat) : Ring X := X.str
- instance (priority := 50) {R : CommRingCat} {S : Type*} [CommRing S] (f : R ⟶ CommRingCat.of S)
- instance (priority := 50) {R : Type*} [CommRing R] {S : CommRingCat} (f : CommRingCat.of R ⟶ S)
- instance (priority := 50) {R S : Type u} [CommRing R] [CommRing S]
- instance (x : PrimeSpectrum R) : IsLocalHom (localizationToStalk R x)
- instance (x : PrimeSpectrum R) : IsLocalHom (stalkToFiberRingHom R x)
- instance (x) : IsLocalHom (f.stalkMap x)
- instance : (forget₂ CommRingCat CommSemiRingCat).Full where map_surjective f := ⟨f, rfl⟩
- instance : BundledHom.ParentProjection @BooleanRing.toCommRing
- instance : BundledHom.ParentProjection @CommRing.toRing
- instance : BundledHom.ParentProjection @CommSemiring.toSemiring
- instance : BundledHom.ParentProjection @Ring.toSemiring
- instance : CoeSort CommSemiRingCat Type*
- instance : ConcreteCategory BoolRing := by
- instance : ConcreteCategory CommSemiRingCat := by
- instance : HasAffineProperty @IsFinite (fun X _ f _ ↦ IsAffine X ∧ RingHom.Finite (f.appTop)) := by
- instance : IsLocalHom (equalizerFork f g).ι := by
- instance {R S : CommRingCat} (f : R ⟶ S) [IsLocalHom f] :
- instance {X : LocallyRingedSpace} : Unique (∅ ⟶ X)
- ringEquivIsoCommRingIso
- ringEquivIsoRingIso
- toCommRingCatIso
- toRingCatIso
-+-+ hasForgetToSemiRingCat
---- RingEquiv_coe_eq
---- coe_comp
---- coe_comp_of
---- coe_comp_of'
---- coe_id_of
---- coe_ringHom_id
---- ext
---- ext_of
---- instFunLike
---- instRingHomClass
---- ofHom_apply'
----+ coe_id

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) = (3.22, 0.02)
Current number Change Type
4888 -25 porting notes
201 -1 disabled simpNF lints
1485 -13 erw

Current commit d16e6d6e6c
Reference commit bfdd6039bf

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

@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 Dec 9, 2024
@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 Dec 10, 2024
@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 Dec 10, 2024
Copy link
Copy Markdown
Contributor

@Vierkantor Vierkantor left a comment

Choose a reason for hiding this comment

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

Okay, I think we're ready for review! Kim said they'd like to take a look a look at this, so I'll contact them if you're happy too :)

@chrisflav chrisflav removed the WIP Work in progress label Dec 10, 2024
@jcommelin
Copy link
Copy Markdown
Member

!bench

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit 252f33a.
There were significant changes against commit bfdd603:

  Benchmark                                                    Metric         Change
  ==================================================================================
+ ~Mathlib.Algebra.Category.AlgebraCat.Basic                   instructions   -25.3%
+ ~Mathlib.Algebra.Category.ModuleCat.Differentials.Presheaf   instructions   -16.9%
+ ~Mathlib.Algebra.Category.ModuleCat.Presheaf                 instructions    -9.8%
+ ~Mathlib.Algebra.Category.Ring.Limits                        instructions   -17.9%
+ ~Mathlib.AlgebraicGeometry.AffineScheme                      instructions   -14.2%
+ ~Mathlib.AlgebraicGeometry.AffineSpace                       instructions    -6.6%
+ ~Mathlib.AlgebraicGeometry.GammaSpecAdjunction               instructions   -39.5%
+ ~Mathlib.AlgebraicGeometry.Morphisms.QuasiSeparated          instructions   -23.3%
+ ~Mathlib.AlgebraicGeometry.Scheme                            instructions   -12.5%
+ ~Mathlib.AlgebraicGeometry.Stalk                             instructions   -35.8%
+ ~Mathlib.AlgebraicGeometry.ValuativeCriterion                instructions   -18.8%
+ ~Mathlib.Geometry.RingedSpace.OpenImmersion                  instructions    -4.9%
- ~Mathlib.Topology.Sheaves.CommRingCat                        instructions    23.6%

Comment on lines -182 to +187
{ (SemiRingCat.FilteredColimits.colimitCocone
(F ⋙ forget₂ CommSemiRingCat SemiRingCat.{max v u})).ι with }
{ app := fun X ↦ ofHom <| ((SemiRingCat.FilteredColimits.colimitCocone
(F ⋙ forget₂ CommSemiRingCat SemiRingCat.{max v u})).ι.app X).hom
naturality := fun _ _ f ↦ hom_ext <|
RingHom.coe_inj ((Types.TypeMax.colimitCocone
(F ⋙ forget CommSemiRingCat)).ι.naturality f) }
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.

Hmm, this seems unfortunate.

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.

Can we provide a function for this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am afraid, I don't understand. This worked before, because it abused the def-eq of morphisms in CommSemiRingCat and SemiRingCat. Do you suggest to add some general construction for (C : Type*) [Category C] [ConcreteCategory C] [HasForget_2 C SemiRingCat]?

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.

Yes, I guess so. I was imagining something that can take a natural transformation, unwrap it and apply hom to the morphism, and hom_ext to the naturality condition, and put it back together. But I didn't think to hard about whether there is a type signature that makes sense. :-)

Comment on lines -245 to +253
{ (SemiRingCat.FilteredColimits.colimitCocone
(F ⋙ forget₂ RingCat SemiRingCat.{max v u})).ι with }
{ app := fun X ↦ ofHom <| ((SemiRingCat.FilteredColimits.colimitCocone
(F ⋙ forget₂ RingCat SemiRingCat.{max v u})).ι.app X).hom
naturality := fun _ _ f ↦ hom_ext <|
RingHom.coe_inj ((Types.TypeMax.colimitCocone (F ⋙ forget RingCat)).ι.naturality f) }
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.

ditto here

@kim-em
Copy link
Copy Markdown
Contributor

kim-em commented Dec 12, 2024

Okay, I'm happy to proceed here as is. We still have a ways to go, I guess, but this is a forward step and we might as well have it in now.

bors d+

@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Dec 12, 2024

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

@ghost ghost added the delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). label Dec 12, 2024
@chrisflav
Copy link
Copy Markdown
Member Author

Then lets merge this before it starts rotting.

bors merge

mathlib-bors bot pushed a commit that referenced this pull request Dec 13, 2024
Following the pattern of #19065, we introduce a `Hom` structure for morphisms in `SemiRingCat`, `CommSemiRingCat`, `RingCat` and `CommRingCat` allowing for many `simp`lified proofs and reducing the need of `erw`.

Besides the additional explicitness in form of `ofHom` and `Hom.hom`, the main regression is friction with the `FunLike` instance from the general `ConcreteCategory` API, causing the need for explicit `rw`s between `f.hom x` and `(forget RingCat).map f x`. This regression can be fixed by replacing the general `ConcreteCategory.instFunLike` by a `CoeFun` (or `FunLike`) instance that is part of the `ConcreteCategory` data.

Co-authored-by: Anne Baanen <anne@anne.mx>



Co-authored-by: Anne C.A. Baanen <vierkantor@vierkantor.com>
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Dec 13, 2024

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title refactor(Algebra/Category/Ring): make morphisms a structure [Merged by Bors] - refactor(Algebra/Category/Ring): make morphisms a structure Dec 13, 2024
@mathlib-bors mathlib-bors bot closed this Dec 13, 2024
@mathlib-bors mathlib-bors bot deleted the chrisflav-commringcat.2 branch December 13, 2024 14:19
Vierkantor added a commit that referenced this pull request Dec 19, 2024
(Everything below is written for `CommRingCat`, but also holds for the other `RingCat`s.)

As a consequence of #19757, it became harder to unify `(forget ?C).obj R =?= CommRingCat.carrier R` since `?C =?= CommRingCat` would no longer be inferred. This PR adds a unification hint that helps with all but 2 cases where we need to hint `C := CommRingCat`.

The current unification hint uses `CommRingCat` as the argument to `forget`, even though we would like it to be an arbitrary category `C`, which can then trigger downstream unification of `C =?= CommRingCat`. However, it seems that dependent unification hints do not work: I cannot get Lean to typecheck `C =?= CommRingCat; (instC : Category C) =?= CommRingCat.instCategory |- ...`.

I tried doing this for `ModuleCat` too and it did not seem to fix any required hints. Perhaps because `ModuleCat R` depends on the `R`?
Vierkantor added a commit that referenced this pull request Jan 6, 2025
(Everything below is written for `CommRingCat`, but also holds for the other `RingCat`s.)

As a consequence of #19757, it became harder to unify `(forget ?C).obj R =?= CommRingCat.carrier R` since `?C =?= CommRingCat` would no longer be inferred. This PR adds a unification hint that helps with all but 2 cases where we need to hint `C := CommRingCat`.

The current unification hint uses `CommRingCat` as the argument to `forget`, even though we would like it to be an arbitrary category `C`, which can then trigger downstream unification of `C =?= CommRingCat`. However, it seems that dependent unification hints do not work: I cannot get Lean to typecheck `C =?= CommRingCat; (instC : Category C) =?= CommRingCat.instCategory |- ...`.

I tried doing this for `ModuleCat` too and it did not seem to fix any required hints. Perhaps because `ModuleCat R` depends on the `R`?
mathlib-bors bot pushed a commit that referenced this pull request Jan 13, 2025
…#20075)

(Everything below is written for `CommRingCat`, but also holds for the other `RingCat`s.)

As a consequence of #19757, it became harder to unify `(forget ?C).obj R =?= CommRingCat.carrier R` since `?C =?= CommRingCat` would no longer be inferred. This PR adds a unification hint that helps with all but 2 cases where we need to hint `C := CommRingCat`.

The current unification hint uses `CommRingCat` as the argument to `forget`, even though we would like it to be an arbitrary category `C`, which can then trigger downstream unification of `C =?= CommRingCat`. However, it seems that dependent unification hints do not work: I cannot get Lean to typecheck `C =?= CommRingCat; (instC : Category C) =?= CommRingCat.instCategory |- ...`.

I tried doing this for `ModuleCat` too and it did not seem to fix any required hints. Perhaps because `ModuleCat R` depends on the `R`?
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) t-category-theory Category theory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants