Zulip Chat Archive

Stream: lean4

Topic: tactic to contract equalities


Jakob von Raumer (May 04 2023 at 16:21):

Do we have a tactic which contracts equalities under various binders when possible? For example given h : ∃ a b c, a = b ∧ b = c ∧ foo c I want to simplify to h : ∃ a, foo a without performing any other simplifications.

Ruben Van de Velde (May 04 2023 at 16:27):

Does simp make progress? You could do something with simp only if it does

Yaël Dillies (May 04 2023 at 16:29):

Unfortunately this kind of goals isn't very simp-friendly. Try simp {contextual := true}, though.

Jeremy Salwen (May 04 2023 at 16:37):

theorem z (h :  a b c, a = b  b  = c  f c): a := by
  simp  at h

works!

Yaël Dillies (May 04 2023 at 16:39):

Shouldn't the goal be f a rather than a?

Jakob von Raumer (May 04 2023 at 16:39):

@Jeremy Salwen Fails to simplify for (h : ∃ a b c, a = b ∧ b = c ∧ f c ∨ f a) though

Jakob von Raumer (May 04 2023 at 16:40):

@Yaël Dillies I'm getting an error on this, is this a fairly new addition to simp?

Yaël Dillies (May 04 2023 at 16:40):

No, it's an old one. I suspect the syntax has changed in Lean 4.

Jakob von Raumer (May 04 2023 at 16:41):

@Jeremy Salwen The issue is also that a pure simp does too much in other situations

Jakob von Raumer (May 04 2023 at 16:42):

@Yaël Dillies Ah, it's simp (config := { contextual := true}) now

Yaël Dillies (May 04 2023 at 16:43):

Ugh, that's a mouthful

Jakob von Raumer (May 04 2023 at 16:49):

Hm, so the result of that is not too bad, probably I can make it work if I find a good simp set. Some of the simp lemmas prevent equalities in nested existential quantifiers to be contracted further.

Jeremy Salwen (May 04 2023 at 16:58):

Adding the following lemma lets simp solve it:

theorem w (p: α -> Prop):  ( x, (p x)  b)   (( x, p x)  b) := sorry

This is similar to the exists_and_left lemma which simp uses to simplify the first expression, but pushing the extential quantifier in through an or expression instead of an and expression.

Jakob von Raumer (Jul 10 2023 at 22:00):

(deleted)

Gabriel Ebner (Jul 10 2023 at 22:06):

You might be interested in this talk: https://matryoshka-project.github.io/matryoshka2018/slides/Matryoskha-2018-Hoelzl-Generalising-the-One-Point-Rule.pdf

Jakob von Raumer (Jul 10 2023 at 22:11):

Thanks :blush:

Jakob von Raumer (Jul 10 2023 at 22:11):

Though this issue is simply about simps unification behaviour under :sweat_smile:

Jakob von Raumer (Jul 10 2023 at 22:13):

Maybe I'm just too tired, but now it simplifies

Jakob von Raumer (Jul 10 2023 at 22:14):

Ignore my last message :face_palm:

Gabriel Ebner (Jul 10 2023 at 22:14):

I should also warn you that foo is false.

Jakob von Raumer (Jul 10 2023 at 22:19):

(deleted)

Jakob von Raumer (Jul 10 2023 at 22:20):

(deleted)

Jakob von Raumer (Jul 11 2023 at 00:21):

Fixed the example:

theorem foo {α : Sort u} {P Q : α  Prop} {a : α} : ( b, Q a  a = b  P b)  (Q a  P a) := by
  constructor
  · rintro _, q, rfl, p; exact q, p
  · rintro q, p; exact _, q, rfl, p

example {a b c : } :  d, c < 3  c = d  d > a * a := by
  simp only [foo (Q := fun (c :  ) => c < 3)]  -- fails to simplify without giving `Q`
  sorry

Last updated: Dec 20 2023 at 11:08 UTC