1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "datatypes/bool.ma".
16 include "datatypes/constructors.ma".
17 include "list/list.ma".
19 inductive in_list (A:Type): A → (list A) → Prop ≝
20 | in_list_head : ∀ x,l.(in_list A x (x::l))
21 | in_list_cons : ∀ x,y,l.(in_list A x l) → (in_list A x (y::l)).
23 definition incl : \forall A.(list A) \to (list A) \to Prop \def
24 \lambda A,l,m.\forall x.in_list A x l \to in_list A x m.
26 lemma not_in_list_nil : \forall A,x.\lnot in_list A x [].
27 intros.unfold.intro.inversion H
28 [intros;lapply (sym_eq ? ? ? H2);destruct Hletin
32 lemma in_list_cons_case : \forall A,x,a,l.in_list A x (a::l) \to
33 x = a \lor in_list A x l.
34 intros;inversion H;intros
35 [destruct H2;left;reflexivity
36 |destruct H4;right;assumption]
39 lemma in_list_tail : \forall l,x,y.
40 in_list nat x (y::l) \to x \neq y \to in_list nat x l.
41 intros 4;elim (in_list_cons_case ? ? ? ? H)
46 lemma in_list_singleton_to_eq : \forall A,x,y.in_list A x [y] \to x = y.
47 intros;elim (in_list_cons_case ? ? ? ? H)
49 |elim (not_in_list_nil ? ? H1)]
52 lemma in_list_to_in_list_append_l: \forall A.\forall x:A.
53 \forall l1,l2.in_list ? x l1 \to in_list ? x (l1@l2).
57 |apply in_list_cons;assumption
61 lemma in_list_to_in_list_append_r: \forall A.\forall x:A.
62 \forall l1,l2. in_list ? x l2 \to in_list ? x (l1@l2).
66 |apply in_list_cons;apply H;assumption
70 theorem in_list_append_to_or_in_list: \forall A:Type.\forall x:A.
71 \forall l,l1. in_list ? x (l@l1) \to in_list ? x l \lor in_list ? x l1.
75 |simplify in H1.inversion H1;intros; destruct;
76 [left.apply in_list_head
78 [left.apply in_list_cons. assumption
86 let rec mem (A:Type) (eq: A → A → bool) x (l: list A) on l ≝
92 | false ⇒ mem A eq x l'
96 lemma mem_true_to_in_list :
98 (\forall x,y.equ x y = true \to x = y) \to
99 \forall x,l.mem A equ x l = true \to in_list A x l.
101 [simplify in H1;destruct H1
102 |simplify in H2;apply (bool_elim ? (equ x a))
103 [intro;rewrite > (H ? ? H3);apply in_list_head
104 |intro;rewrite > H3 in H2;simplify in H2;
105 apply in_list_cons;apply H1;assumption]]
108 lemma in_list_to_mem_true :
110 (\forall x.equ x x = true) \to
111 \forall x,l.in_list A x l \to mem A equ x l = true.
113 [elim (not_in_list_nil ? ? H1)
115 [simplify;rewrite > H;reflexivity
116 |simplify;rewrite > H4;apply (bool_elim ? (equ a1 a2));intro;reflexivity]].
119 lemma in_list_filter_to_p_true : \forall l,x,p.
120 in_list nat x (filter nat l p) \to p x = true.
122 [simplify in H;elim (not_in_list_nil ? ? H)
123 |simplify in H1;apply (bool_elim ? (p a));intro;rewrite > H2 in H1;
125 [elim (in_list_cons_case ? ? ? ? H1)
126 [rewrite > H3;assumption
131 lemma in_list_filter : \forall l,p,x.in_list nat x (filter nat l p) \to in_list nat x l.
133 [simplify in H;elim (not_in_list_nil ? ? H)
134 |simplify in H1;apply (bool_elim ? (p a));intro;rewrite > H2 in H1;
136 [elim (in_list_cons_case ? ? ? ? H1)
137 [rewrite > H3;apply in_list_head
138 |apply in_list_cons;apply H;assumption]
139 |apply in_list_cons;apply H;assumption]]
142 lemma in_list_filter_r : \forall l,p,x.
143 in_list nat x l \to p x = true \to in_list nat x (filter nat l p).
145 [elim (not_in_list_nil ? ? H)
146 |elim (in_list_cons_case ? ? ? ? H1)
147 [rewrite < H3;simplify;rewrite > H2;simplify;apply in_list_head
148 |simplify;apply (bool_elim ? (p a));intro;simplify;
149 [apply in_list_cons;apply H;assumption
150 |apply H;assumption]]]
153 lemma incl_A_A: ∀T,A.incl T A A.
154 intros.unfold incl.intros.assumption.