Zulip Chat Archive

Stream: mathlib4

Topic: applying lemma that uses instance


Paige Thomas (Mar 18 2025 at 05:44):

I'm wondering, why does the simp only [List.nil_union] work in the first example, but not the second? I think List.union is the instance of the union notation?

import Mathlib


example
  {α β : Type}
  [DecidableEq α]
  [DecidableEq β]
  (f : α  β)
  (l1 l2 : List α)
  (h1 : Function.Injective f) :
  List.map f (l1  l2) = (List.map f l1)  (List.map f l2) :=
  by
  induction l1
  case nil =>
    simp only [List.map_nil]
    simp only [List.nil_union]
  case cons hd tl ih =>
    sorry


example
  {α β : Type}
  [DecidableEq α]
  [DecidableEq β]
  (f : α  β)
  (l1 l2 : List α)
  (h1 : Function.Injective f) :
  List.map f (List.union l1 l2) = List.union (List.map f l1) (List.map f l2) :=
  by
  induction l1
  case nil =>
    simp only [List.map_nil]
    -- simp only [List.nil_union] <- fails
    sorry
  case cons hd tl ih =>
    sorry

Paige Thomas (Mar 18 2025 at 06:32):

Is there a way to convert between List.union and ?

Ruben Van de Velde (Mar 18 2025 at 07:17):

You should probably just avoid writing List.union in the first place

Paige Thomas (Mar 19 2025 at 04:40):

I'm not sure how to use when I need to use it as a function. That is, for example, when using it as the function in List.map.

Paige Thomas (Mar 19 2025 at 04:43):

That is List.map List.union xs, for example.

Paige Thomas (Mar 19 2025 at 05:00):

Although, maybe it isn't an issue for the cases where I use it as a function.

Aaron Liu (Mar 19 2025 at 10:03):

fun x => xs ∪ x, or (xs ∪ ·)

Aaron Liu (Mar 19 2025 at 10:18):

Or Union.union xs, but that's not very readable.

Paige Thomas (Mar 29 2025 at 16:30):

Thank you.


Last updated: May 02 2025 at 03:31 UTC