Zulip Chat Archive

Stream: general

Topic: order on options


Simon Hudon (Sep 23 2018 at 04:05):

Is there an instance of decidable_linear_order on option in Mathlib or core? I can't find one

Kenny Lau (Sep 23 2018 at 04:13):

maybe with_bot has an order

Simon Hudon (Sep 23 2018 at 04:20):

Yes, it does, thanks! Now I'm stuck for a new reason: I don't have a decidable linear order for name (from the tactics). I think I'll need to write some of those orders myself

Mario Carneiro (Sep 23 2018 at 04:21):

There is an order on name, but it is meta and not an instance

Kenny Lau (Sep 23 2018 at 04:21):

does it need to be meta?

Mario Carneiro (Sep 23 2018 at 04:21):

no

Simon Hudon (Sep 23 2018 at 04:21):

Actually, I only need a decidable relation, not an order

Mario Carneiro (Sep 23 2018 at 04:21):

it has that already

Mario Carneiro (Sep 23 2018 at 04:22):

meta instance : decidable_rel name.lt :=
λ a b, ordering.decidable_eq _ _

meta instance : has_lt name :=
⟨name.lt⟩

Mario Carneiro (Sep 23 2018 at 04:22):

also relevant

/- Both cmp and lex_cmp are total orders, but lex_cmp implements a lexicographical order. -/
meta constant name.cmp : name → name → ordering
meta constant name.lex_cmp : name → name → ordering

Simon Hudon (Sep 23 2018 at 04:22):

The issue is that the order relation and its decidability for has_bot are wrapped up in order instances

Mario Carneiro (Sep 23 2018 at 04:23):

I guess we could generalize the definitions to has_le from has_le and has_lt from has_lt, without committing to any order properties

Simon Hudon (Sep 23 2018 at 04:24):

Exactly

Mario Carneiro (Sep 23 2018 at 04:25):

An easy fix is

meta instance : decidable_linear_order name :=
by refine {lt := (<), le := \lam a b, \neg b < a, ..}; exact undefined

Simon Hudon (Sep 23 2018 at 04:26):

That's evil

Kenny Lau (Sep 23 2018 at 04:26):

how exactly is undefined defined?

Mario Carneiro (Sep 23 2018 at 04:26):

undefined := undefined, effectively

Kenny Lau (Sep 23 2018 at 04:26):

then how does VM know what to do with #eval unchecked_cast?

Mario Carneiro (Sep 23 2018 at 04:26):

it's not really, because this causes loops instead of an error

Simon Hudon (Sep 23 2018 at 04:27):

@Mario Carneiro you may have a different opinion if you knew that this is for a mathlib PR

Mario Carneiro (Sep 23 2018 at 04:27):

name is basically meta. If a proof gets in your way, kill it

Mario Carneiro (Sep 23 2018 at 04:28):

As long as it's actually true

Mario Carneiro (Sep 23 2018 at 04:28):

or close enough to true that it doesn't matter

Mario Carneiro (Sep 23 2018 at 04:29):

We could write name.lt non-meta, but I would want to see what is the performance hit first

Simon Hudon (Sep 23 2018 at 04:33):

or close enough to true that it doesn't matter

I'm hesitant to agree because I see the type class constraint as a way the type system tells you to make sure you're satisfying assumptions and warning you when you break those assumptions. You write undefined and you lose all that information. Or rather, the type system tells you "all the assumptions are satisfied, no worries" when it might not be the case

Mario Carneiro (Sep 23 2018 at 04:41):

This is true, but meta code doesn't have these guarantees anyway, except in a vague sense

Mario Carneiro (Sep 23 2018 at 04:41):

A proof in meta land means something between "nothing at all" and "probably true"

Simon Hudon (Sep 23 2018 at 04:43):

As a comparison, that used to be my opinion of software testing until I started grading software assignment of students who often didn't bother testing. Yes, tested software is still imperfect but untested is so much worse

Mario Carneiro (Sep 23 2018 at 04:44):

right, which is why a meta proof can mean "probably true": the user had to make a conscious choice to either prove it or stub it out

Mario Carneiro (Sep 23 2018 at 04:45):

I liken it to the "preconditions" requirements in programs in Haskell or Java. It says "don't fail this requirement or else" and no compile or run time checking

Mario Carneiro (Sep 23 2018 at 04:46):

If you pass an order that is not linear to a function expecting one in the type, it's your fault if it breaks

Simon Hudon (Sep 23 2018 at 04:46):

I think comparing it the a quickcheck property would be closer to the truth, when you decide to write them, they nudge you in the right direction


Last updated: Dec 20 2023 at 11:08 UTC