Zulip Chat Archive
Stream: lean4
Topic: BEq Subtype
Marcus Rossel (Sep 01 2022 at 14:07):
Along the lines of Hashable Subtype, does anyone see any problems with this?:
instance [BEq α] {p : α → Prop} : BEq { a : α // p a } where
beq a₁ a₂ := BEq.beq a₁.val a₂.val
Jannis Limperg (Sep 01 2022 at 14:57):
(wrong topic, sorry)
Gabriel Ebner (Sep 01 2022 at 15:44):
The only issue I see is the potential diamond with these instances:
instance [DecidableEq α] : BEq α
instance {p : α → Prop} [DecidableEq α] : DecidableEq { a // p a }
Mario Carneiro (Sep 01 2022 at 15:48):
ugh, that seems like something we are going to have to deal with eventually by adding beq
as a field in DecidableEq
Mario Carneiro (Sep 01 2022 at 15:48):
either that or don't have the [DecidableEq α] : BEq α
instance
Gabriel Ebner (Sep 01 2022 at 15:53):
Dropping this instance is painful. Everything uses BEq
these days, List.contains
, Array.indexOf?
, you name it.
Mario Carneiro (Sep 01 2022 at 15:54):
I guess we want DecidableEq
to just be the same as LawfulBEq
then
Gabriel Ebner (Sep 01 2022 at 15:54):
Bingo! And we can also drop all of the compiler hacks that identify Decidable
and Bool
under the hood.
Mario Carneiro (Sep 01 2022 at 15:55):
Well, we still need that for other decidable things
Gabriel Ebner (Sep 01 2022 at 15:57):
Well, obviously Decidable
should be defined like this as well:
class Decidable (p : Prop) where
decide : Bool
decide_iff : decide ↔ p
Mario Carneiro (Sep 01 2022 at 16:10):
Oh, also with a slight change to the equality instance for bool we could make example (b : Bool) : decide b = b := rfl
work
Gabriel Ebner (Sep 01 2022 at 16:18):
Or with a change to the Bool
-to-Prop
coercion (coercing to true = b
instead of b = true
). I like the approach that Sebastian brought forward a while back of having a Bool.toProp
function (forgot about the details), which would mostly hide this implementation detail (of which way the equation is oriented).
Mario Carneiro (Sep 01 2022 at 16:18):
b = true
is good for rewrites though
Mario Carneiro (Sep 01 2022 at 16:19):
Bool.toProp
would be more in line with the lean 3 way I think
Gabriel Ebner (Sep 01 2022 at 16:19):
Although it's really awful for pretty-printing. We don't want to show all b = true
terms as ↑ b
or even b
. But we could unconditionally hide Bool.toProp b
.
Mario Carneiro (Sep 01 2022 at 16:20):
heh, this will break some recent simp lemmas I wrote that use b
instead of b = true
Mario Carneiro (Sep 01 2022 at 16:21):
well, maybe not if it's reducible
Gabriel Ebner (Sep 01 2022 at 16:29):
Either reducible, or with an extra simp lemma b → b = true
.
Mario Carneiro (Sep 01 2022 at 16:30):
the second option wouldn't work if your simp lemma itself is of type @[simp] theorem foo : toProp ... := ...
Mario Carneiro (Sep 01 2022 at 16:31):
but I'm also okay with declaring these as illegal simp lemmas and require writing them as b = true
Gabriel Ebner (Sep 01 2022 at 16:32):
simp only [foo, eq_true_of_toProp]
would still work. The extra lemma is conditional.
Gabriel Ebner (Sep 01 2022 at 16:32):
Oh, and looping..
Last updated: Dec 20 2023 at 11:08 UTC