Zulip Chat Archive

Stream: lean4

Topic: Proving Filter.ext_iff


Utensil Song (Sep 10 2023 at 15:29):

I was trying out https://github.com/bridgekat/filter-game and proving Filter.ext_iff in it, by following only the hints given by Lean and this tactics cheat sheet, I got the 2nd proof Filter.ext_iff'' in the following #mwe, it's much more verbose than the 1st simple proof:

import Mathlib.Data.Set.Basic
import Mathlib.Data.Set.Finite
import Mathlib.Order.Filter.Basic

theorem Filter.ext_iff₁ (f g : Filter α) : f = g  ( s, s  f  s  g) := by
  simp only [filter_eq_iff, Set.ext_iff, Filter.mem_sets]

theorem Filter.ext_iff₂ (f g : Filter α) : f = g  ( s, s  f  s  g) := by
  apply Iff.intro
  . intro f_eq_g
    intro s
    apply Iff.intro
    . intro s_mem_f
      rw [<-f_eq_g]
      exact s_mem_f
    . intro s_mem_g
      rw [f_eq_g]
      exact s_mem_g
  . intro set_mem_iff
    rw [filter_eq_iff]
    rw [Set.ext_iff]
    intro s
    specialize set_mem_iff s
    rw [Filter.mem_sets]
    exact set_mem_iff

My question is:

  1. Is there somewhere between these 2 proofs that's idiomatic and also down to the basics?
  2. How could I realize that the proof can be a simp only with a few lemmas when simp? made no progress? Can simp somehow give some hints about what shapes of the assumptions and goals it faced right before it gave up so that I might figure out the lemmas?

Damiano Testa (Sep 10 2023 at 16:29):

I am not sure about the Filter proof, since I never really worked with filters.

As for simp, when it fails, it means that it tried all simp lemmas and was able to apply none. This means that place where it was when it failed is exactly where you are.

The other question, about what lemmas to add, that is very dependent on context and if there were a good automation for that, more proof would be easier to formalize!

Utensil Song (Sep 10 2023 at 16:49):

Thanks for your answer~

I'm asking Q1 because I wonder how experts simplify their proofs in general. This is a simple proof which uses little knowledge about filters but lots of basics of Lean 4. So it could be a good example for discussion.

By Q2, I imagine simp (or other automation tactics, e.g. aesop) would know its search depth and evaluate the complexity of the remaining goals and can provide useful insight even in failure.

Utensil Song (Sep 10 2023 at 16:51):

I also would like to share my experience about places where I thought Lean 4 would help me (from my Lean 3 experience) but instead I was confused:

Utensil Song (Sep 19 2023 at 07:14):

With the help of #explode, I have managed to get somewhere in between:

theorem Filter.ext_iff₃ (f g : Filter α) : f = g  ( s, s  f  s  g) := by
  calc
    (f = g)  (f.sets = g.sets)                           := by rw [filter_eq_iff]
          _   (x : Set α), x  f.sets  x  g.sets      := by rw [Set.ext_iff]
          _   (x : Set α), x  f  x  g                := by simp_rw [Filter.mem_sets]

However, I can't make simp_rw go away with more explicit form without increasing the "step count" in #explode, nor can I get "step count" close to 19 in an explicit form.

-- 19
#explode Filter.ext_iff₁

-- 38
#explode Filter.ext_iff₂

-- 31
#explode Filter.ext_iff₃

My attempts and the #explode tables can be view here . Any hint would be appreciated. :thank_you:


Last updated: Dec 20 2023 at 11:08 UTC