Zulip Chat Archive

Stream: general

Topic: apply_ite


Scott Morrison (Jun 26 2020 at 04:44):

-- How is this not in mathlib?!
lemma apply_ite {α β : Type*} (f : α  β) (P : Prop) [decidable P] (x y : α) :
  f (ite P x y) = ite P (f x) (f y) :=
by split_ifs; refl

Is this already somewhere in mathlib? If not, can I put it in logic/basic.lean?

Scott Morrison (Jun 26 2020 at 04:45):

Surely there is some existing colloquial way to push a function inside an if...?

Johan Commelin (Jun 26 2020 at 05:18):

Sounds like a good idea!

Patrick Stevens (Jun 26 2020 at 05:28):

Naive naming question: is this really "apply"? In the "applicative functor" sense, "apply" has the signature F (A -> B) -> F A -> F B, which is the first thing I think of. My guess would have been something like "interchange".

Kenny Lau (Jun 26 2020 at 05:44):

in mathlib apply means applying a function to an input

Floris van Doorn (Jun 26 2020 at 06:52):

We probably also wants its friend:

lemma ite_apply {α} {β : α  Type*} (P : Prop) [decidable P] (f g : Π x, β x) (x : α) :
  (ite P f g) x = ite P (f x) (g x) :=
by split_ifs; refl

Scott Morrison (Jun 26 2020 at 12:16):

all in mathlib now, part of #3177

Simon Hudon (Jun 27 2020 at 22:12):

I don't think it will behave well with simp and rw because the outer function on the lhs is a variable

Scott Morrison (Jun 28 2020 at 00:11):

Yes. To use it you need to write simp [ite_apply _ f], etc. Maybe I should add a doc-string to that effect.

Simon Hudon (Jun 28 2020 at 00:12):

Could it be worth having a specialized version of rw to make it more usable?

Scott Morrison (Jun 28 2020 at 00:19):

Sounds interesting!

Simon Hudon (Jun 28 2020 at 00:19):

I'd start it with generalize h : ite _ _ _ = x

Scott Morrison (Jun 28 2020 at 00:25):

Could we possibly do something much more general? That is not ite specific in any way, but just tries to do rewriting even without being able to key on the head symbol (because it could be a metavariable).


Last updated: Dec 20 2023 at 11:08 UTC