1
(************************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
4
(* \VV/ **************************************************************)
5
(* // * This file is distributed under the terms of the *)
6
(* * GNU Lesser General Public License Version 2.1 *)
7
(************************************************************************)
9
(*i $Id: Uniset.v 5920 2004-07-16 20:01:26Z herbelin $ i*)
11
(** Sets as characteristic functions *)
14
(* Updated Papageno 12/98 *)
18
Set Implicit Arguments.
23
Variable eqA : A -> A -> Prop.
24
Hypothesis eqA_dec : forall x y:A, {eqA x y} + {~ eqA x y}.
26
Inductive uniset : Set :=
27
Charac : (A -> bool) -> uniset.
29
Definition charac (s:uniset) (a:A) : bool := let (f) := s in f a.
31
Definition Emptyset := Charac (fun a:A => false).
33
Definition Fullset := Charac (fun a:A => true).
35
Definition Singleton (a:A) :=
38
match eqA_dec a a' with
43
Definition In (s:uniset) (a:A) : Prop := charac s a = true.
46
(** uniset inclusion *)
47
Definition incl (s1 s2:uniset) := forall a:A, leb (charac s1 a) (charac s2 a).
50
(** uniset equality *)
51
Definition seq (s1 s2:uniset) := forall a:A, charac s1 a = charac s2 a.
54
Lemma leb_refl : forall b:bool, leb b b.
56
destruct b; simpl in |- *; auto.
58
Hint Resolve leb_refl.
60
Lemma incl_left : forall s1 s2:uniset, seq s1 s2 -> incl s1 s2.
62
unfold incl in |- *; intros s1 s2 E a; elim (E a); auto.
65
Lemma incl_right : forall s1 s2:uniset, seq s1 s2 -> incl s2 s1.
67
unfold incl in |- *; intros s1 s2 E a; elim (E a); auto.
70
Lemma seq_refl : forall x:uniset, seq x x.
72
destruct x; unfold seq in |- *; auto.
74
Hint Resolve seq_refl.
76
Lemma seq_trans : forall x y z:uniset, seq x y -> seq y z -> seq x z.
79
destruct x; destruct y; destruct z; simpl in |- *; intros.
83
Lemma seq_sym : forall x y:uniset, seq x y -> seq y x.
86
destruct x; destruct y; simpl in |- *; auto.
90
Definition union (m1 m2:uniset) :=
91
Charac (fun a:A => orb (charac m1 a) (charac m2 a)).
93
Lemma union_empty_left : forall x:uniset, seq x (union Emptyset x).
95
unfold seq in |- *; unfold union in |- *; simpl in |- *; auto.
97
Hint Resolve union_empty_left.
99
Lemma union_empty_right : forall x:uniset, seq x (union x Emptyset).
101
unfold seq in |- *; unfold union in |- *; simpl in |- *.
102
intros x a; rewrite (orb_b_false (charac x a)); auto.
104
Hint Resolve union_empty_right.
106
Lemma union_comm : forall x y:uniset, seq (union x y) (union y x).
108
unfold seq in |- *; unfold charac in |- *; unfold union in |- *.
109
destruct x; destruct y; auto with bool.
111
Hint Resolve union_comm.
114
forall x y z:uniset, seq (union (union x y) z) (union x (union y z)).
116
unfold seq in |- *; unfold union in |- *; unfold charac in |- *.
117
destruct x; destruct y; destruct z; auto with bool.
119
Hint Resolve union_ass.
121
Lemma seq_left : forall x y z:uniset, seq x y -> seq (union x z) (union y z).
123
unfold seq in |- *; unfold union in |- *; unfold charac in |- *.
124
destruct x; destruct y; destruct z.
125
intros; elim H; auto.
127
Hint Resolve seq_left.
129
Lemma seq_right : forall x y z:uniset, seq x y -> seq (union z x) (union z y).
131
unfold seq in |- *; unfold union in |- *; unfold charac in |- *.
132
destruct x; destruct y; destruct z.
133
intros; elim H; auto.
135
Hint Resolve seq_right.
138
(** All the proofs that follow duplicate [Multiset_of_A] *)
140
(** Here we should make uniset an abstract datatype, by hiding [Charac],
141
[union], [charac]; all further properties are proved abstractly *)
143
Require Import Permut.
146
forall x y z:uniset, seq (union x (union y z)) (union z (union x y)).
148
intros; apply (op_rotate uniset union seq); auto.
153
forall x y z t:uniset, seq x y -> seq z t -> seq (union x z) (union y t).
155
intros; apply (cong_congr uniset union seq); auto.
159
Lemma union_perm_left :
160
forall x y z:uniset, seq (union x (union y z)) (union y (union x z)).
162
intros; apply (perm_left uniset union seq); auto.
166
Lemma uniset_twist1 :
167
forall x y z t:uniset,
168
seq (union x (union (union y z) t)) (union (union y (union x t)) z).
170
intros; apply (twist uniset union seq); auto.
174
Lemma uniset_twist2 :
175
forall x y z t:uniset,
176
seq (union x (union (union y z) t)) (union (union y (union x z)) t).
178
intros; apply seq_trans with (union (union x (union y z)) t).
179
apply seq_sym; apply union_ass.
180
apply seq_left; apply union_perm_left.
183
(** specific for treesort *)
185
Lemma treesort_twist1 :
186
forall x y z t u:uniset,
188
seq (union x (union u t)) (union (union y (union x t)) z).
190
intros; apply seq_trans with (union x (union (union y z) t)).
191
apply seq_right; apply seq_left; trivial.
195
Lemma treesort_twist2 :
196
forall x y z t u:uniset,
198
seq (union x (union u t)) (union (union y (union x z)) t).
200
intros; apply seq_trans with (union x (union (union y z) t)).
201
apply seq_right; apply seq_left; trivial.
206
(*i theory of minter to do similarly
208
(* uniset intersection *)
209
Definition minter := [m1,m2:uniset]
210
(Charac [a:A](andb (charac m1 a)(charac m2 a))).
215
Unset Implicit Arguments.
b'\\ No newline at end of file'