Zulip Chat Archive

Stream: general

Topic: Failedd to synthesize type class instance for set.decidab...


AHan (Dec 14 2018 at 02:28):

In the following example, I don't understand why lean failed to synthesize type class instance for decidable (x ∈ s) ?
What did I miss?

import data.set
universes u
variables {α : Type u}

def f (x : α) (s : set α) : set α := if x  s then {x} else 

Bryan Gin-ge Chen (Dec 14 2018 at 03:04):

if P then _ else _ requires P to be decidable, otherwise how will lean know which branch to take? Here's the discussion in TPiL. One thing you could do is use

open classical
local attribute [instance, priority 0] prop_decidable

Mario Carneiro (Dec 14 2018 at 03:11):

Another way is to write the set without an if statement, i.e.

def f (x : α) (s : set α) : set α := {y | x  s  y = x}

AHan (Dec 14 2018 at 07:10):

Thanks a lot!
Both solutions are nice!!

Kenny Lau (Dec 14 2018 at 08:14):

but the latter is nicer


Last updated: Dec 20 2023 at 11:08 UTC