Zulip Chat Archive
Stream: Is there code for X?
Topic: List/BEq diamond
Heather Macbeth (Dec 31 2023 at 17:49):
Couldn't find something like this in the library ... did I miss it?
theorem beq_list_diamond [DecidableEq α] (l1 l2 : List α) :
decide (l1 = l2) = List.beq l1 l2 := by
sorry
Yury G. Kudryashov (Dec 31 2023 at 17:55):
AFAIR, there were plans to redefine docs#Decidable to prevent diamonds like this (going from a boolean to Decidable
and back again is not defeq). I don't know what happened to these plans.
Eric Wieser (Dec 31 2023 at 17:56):
I think the plans were Gabriel's, and MSR losing interest in Lean seems to have caused them to go on hold
Eric Wieser (Dec 31 2023 at 17:56):
lean4#2038 has a trial implementation
Yury G. Kudryashov (Dec 31 2023 at 18:14):
That's a huge diff
Yury G. Kudryashov (Dec 31 2023 at 19:12):
@Gabriel Ebner Do you plan working on lean4#2038? If not, then I'll see if I can pick it up next week.
Kyle Miller (Dec 31 2023 at 19:20):
@Yury G. Kudryashov Something I noticed and mentioned in this PR comment is that there seems to be a lower-impact change to Decidable
(and one that seems to have nicer definitional equalities). I got as far as seeing it'll take also looking through assumptions about Decidable
that are hard-coded into the compiler.
Here's the possible re-definition reproduced here:
class Decidable (p : Prop) where
/-- The truth value of the proposition `p` as a `Bool`.
If `true` then `p` is true, and if `false` then `p` is false. -/
decide : Bool
/-- `decide p` evaluates to the Boolean `true` if and only if `p` is a true proposition. -/
cond_decide : cond decide p (Not p)
/-- Prove that `p` is decidable by supplying a proof of `p` -/
@[match_pattern] def Decidable.isTrue {p : Prop} (h : p) : Decidable p where
decide := true
cond_decide := h
/-- Prove that `p` is decidable by supplying a proof of `¬p` -/
@[match_pattern] def Decidable.isFalse {p : Prop} (h : Not p) : Decidable p where
decide := false
cond_decide := h
Kyle Miller (Dec 31 2023 at 19:24):
I'm not sure where adjusting Decidable
is on the Lean roadmap. It would be good figuring that out before you spend a lot of time on this -- though if it can be carried out in a low-impact way without a huge diff, that would be great to know.
Henrik Böving (Dec 31 2023 at 19:28):
Kyle Miller said:
Yury G. Kudryashov Something I noticed and mentioned in this PR comment is that there seems to be a lower-impact change to
Decidable
(and one that seems to have nicer definitional equalities). I got as far as seeing it'll take also looking through assumptions aboutDecidable
that are hard-coded into the compiler.Here's the possible re-definition reproduced here:
class Decidable (p : Prop) where /-- The truth value of the proposition `p` as a `Bool`. If `true` then `p` is true, and if `false` then `p` is false. -/ decide : Bool /-- `decide p` evaluates to the Boolean `true` if and only if `p` is a true proposition. -/ cond_decide : cond decide p (Not p) /-- Prove that `p` is decidable by supplying a proof of `p` -/ @[match_pattern] def Decidable.isTrue {p : Prop} (h : p) : Decidable p where decide := true cond_decide := h /-- Prove that `p` is decidable by supplying a proof of `¬p` -/ @[match_pattern] def Decidable.isFalse {p : Prop} (h : Not p) : Decidable p where decide := false cond_decide := h
With this definition a Decidable instance would end up being an unboxed bool by our natural FFI definitions I think. That should make it rather easy to handle in the compiler, maybe even without special casing?
Kyle Miller (Dec 31 2023 at 19:44):
@Henrik Böving There are some assumptions about Decidable
here and there. I got some assertion violations in erase_irrelevant.cpp
in particular.
Henrik Böving (Dec 31 2023 at 19:46):
Right but the code in erase_irrelevant.cpp that deals with decidables is concerned with turning decidable things into Bool things. But since that would just naturally happen with the FFI rules I would hope we might just be able to get rid of it without performance penalty?
Henrik Böving (Dec 31 2023 at 19:46):
But that's just a hope, I don't know for sure of course
Kyle Miller (Dec 31 2023 at 19:49):
Oh, ok, I thought you were saying something else. It'd be neat if all we'd need to do to make this work is rip out the special casing.
Henrik Böving (Dec 31 2023 at 19:51):
If you do rip it out you might also want to either do that or add a note in the new compiler directory which deals with this as well but is disabled right now.
Yaël Dillies (Jan 01 2024 at 08:38):
Yury G. Kudryashov said:
That's a huge
diff
It's not that huge once you ignore everything under stage0
.
Gabriel Ebner (Jan 02 2024 at 00:34):
@Yury G. Kudryashov Unfortunately I don't have time to resume work on that PR. IIRC the Lean PR was technically finished, but it wasn't merged because it would cause work for the mathlib port.
Gabriel Ebner (Jan 02 2024 at 00:35):
I like Kyle's proposal. It should be enough to just make that change on top of my PR. I'd already ripped out all the special casing in the compiler.
Yury G. Kudryashov (Jan 02 2024 at 01:39):
I will read instructions on bootstrapping Lean 4 tomorrow.
Last updated: May 02 2025 at 03:31 UTC