Zulip Chat Archive

Stream: mathlib4

Topic: duplicate instances of `PosMulMono` and friends


Jovan Gerbscheid (Mar 20 2025 at 22:40):

I noticed that docs#PosMulMono.toCovariantClass and docs#PosMulMono.to_covariantClass_pos_mul_le are duplicates. One is declared with extends and the other with instance.

Should the extends be replaced with a def? (in #22090, it was changed from an abbrev to an extends by @Floris van Doorn)

Eric Wieser (Mar 20 2025 at 23:10):

Dropping the explicit instance one would be consistent with the goal of #22090

Jovan Gerbscheid (Mar 20 2025 at 23:13):

The goal of #22090 was to stop PosMulMono from unfolding into CovariantClass .. during type class search. This goal is also achieved if we use a def instead of an abbrev

Eric Wieser (Mar 20 2025 at 23:32):

I'm not sure there is any benefit to using a def though, usually we do that as a compromise when the class is too problematic

Eric Wieser (Mar 20 2025 at 23:32):

Here I think @Floris van Doorn forgot to clean up the duplicate when he introduces the extends instance

Jovan Gerbscheid (Mar 20 2025 at 23:33):

I think it's not his fault, because those duplicates were already unnecessary from the start.

Jovan Gerbscheid (Mar 20 2025 at 23:36):

Also I didn't realize it isn't possible to mark a def as a class, so keeping the extends instances is the way.

Eric Wieser (Mar 21 2025 at 00:04):

Jovan Gerbscheid said:

I think it's not his fault, because those duplicates were already unnecessary from the start.

I would guess then that actually that PR was unecessary (but perhaps a good idea anyway), and the performance issue is the instance you identified.

Jovan Gerbscheid (Mar 21 2025 at 00:08):

The performance issue was that CovariantClass α≥0 α (fun x y => y * x) (· ≤ ·) has bad discrimination tree keys, and this problem was definitely resolved by that PR.

Though there is a chance that removing these extra instances will also give a performace improvement.

Jovan Gerbscheid (Mar 21 2025 at 00:09):

(if I remember correctly)

Jovan Gerbscheid (Mar 21 2025 at 01:11):

Oh, one instance is talking about the type α≥0 and the other about α>0, my mistake.


Last updated: May 02 2025 at 03:31 UTC