Zulip Chat Archive

Stream: mathlib4

Topic: ConcreteCategory.instFunLike became a global instance


Kim Morrison (May 23 2024 at 13:32):

During the port we accidentally made ConcreteCategory.instFunLike a global instance in Mathlib/Topology/Category/TopCat/Basic.lean:

-- Porting note: cannot find a coercion to function otherwise
attribute [instance] ConcreteCategory.instFunLike in
instance (X Y : TopCat.{u}) : CoeFun (X  Y) fun _ => X  Y where
  coe f := f

Despite the in, this makes it a global instance (we desperately need a linter for this!!!).

Kim Morrison (May 23 2024 at 13:33):

I've started to try to fix this on branch#TopCat_cleanup2, but there's still a lot that is broken.

Kim Morrison (May 23 2024 at 13:33):

Advice welcome. :-)

Kim Morrison (May 23 2024 at 13:34):

(There appears to be only one other such case, in src#ExteriorAlgebra.GradedAlgebra.ι_sq_zero, which is trivially fixed in #13144.)

Dagur Asgeirsson (May 24 2024 at 09:35):

@Kim Morrison I just filled in the sorry in TopCat/Limits/Products and pushed it to your branch

Dagur Asgeirsson (May 24 2024 at 09:36):

Looking at the pullback file now

Kim Morrison (May 24 2024 at 09:43):

Thanks! I was wondering about asking you, as you are very much working downstream of this problem!

Dagur Asgeirsson (May 24 2024 at 10:01):

Pullback file is error-free now as well. The problem seems to be that there are some lemmas that simp isn't seeing, such as docs#CategoryTheory.comp_apply, and I had to use erw instead

Dagur Asgeirsson (May 24 2024 at 10:04):

In many of the CompHaus-related files, you've added the line

attribute [local instance] ConcreteCategory.instFunLike -- TODO remove this?

and everything works. Is this bad? I mean, would it be better to refactor the files to not use this instance?

Kim Morrison (May 24 2024 at 10:35):

Yes, it would be better.

Kim Morrison (May 24 2024 at 10:35):

But it's better than the current situation where we accidentally made it global.

Dagur Asgeirsson (May 24 2024 at 10:36):

Kim Morrison said:

Yes, it would be better.

Why is that better?

Kim Morrison (May 24 2024 at 10:37):

Hmm... Let me think on that one. I agree it is not obvious that wanting to turn off the global instance implies we should not want to use it locally either.

Kim Morrison (May 24 2024 at 10:38):

Is this branch building now? If so I think we should PR it. We can either just remove the -- TODO remove this? comments,

Kim Morrison (May 24 2024 at 10:38):

or change the comment too -- Previously, this had accidentally been made a global instance, and we now turn it on locally as convenient.

Dagur Asgeirsson (May 24 2024 at 10:40):

No there are still lots of new files with errors appearing in CI after every fix. There are some in Topology/Gluing which aren't fixed by adding the local instance. I'm not very familiar with the API so I'm having trouble fixing that one.

Kim Morrison (May 24 2024 at 10:43):

I wonder if we can tempt @Andrew Yang into having a look. I think cleaning up the basic setup of TopCat is going to be key to resolving the suffering in AG at present.

Dagur Asgeirsson (May 24 2024 at 10:59):

TopCat.pullbackIsoProdSubtype_inv_fst_apply and the snd version are simp lemmas that are frequently failing and I have to use erw instead. Any idea why this might be?

Kim Morrison (May 24 2024 at 11:22):

Can you see if they work with simp (config := {index := false})?

Kim Morrison (May 24 2024 at 11:22):

Oh, hrm, that is only available on nightly-testing.

Kim Morrison (May 24 2024 at 11:24):

The problem is going to be that some implicit argument (e.g. of TopCat.of (X : TopCat)) has dsimp'd "the wrong amount". It may be that going into those lemmas that aren't firing and putting no_index in front of some of the implicit arguments will help. But it's a pretty manual/painful process to discover if anything helps.

Dagur Asgeirsson (May 24 2024 at 11:42):

Dagur Asgeirsson said:

No there are still lots of new files with errors appearing in CI after every fix. There are some in Topology/Gluing which aren't fixed by adding the local instance. I'm not very familiar with the API so I'm having trouble fixing that one.

I managed to fix the gluing file after all

Andrew Yang (May 24 2024 at 11:50):

I just got home. Is there anything (maybe a problematic file?) I could help?

Dagur Asgeirsson (May 24 2024 at 12:03):

I just pushed a commit fixing the last two files with errors in CI. You can see if there are other files with errors after CI runs on the latest commit, I'm taking a break now

Andrew Yang (May 24 2024 at 12:56):

Some rw errors come from the fact that there are two funlike instances on homs in TopCat.
I think making ConcreteCategory.hasCoeToSort and ConcreteCategory.instFunLike fields of ConcreteCategory might solve some of the problems we are facing?

Matthew Ballard (May 24 2024 at 12:59):

Can't you get rid of one?

Andrew Yang (May 24 2024 at 13:00):

One is precisely ConcreteCategory.instFunLike, which is the reason why it cannot be a global instance.

Andrew Yang (May 24 2024 at 13:01):

But even if it is not a global instance, it makes applying general lemmas about concrete categories (where this instance is on) difficult.

Kim Morrison (May 24 2024 at 13:01):

Yes, it was while trying to get rid of this duplication that I noticed we had accidentally made ConcreteCategory.instFunLike a global instance.

Andrew Yang (May 24 2024 at 13:05):

Something like

class ConcreteCategory (C : Type u) [Category.{v} C] where
  hasCoeSort : CoeSort C (Type w)
  funLike :  X Y : C, FunLike (X  Y) X Y
  map_id :  X : C, (𝟙 X : X  X) = id
  map_comp :  {X Y Z} (f : X  Y) (g : Y  Z), (f  g : X  Z) = g  f
  map_injective :  {X Y} {f f' : X  Y} (e : (f : X  Y) = (f' : X  Y)), f = f'

Kim Morrison (May 24 2024 at 13:07):

I think this is going to be a pretty radical change. I'm not saying I'm against it, but I think life we be easier if we make the existing concrete categories more uniform first, and than try changes like this.

Andrew Yang (May 24 2024 at 13:24):

Maybe docs#ConcreteCategory.hasCoeToSort should be reducible?

Matthew Ballard (May 24 2024 at 13:27):

Not sure but worth a shot.

Dagur Asgeirsson (May 24 2024 at 13:40):

Kim's branch is now PR #13170. I'm expecting everything to build now, but I don't know if we want to merge this and then do some more radical refactor of concrete categories, or the other way around

Matthew Ballard (May 24 2024 at 13:41):

We should at least mark the erw regressions with an identifier (eg issue) so we can rip them all out with a fix

Dagur Asgeirsson (May 24 2024 at 13:43):

Ok that makes sense. At least all the errors are gone now

Dagur Asgeirsson (May 24 2024 at 13:43):

I don't have more time for this today unfortunately

Kim Morrison (May 24 2024 at 13:58):

Thanks very much for the help on this. I was starting to get intimidated by the problems in ConcreteCategory land, so I'm excited to see everyone is interested! I think we should merge this, and then start experimenting with deeper fixes.

Matthew Ballard (May 24 2024 at 17:04):

It builds now. The PR number is attached as tracker. Benchmarking is in progress.

My choice of linting was to delete a few simp's so I cannot call bors

Matthew Ballard (May 24 2024 at 17:06):

-162B

Andrew Yang (May 24 2024 at 18:14):

Andrew Yang said:

Something like

class ConcreteCategory (C : Type u) [Category.{v} C] where
  hasCoeSort : CoeSort C (Type w)
  funLike :  X Y : C, FunLike (X  Y) X Y
  map_id :  X : C, (𝟙 X : X  X) = id
  map_comp :  {X Y Z} (f : X  Y) (g : Y  Z), (f  g : X  Z) = g  f
  map_injective :  {X Y} {f f' : X  Y} (e : (f : X  Y) = (f' : X  Y)), f = f'

For the record, this does not work. If we have instance : CoeSort (Bundled c) (Type w) = ⟨Bundled.α⟩, then for X : Bundled c, X : Type w will (reducibly) become Bundled.α X, but via the instance in ConcreteCategory it is CoeSort.coe X, and they are not reducibly equal.

Michael Rothgang (May 24 2024 at 23:52):

I wrote a syntax linter for this, in #13190. Careful review by something whose meta skills are less cargo-culted than mine welcome.

Kim Morrison (May 26 2024 at 14:03):

Okay, shall we merge this? Obviously the additional erws are sad, but I think this is a case where we have to go backwards in order to go forwards.

Dagur Asgeirsson (May 27 2024 at 08:50):

I merged master to get rid of a merge conflict -- should be good to go (it builds, but CI is still linting)

Dagur Asgeirsson (May 27 2024 at 14:34):

We should probably try to merge this pretty quickly, I've just fixed another merge conflict (awaiting CI)

Kevin Buzzard (May 27 2024 at 17:38):

I made a bunch of pernickety comments but I agree that if we're merging this then it should be merged quickly!


Last updated: May 02 2025 at 03:31 UTC