Zulip Chat Archive

Stream: Is there code for X?

Topic: More general version of `list.map_const`?


Michael Stoll (Dec 05 2022 at 20:27):

There is

theorem list.map_const {α : Type u} {β : Type v} (l : list α) (b : β) :
  list.map (function.const α b) l = list.repeat b l.length

which clearly generalizes to

example {α β} {l : list α} {f : α  β} {b : β} (h :  x  l, f x = b) :
  l.map f = list.repeat b l.length :=

but I can't find this more general version. Is it really not there? And if so, would it make sense to add it? (I have a use case...)

Scott Morrison (Dec 05 2022 at 20:41):

Do you want this as a @[simp] lemma, in a situation where you expect simp to solve h as well?

Do you actually want a lemma that says (∀ x ∈ l, f x = b) → f = function.const α b?

Michael Stoll (Dec 05 2022 at 20:45):

Not sure it would make sense as a simplemma.

Scott Morrison said:

Do you actually want a lemma that says (∀ x ∈ l, f x = b) → f = function.const α b?

This will not be true in general: fcan take other values on elments that are not in the list.

Michael Stoll (Dec 05 2022 at 20:45):

(Which is precisely the point...)

Eric Wieser (Dec 05 2022 at 23:02):

Your version might be better as an `iff

Michael Stoll (Dec 06 2022 at 12:43):

OK; I'll do the iff version and PR it.

Michael Stoll (Dec 06 2022 at 14:43):

#17832

Michael Stoll (Dec 08 2022 at 15:47):

I think this can be merged now (before the tide rises :smile: ...).


Last updated: Dec 20 2023 at 11:08 UTC