author | berghofe |
Tue, 30 Jun 1998 20:51:15 +0200 | |
changeset 5102 | 8c782c25a11e |
parent 4761 | 1681b32dd134 |
child 5144 | 7ac22e5a05d7 |
permissions | -rw-r--r-- |
923 | 1 |
(* Title: HOL/Set.thy |
2 |
ID: $Id$ |
|
3 |
Author: Tobias Nipkow |
|
4 |
Copyright 1993 University of Cambridge |
|
5 |
*) |
|
6 |
||
7 |
Set = Ord + |
|
8 |
||
2261 | 9 |
|
10 |
(** Core syntax **) |
|
11 |
||
3947 | 12 |
global |
13 |
||
923 | 14 |
types |
15 |
'a set |
|
16 |
||
17 |
arities |
|
18 |
set :: (term) term |
|
19 |
||
20 |
instance |
|
4761 | 21 |
set :: (term) {ord, minus, power} (* only ('a * 'a) set should be in power! *) |
923 | 22 |
|
3820 | 23 |
syntax |
24 |
"op :" :: ['a, 'a set] => bool ("op :") |
|
25 |
||
923 | 26 |
consts |
1370
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
27 |
"{}" :: 'a set ("{}") |
4159
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
paulson
parents:
4151
diff
changeset
|
28 |
UNIV :: 'a set |
1370
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
29 |
insert :: ['a, 'a set] => 'a set |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
30 |
Collect :: ('a => bool) => 'a set (*comprehension*) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
31 |
Compl :: ('a set) => 'a set (*complement*) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
32 |
Int :: ['a set, 'a set] => 'a set (infixl 70) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
33 |
Un :: ['a set, 'a set] => 'a set (infixl 65) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
34 |
UNION, INTER :: ['a set, 'a => 'b set] => 'b set (*general*) |
2261 | 35 |
Union, Inter :: (('a set) set) => 'a set (*of a set*) |
1370
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
36 |
Pow :: 'a set => 'a set set (*powerset*) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
37 |
range :: ('a => 'b) => 'b set (*of function*) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
38 |
Ball, Bex :: ['a set, 'a => bool] => bool (*bounded quantifiers*) |
1962
e60a230da179
Corrected associativity: must be to right, as the type dictatess
paulson
parents:
1883
diff
changeset
|
39 |
"``" :: ['a => 'b, 'a set] => ('b set) (infixr 90) |
2261 | 40 |
(*membership*) |
41 |
"op :" :: ['a, 'a set] => bool ("(_/ : _)" [50, 51] 50) |
|
923 | 42 |
|
43 |
||
2261 | 44 |
|
45 |
(** Additional concrete syntax **) |
|
46 |
||
923 | 47 |
syntax |
48 |
||
2261 | 49 |
(* Infix syntax for non-membership *) |
923 | 50 |
|
3820 | 51 |
"op ~:" :: ['a, 'a set] => bool ("op ~:") |
2261 | 52 |
"op ~:" :: ['a, 'a set] => bool ("(_/ ~: _)" [50, 51] 50) |
923 | 53 |
|
2261 | 54 |
"@Finset" :: args => 'a set ("{(_)}") |
55 |
||
56 |
"@Coll" :: [pttrn, bool] => 'a set ("(1{_./ _})") |
|
57 |
"@SetCompr" :: ['a, idts, bool] => 'a set ("(1{_ |/_./ _})") |
|
923 | 58 |
|
59 |
(* Big Intersection / Union *) |
|
60 |
||
4159
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
paulson
parents:
4151
diff
changeset
|
61 |
INTER1 :: [pttrns, 'a => 'b set] => 'b set ("(3INT _./ _)" 10) |
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
paulson
parents:
4151
diff
changeset
|
62 |
UNION1 :: [pttrns, 'a => 'b set] => 'b set ("(3UN _./ _)" 10) |
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
paulson
parents:
4151
diff
changeset
|
63 |
|
1370
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
64 |
"@INTER" :: [pttrn, 'a set, 'b set] => 'b set ("(3INT _:_./ _)" 10) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
65 |
"@UNION" :: [pttrn, 'a set, 'b set] => 'b set ("(3UN _:_./ _)" 10) |
923 | 66 |
|
67 |
(* Bounded Quantifiers *) |
|
68 |
||
2368 | 69 |
"@Ball" :: [pttrn, 'a set, bool] => bool ("(3! _:_./ _)" [0, 0, 10] 10) |
70 |
"@Bex" :: [pttrn, 'a set, bool] => bool ("(3? _:_./ _)" [0, 0, 10] 10) |
|
71 |
"*Ball" :: [pttrn, 'a set, bool] => bool ("(3ALL _:_./ _)" [0, 0, 10] 10) |
|
72 |
"*Bex" :: [pttrn, 'a set, bool] => bool ("(3EX _:_./ _)" [0, 0, 10] 10) |
|
923 | 73 |
|
74 |
translations |
|
2261 | 75 |
"range f" == "f``UNIV" |
923 | 76 |
"x ~: y" == "~ (x : y)" |
77 |
"{x, xs}" == "insert x {xs}" |
|
78 |
"{x}" == "insert x {}" |
|
79 |
"{x. P}" == "Collect (%x. P)" |
|
4159
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
paulson
parents:
4151
diff
changeset
|
80 |
"UN x y. B" == "UN x. UN y. B" |
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
paulson
parents:
4151
diff
changeset
|
81 |
"UN x. B" == "UNION UNIV (%x. B)" |
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
paulson
parents:
4151
diff
changeset
|
82 |
"INT x y. B" == "INT x. INT y. B" |
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
paulson
parents:
4151
diff
changeset
|
83 |
"INT x. B" == "INTER UNIV (%x. B)" |
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
paulson
parents:
4151
diff
changeset
|
84 |
"UN x:A. B" == "UNION A (%x. B)" |
923 | 85 |
"INT x:A. B" == "INTER A (%x. B)" |
86 |
"! x:A. P" == "Ball A (%x. P)" |
|
87 |
"? x:A. P" == "Bex A (%x. P)" |
|
88 |
"ALL x:A. P" => "Ball A (%x. P)" |
|
89 |
"EX x:A. P" => "Bex A (%x. P)" |
|
90 |
||
2388 | 91 |
syntax ("" output) |
3820 | 92 |
"_setle" :: ['a set, 'a set] => bool ("op <=") |
2388 | 93 |
"_setle" :: ['a set, 'a set] => bool ("(_/ <= _)" [50, 51] 50) |
3820 | 94 |
"_setless" :: ['a set, 'a set] => bool ("op <") |
2684 | 95 |
"_setless" :: ['a set, 'a set] => bool ("(_/ < _)" [50, 51] 50) |
923 | 96 |
|
2261 | 97 |
syntax (symbols) |
3820 | 98 |
"_setle" :: ['a set, 'a set] => bool ("op \\<subseteq>") |
2388 | 99 |
"_setle" :: ['a set, 'a set] => bool ("(_/ \\<subseteq> _)" [50, 51] 50) |
3820 | 100 |
"_setless" :: ['a set, 'a set] => bool ("op \\<subset>") |
2684 | 101 |
"_setless" :: ['a set, 'a set] => bool ("(_/ \\<subset> _)" [50, 51] 50) |
2261 | 102 |
"op Int" :: ['a set, 'a set] => 'a set (infixl "\\<inter>" 70) |
103 |
"op Un" :: ['a set, 'a set] => 'a set (infixl "\\<union>" 65) |
|
3820 | 104 |
"op :" :: ['a, 'a set] => bool ("op \\<in>") |
2261 | 105 |
"op :" :: ['a, 'a set] => bool ("(_/ \\<in> _)" [50, 51] 50) |
3820 | 106 |
"op ~:" :: ['a, 'a set] => bool ("op \\<notin>") |
2261 | 107 |
"op ~:" :: ['a, 'a set] => bool ("(_/ \\<notin> _)" [50, 51] 50) |
108 |
"UN " :: [idts, bool] => bool ("(3\\<Union> _./ _)" 10) |
|
109 |
"INT " :: [idts, bool] => bool ("(3\\<Inter> _./ _)" 10) |
|
4159
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
paulson
parents:
4151
diff
changeset
|
110 |
"UNION1" :: [pttrn, 'b set] => 'b set ("(3\\<Union> _./ _)" 10) |
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
paulson
parents:
4151
diff
changeset
|
111 |
"INTER1" :: [pttrn, 'b set] => 'b set ("(3\\<Inter> _./ _)" 10) |
2261 | 112 |
"@UNION" :: [pttrn, 'a set, 'b set] => 'b set ("(3\\<Union> _\\<in>_./ _)" 10) |
113 |
"@INTER" :: [pttrn, 'a set, 'b set] => 'b set ("(3\\<Inter> _\\<in>_./ _)" 10) |
|
114 |
Union :: (('a set) set) => 'a set ("\\<Union> _" [90] 90) |
|
115 |
Inter :: (('a set) set) => 'a set ("\\<Inter> _" [90] 90) |
|
2368 | 116 |
"@Ball" :: [pttrn, 'a set, bool] => bool ("(3\\<forall> _\\<in>_./ _)" [0, 0, 10] 10) |
117 |
"@Bex" :: [pttrn, 'a set, bool] => bool ("(3\\<exists> _\\<in>_./ _)" [0, 0, 10] 10) |
|
2372 | 118 |
|
119 |
syntax (symbols output) |
|
2368 | 120 |
"*Ball" :: [pttrn, 'a set, bool] => bool ("(3\\<forall> _\\<in>_./ _)" [0, 0, 10] 10) |
121 |
"*Bex" :: [pttrn, 'a set, bool] => bool ("(3\\<exists> _\\<in>_./ _)" [0, 0, 10] 10) |
|
2261 | 122 |
|
2412 | 123 |
translations |
2965
afbda7e26f15
improved translations for subset symbols syntax: constraints;
wenzelm
parents:
2912
diff
changeset
|
124 |
"op \\<subseteq>" => "op <= :: [_ set, _ set] => bool" |
afbda7e26f15
improved translations for subset symbols syntax: constraints;
wenzelm
parents:
2912
diff
changeset
|
125 |
"op \\<subset>" => "op < :: [_ set, _ set] => bool" |
2412 | 126 |
|
2261 | 127 |
|
128 |
||
129 |
(** Rules and definitions **) |
|
130 |
||
3947 | 131 |
local |
132 |
||
923 | 133 |
rules |
134 |
||
135 |
(* Isomorphisms between Predicates and Sets *) |
|
136 |
||
3842 | 137 |
mem_Collect_eq "(a : {x. P(x)}) = P(a)" |
138 |
Collect_mem_eq "{x. x:A} = A" |
|
923 | 139 |
|
140 |
||
141 |
defs |
|
2261 | 142 |
|
923 | 143 |
Ball_def "Ball A P == ! x. x:A --> P(x)" |
144 |
Bex_def "Bex A P == ? x. x:A & P(x)" |
|
145 |
subset_def "A <= B == ! x:A. x:B" |
|
3222
726a9b069947
Distributed Psubset stuff to basic set theory files, incl Finite.
nipkow
parents:
2965
diff
changeset
|
146 |
psubset_def "A < B == (A::'a set) <= B & ~ A=B" |
2393 | 147 |
Compl_def "Compl A == {x. ~x:A}" |
3842 | 148 |
Un_def "A Un B == {x. x:A | x:B}" |
149 |
Int_def "A Int B == {x. x:A & x:B}" |
|
923 | 150 |
set_diff_def "A - B == {x. x:A & ~x:B}" |
151 |
INTER_def "INTER A B == {y. ! x:A. y: B(x)}" |
|
152 |
UNION_def "UNION A B == {y. ? x:A. y: B(x)}" |
|
2393 | 153 |
Inter_def "Inter S == (INT x:S. x)" |
154 |
Union_def "Union S == (UN x:S. x)" |
|
155 |
Pow_def "Pow A == {B. B <= A}" |
|
923 | 156 |
empty_def "{} == {x. False}" |
4159
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
paulson
parents:
4151
diff
changeset
|
157 |
UNIV_def "UNIV == {x. True}" |
3842 | 158 |
insert_def "insert a B == {x. x=a} Un B" |
923 | 159 |
image_def "f``A == {y. ? x:A. y=f(x)}" |
1273 | 160 |
|
923 | 161 |
end |
162 |
||
2261 | 163 |
|
923 | 164 |
ML |
165 |
||
166 |
local |
|
167 |
||
2388 | 168 |
(* Set inclusion *) |
169 |
||
4151 | 170 |
fun le_tr' _ (*op <=*) (Type ("fun", (Type ("set", _) :: _))) ts = |
2388 | 171 |
list_comb (Syntax.const "_setle", ts) |
4151 | 172 |
| le_tr' _ (*op <=*) _ _ = raise Match; |
2388 | 173 |
|
4151 | 174 |
fun less_tr' _ (*op <*) (Type ("fun", (Type ("set", _) :: _))) ts = |
2684 | 175 |
list_comb (Syntax.const "_setless", ts) |
4151 | 176 |
| less_tr' _ (*op <*) _ _ = raise Match; |
2684 | 177 |
|
2388 | 178 |
|
923 | 179 |
(* Translates between { e | x1..xn. P} and {u. ? x1..xn. u=e & P} *) |
180 |
(* {y. ? x1..xn. y = e & P} is only translated if [0..n] subset bvs(e) *) |
|
181 |
||
182 |
val ex_tr = snd(mk_binder_tr("? ","Ex")); |
|
183 |
||
184 |
fun nvars(Const("_idts",_) $ _ $ idts) = nvars(idts)+1 |
|
185 |
| nvars(_) = 1; |
|
186 |
||
187 |
fun setcompr_tr[e,idts,b] = |
|
188 |
let val eq = Syntax.const("op =") $ Bound(nvars(idts)) $ e |
|
189 |
val P = Syntax.const("op &") $ eq $ b |
|
190 |
val exP = ex_tr [idts,P] |
|
191 |
in Syntax.const("Collect") $ Abs("",dummyT,exP) end; |
|
192 |
||
193 |
val ex_tr' = snd(mk_binder_tr' ("Ex","DUMMY")); |
|
194 |
||
195 |
fun setcompr_tr'[Abs(_,_,P)] = |
|
196 |
let fun ok(Const("Ex",_)$Abs(_,_,P),n) = ok(P,n+1) |
|
197 |
| ok(Const("op &",_) $ (Const("op =",_) $ Bound(m) $ e) $ _, n) = |
|
198 |
if n>0 andalso m=n andalso |
|
199 |
((0 upto (n-1)) subset add_loose_bnos(e,0,[])) |
|
200 |
then () else raise Match |
|
201 |
||
202 |
fun tr'(_ $ abs) = |
|
203 |
let val _ $ idts $ (_ $ (_ $ _ $ e) $ Q) = ex_tr'[abs] |
|
204 |
in Syntax.const("@SetCompr") $ e $ idts $ Q end |
|
205 |
in ok(P,0); tr'(P) end; |
|
206 |
||
207 |
in |
|
208 |
||
209 |
val parse_translation = [("@SetCompr", setcompr_tr)]; |
|
210 |
val print_translation = [("Collect", setcompr_tr')]; |
|
2684 | 211 |
val typed_print_translation = [("op <=", le_tr'), ("op <", less_tr')]; |
923 | 212 |
val print_ast_translation = |
213 |
map HOL.alt_ast_tr' [("@Ball", "*Ball"), ("@Bex", "*Bex")]; |
|
214 |
||
215 |
end; |