Zulip Chat Archive

Stream: lean4

Topic: understanding simp and interaction with iff and hypotheses


Yakov Pechersky (Oct 23 2022 at 22:46):

Consider the following example, pbind_eq_some_iff, which is a mwe of pbind_eq_some, in porting in Mathlib.Data.Option.Basic for mathlib4. Some questions: why is the only working proof here the one that is simp only ... <;> intro h <;> simp at h? Why does just simp not work? Does one need the new simp_intros? Why does the simp at * version not work? That issue is regardless of whether the intro-d hypothesis named or not:

@[simp] theorem not_exists {α : Sort _} {p : α  Prop} : (¬∃ x, p x)   x, ¬p x := sorry

namespace Option

instance : Membership α (Option α) := fun a b => b = some a

variable {x : Option α}

@[simp] theorem mem_def {a : α} {b : Option α} : a  b  b = some a := .rfl

@[simp]
def pbind :  x : Option α, ( a : α, a  x  Option β)  Option β
  | none, _ => none
  | some a, f => f a rfl

theorem pbind_eq_some_imp {f :  a : α, a  x  Option β} {y : β} :
    x.pbind f = some y   (z : α) (H : z  x), f z H = some y := by
  cases x
  · simp
  · sorry

-- why does this not work when the `imp` version does?
theorem pbind_eq_some_iff {f :  a : α, a  x  Option β} {y : β} :
    x.pbind f = some y   (z : α) (H : z  x), f z H = some y := by
  cases x
  · simp -- doesn't work all the way
    sorry
  · sorry

theorem pbind_eq_some_iff' {f :  a : α, a  x  Option β} {y : β} :
    x.pbind f = some y   (z : α) (H : z  x), f z H = some y := by
  cases x
  · simp only [pbind, false_iff, not_exists]
    intro z h
    simp at h
  · sorry

-- why does this not work when the previous `intro h, simp at h` did?
theorem pbind_eq_some_iff'' {f :  a : α, a  x  Option β} {y : β} :
    x.pbind f = some y   (z : α) (H : z  x), f z H = some y := by
  cases x
  · simp only [pbind, false_iff, not_exists] -- also red line is here and not at `simp at *`
    intro z h
    simp at * -- doesn't work
  · sorry

end Option

Kevin Buzzard (Oct 24 2022 at 05:47):

In Lean 3 there was something like simp {something:=tt} which would do the intros for you

Mario Carneiro (Oct 24 2022 at 06:10):

you mean simp {contextual := tt}?

Mario Carneiro (Oct 24 2022 at 06:10):

that's spelled simp (config := {contextual := true}) now

Kevin Buzzard (Oct 24 2022 at 06:11):

I never really understood whether that was simp_intros or whether it just happened to do what simp_intros did

Mario Carneiro (Oct 24 2022 at 06:11):

Oh, simp_intros is something else

Mario Carneiro (Oct 24 2022 at 06:12):

maybe that's what you want here, I didn't read closely

Mario Carneiro (Oct 24 2022 at 06:12):

simp {contextual := tt} will make use of hypotheses that enter the context when it "rewrites under binders"

Mario Carneiro (Oct 24 2022 at 06:13):

so for example \forall (h : a = b), a + a = 1 will simp to \forall (h : a = b), b + b = 1


Last updated: Dec 20 2023 at 11:08 UTC