summaryrefslogtreecommitdiff
path: root/theories7/Sets/Uniset.v
blob: 33880214addd8bccf1bd9c3160d05e101796adb9 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
(************************************************************************)
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team     *)
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
(*   \VV/  **************************************************************)
(*    //   *      This file is distributed under the terms of the       *)
(*         *       GNU Lesser General Public License Version 2.1        *)
(************************************************************************)

(*i $Id: Uniset.v,v 1.1.2.1 2004/07/16 19:31:40 herbelin Exp $ i*)

(** Sets as characteristic functions *)

(* G. Huet 1-9-95 *)
(* Updated Papageno 12/98 *)

Require Bool.

Set Implicit Arguments.

Section defs.

Variable A : Set.
Variable eqA : A -> A -> Prop.
Hypothesis eqA_dec : (x,y:A){(eqA x y)}+{~(eqA x y)}.

Inductive uniset : Set := 
      Charac : (A->bool) -> uniset.

Definition charac : uniset -> A -> bool :=
  [s:uniset][a:A]Case s of [f:A->bool](f a) end.

Definition Emptyset := (Charac [a:A]false).

Definition Fullset  := (Charac [a:A]true).

Definition Singleton := [a:A](Charac [a':A]
              Case (eqA_dec a a') of 
                   [h:(eqA a a')]  true
                   [h: ~(eqA a a')] false end).

Definition In : uniset -> A -> Prop :=
     [s:uniset][a:A](charac s a)=true.
Hints Unfold In.

(** uniset inclusion *)
Definition incl := [s1,s2:uniset]
    (a:A)(leb (charac s1 a) (charac s2 a)).
Hints Unfold incl.

(** uniset equality *)
Definition seq := [s1,s2:uniset]
    (a:A)(charac s1 a) = (charac s2 a).
Hints Unfold seq.

Lemma leb_refl : (b:bool)(leb b b).
Proof.
NewDestruct b; Simpl; Auto.
Qed.
Hints Resolve leb_refl.

Lemma incl_left : (s1,s2:uniset)(seq s1 s2)->(incl s1 s2).
Proof.
Unfold incl; Intros s1 s2 E a; Elim (E a); Auto.
Qed.

Lemma incl_right : (s1,s2:uniset)(seq s1 s2)->(incl s2 s1).
Proof.
Unfold incl; Intros s1 s2 E a; Elim (E a); Auto.
Qed.

Lemma seq_refl : (x:uniset)(seq x x).
Proof.
NewDestruct x; Unfold seq; Auto.
Qed.
Hints Resolve seq_refl.

Lemma seq_trans : (x,y,z:uniset)(seq x y)->(seq y z)->(seq x z).
Proof.
Unfold seq.
NewDestruct x; NewDestruct y; NewDestruct z; Simpl; Intros.
Rewrite H; Auto.
Qed.

Lemma seq_sym : (x,y:uniset)(seq x y)->(seq y x).
Proof.
Unfold seq.
NewDestruct x; NewDestruct y; Simpl; Auto.
Qed.

(** uniset union *)
Definition union := [m1,m2:uniset]
    (Charac [a:A](orb (charac m1 a)(charac m2 a))).

Lemma union_empty_left :
     (x:uniset)(seq x (union Emptyset x)).  
Proof.  
Unfold seq; Unfold union; Simpl; Auto.  
Qed. 
Hints Resolve union_empty_left.

Lemma union_empty_right :
     (x:uniset)(seq x (union x Emptyset)).
Proof.
Unfold seq; Unfold union; Simpl.
Intros x a; Rewrite (orb_b_false (charac x a)); Auto.
Qed.
Hints Resolve union_empty_right.

Lemma union_comm : (x,y:uniset)(seq (union x y) (union y x)).
Proof.
Unfold seq; Unfold charac; Unfold union.
NewDestruct x; NewDestruct y; Auto with bool.
Qed.
Hints Resolve union_comm.

Lemma union_ass : 
      (x,y,z:uniset)(seq (union (union x y) z) (union x (union y z))).
Proof.
Unfold seq; Unfold union; Unfold charac.
NewDestruct x; NewDestruct y; NewDestruct z; Auto with bool.
Qed.
Hints Resolve union_ass.

Lemma seq_left :  (x,y,z:uniset)(seq x y)->(seq (union x z) (union y z)).
Proof.
Unfold seq; Unfold union; Unfold charac.
NewDestruct x; NewDestruct y; NewDestruct z.
Intros; Elim H; Auto.
Qed.
Hints Resolve seq_left.

Lemma seq_right : (x,y,z:uniset)(seq x y)->(seq (union z x) (union z y)).
Proof.
Unfold seq; Unfold union; Unfold charac.
NewDestruct x; NewDestruct y; NewDestruct z.
Intros; Elim H; Auto.
Qed.
Hints Resolve seq_right.


(** All the proofs that follow duplicate [Multiset_of_A] *)

(** Here we should make uniset an abstract datatype, by hiding [Charac],
    [union], [charac]; all further properties are proved abstractly *)

Require Permut.

Lemma union_rotate :
   (x,y,z:uniset)(seq (union x (union y z)) (union z (union x y))).
Proof.
Intros; Apply (op_rotate uniset union seq); Auto.
Exact seq_trans.
Qed.

Lemma seq_congr : (x,y,z,t:uniset)(seq x y)->(seq z t)->
                  (seq (union x z) (union y t)).
Proof.
Intros; Apply (cong_congr uniset union seq); Auto.
Exact seq_trans.
Qed.

Lemma union_perm_left :
   (x,y,z:uniset)(seq (union x (union y z)) (union y (union x z))).
Proof.
Intros; Apply (perm_left uniset union seq); Auto.
Exact seq_trans.
Qed.

Lemma uniset_twist1 : (x,y,z,t:uniset)
   (seq (union x (union (union y z) t)) (union (union y (union x t)) z)).
Proof.
Intros; Apply (twist uniset union seq); Auto.
Exact seq_trans.
Qed.

Lemma uniset_twist2 : (x,y,z,t:uniset)
   (seq (union x (union (union y z) t)) (union (union y (union x z)) t)).
Proof.
Intros; Apply seq_trans with (union (union x (union y z)) t).
Apply seq_sym; Apply union_ass.
Apply seq_left; Apply union_perm_left.
Qed.

(** specific for treesort *)

Lemma treesort_twist1 : (x,y,z,t,u:uniset) (seq u (union y z)) ->
   (seq (union x (union u t)) (union (union y (union x t)) z)).
Proof.
Intros; Apply seq_trans with (union x (union (union y z) t)).
Apply seq_right; Apply seq_left; Trivial.
Apply uniset_twist1.
Qed.

Lemma treesort_twist2 : (x,y,z,t,u:uniset) (seq u (union y z)) ->
   (seq (union x (union u t)) (union (union y (union x z)) t)).
Proof.
Intros; Apply seq_trans with (union x (union (union y z) t)).
Apply seq_right; Apply seq_left; Trivial.
Apply uniset_twist2.
Qed.


(*i theory of minter to do similarly 
Require Min.
(* uniset intersection *)
Definition minter := [m1,m2:uniset]
    (Charac [a:A](andb (charac m1 a)(charac m2 a))).
i*)

End defs.

Unset Implicit Arguments.