Theoremlen_filter_eq
Statement
theorem len_filter_eq {α : Type} : ∀ {l : List α} {p q : α → Bool},
(∀ x ∈ l, p x = true → q x = true) → (l.filter p).length = (l.filter q).length →
∀ x ∈ l, q x = true → p x = true
| [], _, _, _, _, x, hx, _ => by simp at hx
| y :: ys, p, q, h, he, x, hx, hq => by
have hleProof
len_filter_mono (l := ys) (p := p) (q := q) (fun z hz => h z (List.mem_cons_of_mem _ hz))
have hy := h y List.mem_cons_self
simp only [List.filter_cons] at he
have he' : (ys.filter p).length = (ys.filter q).length := by
cases hp : p y <;> cases hq' : q y <;> simp_all <;> omega
rcases List.mem_cons.mp hx with rfl | hx
· cases hp : p x
· cases hq' : q x
· simp_all
· simp [hp, hq'] at he; omega
· rfl
· exact len_filter_eq (fun z hz => h z (List.mem_cons_of_mem _ hz)) he' x hx hqProved by a term, which Lean's kernel checks directly.
Theorems it uses
Used by
In StandardElmMech/Src/Graph.lean: Reachability on graphs over 0 .. n-1 (Plus, Reach) and its decider, proved correct (plusB_iff, reachB_iff).
A Standard Definition of Elm? (Draft version 0.4) © Rupert Smith. The text is licensed under CC BY 4.0: share and adapt it freely, with credit and a link to the licence.