diff options
| author | Hugo Herbelin | 2020-02-17 22:27:29 +0100 |
|---|---|---|
| committer | Hugo Herbelin | 2020-02-17 22:27:29 +0100 |
| commit | fdcfe8b75be809fcce231a69cb756e1e23d50f93 (patch) | |
| tree | 8d7eba510bdbbe13173263de5714a5dd77b7e084 /theories/Lists | |
| parent | c51323a3cf1f4bb4c1ec170e3a1acfc6f5b1696b (diff) | |
| parent | b71c0f9559a6c92029e797c3ab3620a51a85c2b5 (diff) | |
Merge PR #11350: stdlib List: add [remove'] and [count_occ'] that use [filter]
Reviewed-by: anton-trunov
Diffstat (limited to 'theories/Lists')
| -rw-r--r-- | theories/Lists/List.v | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/theories/Lists/List.v b/theories/Lists/List.v index 74335da2f1..2e8af3ecb9 100644 --- a/theories/Lists/List.v +++ b/theories/Lists/List.v @@ -1630,6 +1630,31 @@ End Fold_Right_Recursor. intros f g H l. rewrite filter_map. apply map_ext. assumption. Qed. + (** Remove by filtering *) + + Hypothesis eq_dec : forall x y : A, {x = y}+{x <> y}. + + Definition remove' (x : A) : list A -> list A := + filter (fun y => if eq_dec x y then false else true). + + Lemma remove_alt (x : A) (l : list A) : remove' x l = remove eq_dec x l. + Proof with intuition. + induction l... + simpl. destruct eq_dec; f_equal... + Qed. + + (** Counting occurrences by filtering *) + + Definition count_occ' (l : list A) (x : A) : nat := + length (filter (fun y => if eq_dec y x then true else false) l). + + Lemma count_occ_alt (l : list A) (x : A) : + count_occ' l x = count_occ eq_dec l x. + Proof with intuition. + unfold count_occ'. induction l... + simpl; destruct eq_dec; simpl... + Qed. + End Filtering. |
