7 kyu

Another random fact about filtering

Description:

Last time we proved a random fact about filtering. Here's another one: given two predicates f, g, the number of elements satisfying both cannot exceed that satisfying either.

forall (X : Type) (l : list X) (f g : X -> bool),
  length (filter (fun x => f x && g x) l) <= length (filter f l) /\
  length (filter (fun x => f x && g x) l) <= length (filter g l)
universe u

: Type u} {p q : α  Prop} [decidable_pred p]
  [decidable_pred q] {L: list α}, 
  (L.filter $ λ x, p x ∧ q x).length ≤ (L.filter p).length ∧
    (L.filter $ λ x, p x ∧ q x).length ≤ (L.filter q).length

Prove it.

Theorem Proving
Logic
Fundamentals

Stats:

CreatedNov 6, 2021
PublishedNov 6, 2021
Warriors Trained75
Total Skips6
Total Code Submissions95
Total Times Completed40
Coq Completions30
Lean Completions13
Total Stars0
% of votes with a positive feedback rating100% of 6
Total "Very Satisfied" Votes6
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Total Rank Assessments3
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • donaldsebleung Avatar
  • Madjosz Avatar
Ad