Zulip Chat Archive

Stream: Is there code for X?

Topic: BEq instance for sigma


Adam Topaz (Dec 06 2023 at 15:38):

I'm surprised that I couldn't find the following:

instance {α : Type} [BEq α] [LawfulBEq α] {β : α  Type} [ a, BEq (β a)] :
    BEq ((a : α) × β a) where
  beq := fun a,b a',b' =>
    match h : a == a' with
      | true =>
        match eq_of_beq h with
          | rfl => b == b'
      | false => false

Do we really not have this in mathlib (or even std)?

Ruben Van de Velde (Dec 06 2023 at 15:45):

Do we have anything about BEq in mathlib?

Adam Topaz (Dec 06 2023 at 15:46):

maybe not. but std does, right?

Adam Topaz (Dec 06 2023 at 15:49):

OTOH, mathlib does have some programmy things about Sigma like docs#Sigma.instDecidableEqSigma

Eric Wieser (Dec 06 2023 at 16:34):

I thought we were still waiting for a solution to the decidable/BEq diamonds before adopting BEq anywhere in mathlib

Adam Topaz (Dec 06 2023 at 17:19):

BTW, I'm getting some motive is not type correct issues trying to prove the following sorry:

instance {α : Type} [BEq α] [LawfulBEq α] {β : α  Type} [ a, BEq (β a)] :
    BEq ((a : α) × β a) where
  beq := fun a,b a',b' =>
    match h : a == a' with
      | true =>
        match eq_of_beq h with
          | rfl => b == b'
      | false => false

instance {α : Type} [BEq α] [LawfulBEq α]
    {β : α  Type} [ a, BEq (β a)]
    [ a, LawfulBEq (β a)] :
    LawfulBEq ((a : α) × β a) := sorry

Does anyone see a slick way to prove this?

Kyle Miller (Dec 06 2023 at 17:52):

It's not pretty, but here's a proof:

instance {α : Type} [BEq α] [LawfulBEq α]
    {β : α  Type} [ a, BEq (β a)]
    [ a, LawfulBEq (β a)] :
    LawfulBEq ((a : α) × β a) where
  rfl := by intro a, b; unfold_projs; simp; split; rfl; rename_i h; simp at h
  eq_of_beq := @fun a, b a', b' => by
    unfold_projs
    simp
    split
    · split
      subst_vars
      simp
    · simp

Yury G. Kudryashov (Dec 06 2023 at 17:53):

Can we teach simp to simplify match?

Kyle Miller (Dec 06 2023 at 17:56):

Here's another definition:

instance {α : Type} [BEq α] [LawfulBEq α] {β : α  Type} [ a, BEq (β a)] :
    BEq ((a : α) × β a) where
  beq
  | a, b⟩, a', b' => if h : a == a' then (eq_of_beq h  b) == b' else false

instance {α : Type} [BEq α] [LawfulBEq α]
    {β : α  Type} [ a, BEq (β a)]
    [ a, LawfulBEq (β a)] :
    LawfulBEq ((a : α) × β a) where
  rfl := by intro a, b; unfold_projs; simp
  eq_of_beq := @fun a, b a', b' => by
    unfold_projs
    simp
    split
    · rename_i h
      simp at h
      subst_vars
      simp
    · simp

Adam Topaz (Dec 06 2023 at 18:08):

Thanks Kyle!


Last updated: Dec 20 2023 at 11:08 UTC