Zulip Chat Archive

Stream: lean4

Topic: theorems about dropWhile


Damiano Testa (Jan 10 2023 at 09:40):

Dear All,

for my own benefit, I proved some trivialities about docs4#List.dropWhile -- you can find them below.

If anyone thinks that they may be useful, let me know and I can PR them somewhere!

Thanks!

import Std.Data.List.Basic

theorem List.dropWhile_of_true {a : α} {L : List α} {c : α  Bool} (ca : c a = true) :
    (a::L).dropWhile c = L.dropWhile c := by simp [ca]

theorem List.dropWhile_of_false {a : α} {L : List α} {c : α  Bool} (ca : c a = false) :
    (a::L).dropWhile c = a :: L := by simp [ca]

theorem List.length_dropWhile {L : List α} {c : α  Bool} : (L.dropWhile c).length  L.length := by
  cases L with
    | nil => simp
    | cons a as => if h : c a
      then
        rw [List.dropWhile_of_true h];
        exact Nat.le_trans List.length_dropWhile (Nat.le_succ _)
      else rw [List.dropWhile_of_false]; simp; simp [h]

Eric Wieser (Jan 10 2023 at 11:43):

Do we want to be making non-meta feature PRs to mathlib4 yet?

Damiano Testa (Jan 10 2023 at 11:51):

It was not my intention to push for these lemmas to be PRed: I simply "needed" these lemmas, saw that docs4#List.length_drop exists and wondered whether then also some dropWhile lemmas were to be expected!

It is certainly of no priority for me!

Eric Rodriguez (Jan 10 2023 at 11:51):

I guess we'd have to reverse-synchronise them, which seems irritating. We could put them in non-synced files for the time being.

Eric Rodriguez (Jan 10 2023 at 11:52):

e.g. these could be in Data/List/DropWhile4.lean where the 4 symbolises that these are mathlib4-only files. we could, after the port is done, then merge everything into the correct files

Damiano Testa (Jan 10 2023 at 11:52):

The reason for me "needing" these lemmas was to remove a partial in a definition that I had. Now that I have convinced Lean that partial is superfluous, I can live with having a partial! :upside_down:

Ruben Van de Velde (Jan 10 2023 at 12:08):

Or in this case, PR them to std4 directly? :)

Damiano Testa (Jan 10 2023 at 12:17):

I am happy to make a PR to std4, but also to wait and possibly not PR these lemmas at all! :smile:

Damiano Testa (Jan 10 2023 at 13:51):

I also just noticed that with mathlib, the proof is easier, although I had to fight a decidable typeclass:

import Mathlib.Data.List.Infix

theorem List.length_dropWhile {L : List α} {c : α  Bool} : (L.dropWhile c).length  L.length := by
  convert List.isSuffix.length_le (@List.dropWhile_suffix α L (c ·) _)
  simp only [Bool.decide_coe]

Mario Carneiro (Jan 10 2023 at 17:20):

Eric Wieser said:

Do we want to be making non-meta feature PRs to mathlib4 yet?

Yes, certainly. There are no restrictions on new material in mathlib4 besides compatibility with mathlib, and I absolutely do not want to send a message that mathlib4 is "frozen" at all!

Eric Wieser (Jan 10 2023 at 18:01):

Should we have a compromise like "all mathlib4-new material in existing files should go at the bottom of the file", so as not to interfere with forward-ports?

James Gallicchio (Jan 10 2023 at 18:13):

would it also be fine to make changes to anything where the lean3 mathlib file is frozen?

Eric Wieser (Jan 10 2023 at 18:21):

Are there any such files?

Damiano Testa (Jan 10 2023 at 18:26):

While I agree with the spirit, now that I am at a computer that actually has Lean4, instead of using the online editor, I can see that the lemma that I had was completely trivial, given what is in mathlib4:

theorem List.length_dropWhile {L : List α} {c : α  Bool} : (L.dropWhile c).length  L.length :=
  List.isSuffix.length_le (List.dropWhile_suffix (c ·))

If you think that it is worth to PR it, I can do it, but maybe it is too trivial, even from the point of view of formalization! :smile:


Last updated: Dec 20 2023 at 11:08 UTC