Zulip Chat Archive

Stream: mathlib4

Topic: remove decidable fields from LinearOrder?


Matthew Ballard (Feb 26 2025 at 14:30):

Splitting off the discussion from #mathlib4 > set_option maxSynthPendingDepth 2 about this since there appears to be support on both sides of the question.

It might be too early for a poll but please register your sentiments about dropping the Decidable fields from LinearOrder.

Matthew Ballard (Feb 26 2025 at 14:30):

Personally I also found this strange compared to the rest of mathlib when I first encountered it. I would lean yes

Eric Wieser (Feb 26 2025 at 14:37):

I don't think "strange" is that good a reason; Field.nnqsmul is certainly also strange, but it is also useful!

Eric Wieser (Feb 26 2025 at 14:39):

I think your this proposal would amount to replacing

variable [LinearOrder X]

with

variable [LinearOrder X]
variable [Ord X] [DecidableEq X] [DecidableLT X] [DecidableLE X] [Batteries.LawfulOrd X]

which is rather a mouthful

Matthew Ballard (Feb 26 2025 at 14:43):

Perhaps "inconsistent" is better language. I hesitate to call this "mine" :) The previous thread had people responding with exclamation points! and did have an actual problem that was currently hidden under the cutoff for depth.

I really just want people to convince me one way or the other while I focus on grading for bit. But I do think further discussion is merited either way.

Eric Wieser (Feb 26 2025 at 14:46):

I think the actuall problem was a weird typeclass argument, not the fields within LinearOrder. I think pulling decidable fields out of LinearOrder is likely to increase the prevalence of such weird arguments (chosen from the mouthful above)

Matthew Ballard (Feb 26 2025 at 14:46):

Certainly a mouthful of typeclass assumptions is a solid reason against

Matthew Ballard (Feb 26 2025 at 14:47):

But we already have default values for some don't we?

Eric Wieser (Feb 26 2025 at 14:47):

I think splitting it also means we need to re-separate min and inf

Eric Wieser (Feb 26 2025 at 14:47):

Otherwise either docs#minOfLe creates an instance diamond, or we still need all the decidable instances to define LinearOrder anyway

Eric Wieser (Feb 26 2025 at 14:49):

Matthew Ballard said:

But we already have default values for some don't we?

We already have default values for the fields in LinearOrder. Did you mean default instances? I think default Decidable instances is just reverting back to the (global) open scoped Classical approach that we've moved away from

Kevin Buzzard (Feb 26 2025 at 20:11):

that we've moved away from

...and for good reason, as it used to cause diamonds when Lean found the actual decidable order instances on e.g. Nat. So this is where it differs from the [DecidableEq (Ideal R)] situation where there are literally no instances in mathlib.

Martin Dvořák (Feb 27 2025 at 17:46):

Eric Wieser said:

I don't think "strange" is that good a reason; Field.nnqsmul is certainly also strange, but it is also useful!

It is a good reason. If possible, we should avoid "strange things" in definitions. Imagine somebody comes with a new shiny theorem about linear orders. Whoëver comes to check whether the theorem holds really for all linear orders will be puzzled with the complicated definition, making them wonder whether some linear orders (according to their personal understanding of what linear order is) are excluded. In my case, I have struggled both with nnqsmul and with what OP mentions.

However, I also understand the reasons why it shouldn't be changed.

Jireh Loreaux (Feb 27 2025 at 18:46):

1 / 0 = 0 is strange to many mathematicians, and we could avoid it. But we don't because strange is not the primary metric we should minimize / optimize for. It's much more useful to allow 1 / 0 = 0.

Martin Dvořák (Feb 27 2025 at 21:26):

Philosophically, it is the same kind of issue, but in practice, division by zero has different trade-offs.

Jovan Gerbscheid (Mar 14 2025 at 19:11):

Could there be some comment at LinearOrder explaining why these fields are there?

I think the mouthful of typeclass assumptions isn't a good objection, because we can define ComputableLinearOrder to extend LinearOrder and also contain all of [Ord X] [DecidableEq X] [DecidableLT X] [DecidableLE X] [Batteries.LawfulOrd X].

Eric Wieser (Mar 14 2025 at 23:36):

Certainly we should document the status quo

Eric Wieser (Mar 14 2025 at 23:39):

I think if you had that second typeclass, you'd just annoy a bunch of mathematicians who don't like typing the word "computable" because they don't care about it, and then mathlib would end up being less computable as a result.

Eric Wieser (Mar 14 2025 at 23:40):

Which is a loss both for the mathematicians who were made to think about it more than they currently do, and a loss for the people who like using #eval.

Yury G. Kudryashov (Mar 15 2025 at 05:18):

Note: we had linear_order and decidable_linear_order in Lean 3, then decided to merge them.

Yury G. Kudryashov (Mar 15 2025 at 05:18):

Semi-offtopic: I think that default fields is a footgun. IMHO, we should use something like ofMinimalAxioms instead.

Yury G. Kudryashov (Mar 15 2025 at 05:20):

BTW, doesn't docs#minOfLe create a diamon for Min (Nat × Nat)?

Jovan Gerbscheid (Mar 15 2025 at 09:16):

Yes, it does:

import Mathlib

#eval min (0,1) (1,0) -- (0,0)

attribute [instance high] minOfLe

#eval min (0,1) (1,0) -- (1,0)

Jovan Gerbscheid (Mar 15 2025 at 09:18):

I think nobody would ever use minOfLe on Nat × Nat, because it only really makes sense on a linear order, while × is given the pairwise order.

Yury G. Kudryashov (Mar 15 2025 at 16:58):

Is it possible that someone will use it by accident?

Yury G. Kudryashov (Mar 15 2025 at 16:59):

(probably, yes, but how easy is to shoot yourself in the foot with this?)

Jovan Gerbscheid (Mar 15 2025 at 17:00):

It's not an instance, so I don't think so.

Yury G. Kudryashov (Mar 15 2025 at 17:00):

Ah, indeed!

Kevin Buzzard (Mar 15 2025 at 17:01):

Aha, so it's on a par with that non-instance which makes ARBA\otimes_R B into a BB-algebra, which gives a diamond if A=BA=B.


Last updated: May 02 2025 at 03:31 UTC