-
Notifications
You must be signed in to change notification settings - Fork 4
/
sets.ml
321 lines (245 loc) · 8.52 KB
/
sets.ml
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
type __ = Obj.t
let __ = let rec f _ = Obj.repr f in Obj.repr f
type nat =
| O
| S of nat
type comparison =
| Eq
| Lt
| Gt
type compareSpecT =
| CompEqT
| CompLtT
| CompGtT
(** val id : 'a1 -> 'a1 **)
let id x =
x
type 'a sig0 =
'a
(* singleton inductive, whose constructor was exist *)
type 'a eqDec = 'a -> 'a -> bool
type 'a ordered = { eq_dec : 'a eqDec; compare : ('a -> 'a -> comparison);
compare_spec : ('a -> 'a -> compareSpecT) }
(** val compare_spec : 'a1 ordered -> 'a1 -> 'a1 -> compareSpecT **)
let compare_spec x = x.compare_spec
type ('a, 'tree) breakResult =
| BreakLeaf
| BreakNode of 'tree * 'a * 'tree
type ('a, 'tree) insertResult =
| InsertFound
| Inserted of 'tree
type ('a, 'tree) delminResult =
| DelminLeaf
| DelminNode of 'a * 'tree
type ('a, 'tree) delmaxResult =
| DelmaxLeaf
| DelmaxNode of 'a * 'tree
type ('a, 'tree) deleteResult =
| DelNotFound
| Deleted of 'tree
type 'a tree = { leaf : __; break : (__ -> __ -> ('a, __) breakResult);
insert : ('a -> __ -> __ -> ('a, __) insertResult);
join : (__ -> __ -> 'a -> __ -> __ -> __ -> __);
delmin : (__ -> __ -> ('a, __) delminResult);
delmax : (__ -> __ -> ('a, __) delmaxResult);
delete : ('a -> __ -> __ -> ('a, __) deleteResult) }
type 'a tree0 = __
(** val leaf : 'a1 ordered -> 'a1 tree -> 'a1 tree0 **)
let leaf _ x = x.leaf
(** val break :
'a1 ordered -> 'a1 tree -> 'a1 tree0 -> ('a1, 'a1 tree0) breakResult **)
let break ordA0 tree1 t =
tree1.break __ t
(** val join :
'a1 ordered -> 'a1 tree -> 'a1 tree0 -> 'a1 -> 'a1 tree0 -> 'a1 tree0 **)
let join ordA0 tree1 tl d tr =
tree1.join __ tl d __ tr __
(** val delmin :
'a1 ordered -> 'a1 tree -> 'a1 tree0 -> ('a1, 'a1 tree0) delminResult **)
let delmin ordA0 tree1 t =
tree1.delmin __ t
(** val enat_xrect : (__ -> (__ -> __ -> 'a1) -> 'a1) -> 'a1 **)
let enat_xrect x =
let rec f x0 =
x x0 (fun y _ -> f y)
in f __
type a (* AXIOM TO BE REALIZED *)
(** val ordA : a ordered **)
let ordA =
failwith "AXIOM TO BE REALIZED"
(** val treeA : a tree **)
let treeA =
failwith "AXIOM TO BE REALIZED"
type findResult =
| Found
| NotFound
(** val find : a -> a tree0 -> findResult **)
let find x t =
enat_xrect (fun _ recurse _ t0 _ ->
match break ordA treeA t0 with
| BreakLeaf -> NotFound
| BreakNode (tl, d, tr) ->
(match ordA.compare_spec x d with
| CompEqT -> Found
| CompLtT -> recurse __ __ __ tl __
| CompGtT -> recurse __ __ __ tr __)) __ t __
type splitResult =
| Split of bool * a tree0 * a tree0
(** val split : a -> a tree0 -> splitResult **)
let split x t =
enat_xrect (fun _ recurse _ t0 _ ->
match break ordA treeA t0 with
| BreakLeaf -> Split (false, t0, t0)
| BreakNode (tl, d, tr) ->
(match ordA.compare_spec x d with
| CompEqT -> Split (true, tl, tr)
| CompLtT ->
let h = recurse __ __ __ tl __ in
let Split (found, x0, x1) = h in
Split (found, x0, (join ordA treeA x1 d tr))
| CompGtT ->
let h = recurse __ __ __ tr __ in
let Split (found, x0, x1) = h in
Split (found, (join ordA treeA tl d x0), x1))) __ t __
type unionResult =
a tree0
(* singleton inductive, whose constructor was UnionResult *)
(** val union : a tree0 -> a tree0 -> unionResult **)
let union t1 t2 =
enat_xrect (fun _ recurse _ _ _ t3 t4 ->
match break ordA treeA t3 with
| BreakLeaf -> t4
| BreakNode (tl, d, tr) ->
let Split (found, x, x0) = split d t4 in
let h = recurse __ __ __ __ __ tl x in
let h0 = recurse __ __ __ __ __ tr x0 in join ordA treeA h d h0) __ __ __
t1 t2
(** val delete_free_delmin : a tree0 -> (a, a tree0) delminResult **)
let delete_free_delmin t =
enat_xrect (fun _ recurse _ _ t0 ->
match break ordA treeA t0 with
| BreakLeaf -> DelminLeaf
| BreakNode (tl, d, tr) ->
let dr = recurse __ __ __ __ tl in
(match dr with
| DelminLeaf -> DelminNode (d, tr)
| DelminNode (m, t1) -> DelminNode (m, (join ordA treeA t1 d tr)))) __
__ t
(** val merge : a tree0 -> a tree0 -> a tree0 **)
let merge t1 t2 =
match delmin ordA treeA t2 with
| DelminLeaf -> t1
| DelminNode (m, tr) -> join ordA treeA t1 m tr
type intersectResult =
a tree0
(* singleton inductive, whose constructor was IntersectResult *)
(** val intersection : a tree0 -> a tree0 -> intersectResult **)
let intersection t1 t2 =
enat_xrect (fun _ recurse _ _ _ t3 t4 ->
match break ordA treeA t3 with
| BreakLeaf -> treeA.leaf
| BreakNode (tl, d, tr) ->
let Split (found, x, x0) = split d t4 in
let h = recurse __ __ __ __ __ tl x in
let h0 = recurse __ __ __ __ __ tr x0 in
if found then join ordA treeA h d h0 else merge h h0) __ __ __ t1 t2
type setdiffResult =
a tree0
(* singleton inductive, whose constructor was SetDiffResult *)
(** val setdifference : a tree0 -> a tree0 -> setdiffResult **)
let setdifference t1 t2 =
enat_xrect (fun _ recurse _ _ _ t3 t4 ->
match break ordA treeA t3 with
| BreakLeaf -> treeA.leaf
| BreakNode (tl, d, tr) ->
let Split (found, x, x0) = split d t4 in
let h = recurse __ __ __ __ __ tl x in
let h0 = recurse __ __ __ __ __ tr x0 in
if found then merge h h0 else join ordA treeA h d h0) __ __ __ t1 t2
type filterResult =
a tree0
(* singleton inductive, whose constructor was Filtered *)
(** val filter : (a -> bool) -> a tree0 -> filterResult **)
let filter filt t =
enat_xrect (fun _ recurse _ t0 _ ->
match break ordA treeA t0 with
| BreakLeaf -> treeA.leaf
| BreakNode (tl, d, tr) ->
let h = recurse __ __ __ tl __ in
let h0 = recurse __ __ __ tr __ in
if filt d then join ordA treeA h d h0 else merge h h0) __ t __
type partitionResult =
| Partitioned of a tree0 * a tree0
(** val partition : (a -> bool) -> a tree0 -> partitionResult **)
let partition filt t =
enat_xrect (fun _ recurse _ t0 _ ->
match break ordA treeA t0 with
| BreakLeaf -> Partitioned (treeA.leaf, treeA.leaf)
| BreakNode (tl, d, tr) ->
let h = recurse __ __ __ tl __ in
let Partitioned (tl1, tl0) = h in
let h0 = recurse __ __ __ tr __ in
let Partitioned (tr1, tr0) = h0 in
if filt d
then Partitioned ((join ordA treeA tl1 d tr1), (merge tl0 tr0))
else Partitioned ((merge tl1 tr1), (join ordA treeA tl0 d tr0))) __ t __
type subsetResult =
| IsSubset of bool
| NotSubset of a
(** val subset : a tree0 -> a tree0 -> subsetResult **)
let subset t1 t2 =
enat_xrect (fun _ recurse _ _ _ t3 t4 ->
match break ordA treeA t3 with
| BreakLeaf ->
IsSubset
(match break ordA treeA t4 with
| BreakLeaf -> false
| BreakNode (tl, d, tr) -> true)
| BreakNode (tl, d, tr) ->
let Split (found, x, x0) = split d t4 in
if found
then let rl = recurse __ __ __ __ __ tl x in
(match rl with
| IsSubset isProperl ->
let rr = recurse __ __ __ __ __ tr x0 in
(match rr with
| IsSubset isProperr ->
IsSubset (if isProperl then true else isProperr)
| NotSubset a0 -> NotSubset a0)
| NotSubset a0 -> NotSubset a0)
else NotSubset d) __ __ __ t1 t2
(** val equiv : a tree0 -> a tree0 -> bool **)
let equiv t1 t2 =
match subset t1 t2 with
| IsSubset isProper -> if isProper then false else true
| NotSubset a0 -> false
type 't ecomprehension = 't
type 'b foldLeftResult = 'b ecomprehension
(** val fold_left :
('a1 -> a -> 'a1) -> a tree0 -> 'a1 -> 'a1 foldLeftResult **)
let fold_left foldf t b =
enat_xrect (fun _ recurse _ t0 b0 _ ->
match break ordA treeA t0 with
| BreakLeaf -> b0
| BreakNode (tl, d, tr) ->
let h = recurse __ __ __ tl b0 __ in recurse __ __ __ tr (foldf h d) __)
__ t b __
type 'b foldRightResult = 'b ecomprehension
(** val fold_right :
(a -> 'a1 -> 'a1) -> 'a1 -> a tree0 -> 'a1 foldRightResult **)
let fold_right foldf b t =
enat_xrect (fun _ recurse _ t0 b0 _ ->
match break ordA treeA t0 with
| BreakLeaf -> b0
| BreakNode (tl, d, tr) ->
let h = recurse __ __ __ tr b0 __ in recurse __ __ __ tl (foldf d h) __)
__ t b __
(** val cardinality : a tree0 -> nat ecomprehension **)
let cardinality t =
fold_right (fun x n -> S n) O t
(** val map : (a -> 'a1) -> a tree0 -> 'a1 list ecomprehension **)
let map mapf t =
fold_right (fun a0 bs -> (mapf a0) :: bs) [] t
(** val flatten : a tree0 -> a list ecomprehension **)
let flatten t =
map id t