Zulip Chat Archive

Stream: general

Topic: DecidableEq for Tree


Asei Inoue (Oct 04 2025 at 07:03):

why this raise an error?

variable {α : Type} [DecidableEq α]

inductive Tree (α : Type) where
  | empty
  | node (v : α) (children : List (Tree α))
/- None of the deriving handlers for class `DecidableEq` applied to Tree -/
deriving DecidableEq, BEq

Henrik Böving (Oct 04 2025 at 10:04):

Because Tree is a nested inductive type so it's quite a bit more complicated to automatically derive a DecidableEq (or anything that recurses over it for that matter)

Asei Inoue (Oct 04 2025 at 10:04):

but we can derive BEq. why?

Henrik Böving (Oct 04 2025 at 10:05):

Most likely because BEq is not proof carrying so getting it done is quite a lot easier. It's most likely not the case that deriving DecidableEq is actually impossible, it's just hard.

Joachim Breitner (Oct 05 2025 at 10:58):

The derived BEq uses partial here. That would be silly for DecidableEq.

Eric Wieser (Oct 05 2025 at 11:27):

Would it? DecidableEq is for more than just decide

Aaron Liu (Oct 05 2025 at 11:39):

I feel like it should still be possible to systematically derive a DecidableEq here

Aaron Liu (Oct 05 2025 at 11:39):

how does it work normally?

Joachim Breitner (Oct 05 2025 at 11:46):

Hmm, ok, maybe silly is a strong word. So you say a partial definition that doesn't work with by decide or with kernel reduction of if would still be more useful than unhelpful?

Joachim Breitner (Oct 05 2025 at 11:47):

(it is maybe unfortunate that the same type class is used both for kernel reduction and compiled code)

Eric Wieser (Oct 05 2025 at 16:21):

I would argue that decidable instances are still sometimes a good idea even if they are neither reducible nor executable!

Joachim Breitner (Oct 05 2025 at 18:37):

If you want something that's neither reducible nor executable, wouldn't then Classical.propDecidable serve your purpose?

Edward van de Meent (Oct 05 2025 at 20:19):

having an instance makes lean not complain about failure to synthesize. However, if you use open Classical, the instance synthesis might not give you the decidability instance you want in unrelated cases (possibly in the same declaration, making open in not a feasible alternative). Therefore there is benefit, however small

Edward van de Meent (Oct 05 2025 at 20:20):

that aside, maybe this just means that someone needs to look into/spend time writing a non-partial deriver for DecidableEq for mutual/nested inductives...

Aaron Liu (Oct 05 2025 at 20:27):

Edward van de Meent said:

having an instance makes lean not complain about failure to synthesize. However, if you use open Classical, the instance synthesis might not give you the decidability instance you want in unrelated cases (possibly in the same declaration, making open in not a feasible alternative). Therefore there is benefit, however small

but if that's the case then you can just register the instance but make the implementation be Classical.propDecidable, right? (mathlib does this for docs#Real.decidableEq)

Eric Wieser (Oct 05 2025 at 21:22):

I guess I should clarify that while registering the instance is a good idea in that case, indeed there would be little value in deriving it


Last updated: Dec 20 2025 at 21:32 UTC