-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.v
40 lines (38 loc) · 916 Bytes
/
filter.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Require Import List.
Fixpoint filter {X : Type} (p : X -> bool) (l: list X) : list X :=
match l with
| nil => nil
| x :: xs => if p x then x :: (filter p xs) else filter p xs
end.
Theorem filter_correct : forall (X : Type) (p : X -> bool)
(l l' : list X) (x : X),
In x l -> l' = filter p l -> p x = true -> In x l'.
Proof.
intros X p l.
induction l as [| y ys].
intros l' x H1 H2 H3.
inversion H1.
intros l' x H1 H2 H3.
simpl in H2.
simpl in H1.
destruct H1.
rewrite <- H in H3.
destruct (p y) eqn:H4.
rewrite -> H2.
rewrite <- H.
constructor.
reflexivity.
inversion H3.
destruct (p y) eqn:H4.
specialize (IHys (filter p ys) x H).
rewrite -> H2.
eapply in_cons.
apply IHys.
reflexivity.
assumption.
rewrite -> H2.
specialize (IHys (filter p ys) x H).
apply IHys.
reflexivity.
assumption.
Qed.