source: src/utilities/adt/set_adt.ma @ 1274

Last change on this file since 1274 was 1223, checked in by mulligan, 9 years ago

changes

File size: 2.7 KB
Line 
1include "basics/types.ma".
2include "basics/list.ma".
3include "arithmetics/nat.ma".
4include "ASM/Util.ma".
5
6axiom set: Type[0] → Type[0].
7axiom set_empty: ∀elt_type. set elt_type.
8
9axiom set_size: ∀elt_type. set elt_type → nat.
10axiom set_to_list: ∀elt_type. set elt_type → list elt_type.
11axiom set_insert: ∀elt_type. elt_type → set elt_type → set elt_type.
12axiom set_remove: ∀elt_type. elt_type → set elt_type → set elt_type.
13axiom set_member: ∀elt_type. (elt_type → elt_type → bool) → elt_type → set elt_type → bool.
14axiom set_forall: ∀elt_type. (elt_type → bool) → set elt_type → bool.
15axiom set_exists: ∀elt_type. (elt_type → bool) → set elt_type → bool.
16axiom set_filter: ∀elt_type. (elt_type → bool) → set elt_type → set elt_type.
17axiom set_map: ∀elt_type, a. (elt_type → a) → set elt_type → set a.
18axiom set_fold: ∀elt_type, a: Type[0]. (elt_type → a → a) → set elt_type  → a → a.
19axiom set_equal: ∀elt_type: Type[0]. (elt_type → elt_type → bool) →
20  set elt_type → set elt_type → bool.
21
22(* XXX: define in terms of primitives *)
23axiom set_diff: ∀elt_type: Type[0]. set elt_type → set elt_type → set elt_type.
24
25definition set_is_empty ≝
26  λelt_type: Type[0].
27  λset: set elt_type.
28    eq_nat (set_size elt_type set) 0.
29
30definition set_singleton ≝
31  λelt_type: Type[0].
32  λelt     : elt_type.
33    set_insert elt_type elt (set_empty elt_type).
34
35definition set_from_list ≝
36  λelt_type: Type[0].
37  λthe_list: list elt_type.
38    foldr … (set_insert elt_type) (set_empty elt_type) the_list.
39
40definition set_split ≝
41  λelt_type: Type[0].
42  λpred    : elt_type → bool.
43  λthe_set : set elt_type.
44  let left  ≝ set_filter elt_type pred the_set in
45  let npred ≝ λx. ¬ (pred x) in
46  let right ≝ set_filter elt_type npred the_set in
47    〈left, right〉.
48
49definition set_subset ≝
50  λelt_type: Type[0].
51  λeq      : elt_type → elt_type → bool.
52  λleft    : set elt_type.
53  λright   : set elt_type.
54    set_forall elt_type (λelt. set_member elt_type eq elt right) left.
55
56definition set_subseteq ≝
57  λelt_type: Type[0].
58  λeq      : elt_type → elt_type → bool.
59  λleft    : set elt_type.
60  λright   : set elt_type.
61    set_equal elt_type eq left right ∧ (set_subset elt_type eq left right).
62
63definition set_union ≝
64  λelt_type: Type[0].
65  λleft    : set elt_type.
66  λright   : set elt_type.
67    set_fold elt_type (set elt_type) (set_insert elt_type) left right.
68
69definition set_intersection ≝
70  λelt_type: Type[0].
71  λeq      : elt_type → elt_type → bool.
72  λleft    : set elt_type.
73  λright   : set elt_type.
74    set_filter elt_type (λelt. set_member elt_type eq elt right) left.
Note: See TracBrowser for help on using the repository browser.