author | paulson |
Wed, 13 Nov 1996 10:47:08 +0100 | |
changeset 2183 | 8d42a7bccf0b |
parent 2006 | 72754e060aa2 |
child 2261 | d926157c0a6a |
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 |
||
9 |
types |
|
10 |
'a set |
|
11 |
||
12 |
arities |
|
13 |
set :: (term) term |
|
14 |
||
15 |
instance |
|
16 |
set :: (term) {ord, minus} |
|
17 |
||
18 |
consts |
|
1370
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
19 |
"{}" :: 'a set ("{}") |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
20 |
insert :: ['a, 'a set] => 'a set |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
21 |
Collect :: ('a => bool) => 'a set (*comprehension*) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
22 |
Compl :: ('a set) => 'a set (*complement*) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
23 |
Int :: ['a set, 'a set] => 'a set (infixl 70) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
24 |
Un :: ['a set, 'a set] => 'a set (infixl 65) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
25 |
UNION, INTER :: ['a set, 'a => 'b set] => 'b set (*general*) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
26 |
UNION1 :: ['a => 'b set] => 'b set (binder "UN " 10) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
27 |
INTER1 :: ['a => 'b set] => 'b set (binder "INT " 10) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
28 |
Union, Inter :: (('a set)set) => 'a set (*of a set*) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
29 |
Pow :: 'a set => 'a set set (*powerset*) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
30 |
range :: ('a => 'b) => 'b set (*of function*) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
31 |
Ball, Bex :: ['a set, 'a => bool] => bool (*bounded quantifiers*) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
32 |
inj, surj :: ('a => 'b) => bool (*inj/surjective*) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
33 |
inj_onto :: ['a => 'b, 'a set] => bool |
1962
e60a230da179
Corrected associativity: must be to right, as the type dictatess
paulson
parents:
1883
diff
changeset
|
34 |
"``" :: ['a => 'b, 'a set] => ('b set) (infixr 90) |
2006 | 35 |
(*membership*) |
36 |
"op :" :: ['a, 'a set] => bool ("(_/ : _)" [50,51] 50) |
|
923 | 37 |
|
38 |
||
39 |
syntax |
|
40 |
||
1531 | 41 |
UNIV :: 'a set |
42 |
||
2006 | 43 |
(*infix synatx for non-membership*) |
44 |
"op ~:" :: ['a, 'a set] => bool ("(_/ ~: _)" [50,51] 50) |
|
923 | 45 |
|
1370
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
46 |
"@Finset" :: args => 'a set ("{(_)}") |
923 | 47 |
|
1370
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
48 |
"@Coll" :: [pttrn, bool] => 'a set ("(1{_./ _})") |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
49 |
"@SetCompr" :: ['a, idts, bool] => 'a set ("(1{_ |/_./ _})") |
923 | 50 |
|
51 |
(* Big Intersection / Union *) |
|
52 |
||
1370
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
53 |
"@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
|
54 |
"@UNION" :: [pttrn, 'a set, 'b set] => 'b set ("(3UN _:_./ _)" 10) |
923 | 55 |
|
56 |
(* Bounded Quantifiers *) |
|
57 |
||
1370
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
58 |
"@Ball" :: [pttrn, 'a set, bool] => bool ("(3! _:_./ _)" 10) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
59 |
"@Bex" :: [pttrn, 'a set, bool] => bool ("(3? _:_./ _)" 10) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
60 |
"*Ball" :: [pttrn, 'a set, bool] => bool ("(3ALL _:_./ _)" 10) |
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset
|
61 |
"*Bex" :: [pttrn, 'a set, bool] => bool ("(3EX _:_./ _)" 10) |
923 | 62 |
|
63 |
translations |
|
1531 | 64 |
"UNIV" == "Compl {}" |
1883 | 65 |
"range(f)" == "f``UNIV" |
923 | 66 |
"x ~: y" == "~ (x : y)" |
67 |
"{x, xs}" == "insert x {xs}" |
|
68 |
"{x}" == "insert x {}" |
|
69 |
"{x. P}" == "Collect (%x. P)" |
|
70 |
"INT x:A. B" == "INTER A (%x. B)" |
|
71 |
"UN x:A. B" == "UNION A (%x. B)" |
|
72 |
"! x:A. P" == "Ball A (%x. P)" |
|
73 |
"? x:A. P" == "Bex A (%x. P)" |
|
74 |
"ALL x:A. P" => "Ball A (%x. P)" |
|
75 |
"EX x:A. P" => "Bex A (%x. P)" |
|
76 |
||
77 |
||
78 |
rules |
|
79 |
||
80 |
(* Isomorphisms between Predicates and Sets *) |
|
81 |
||
82 |
mem_Collect_eq "(a : {x.P(x)}) = P(a)" |
|
83 |
Collect_mem_eq "{x.x:A} = A" |
|
84 |
||
85 |
||
86 |
defs |
|
87 |
Ball_def "Ball A P == ! x. x:A --> P(x)" |
|
88 |
Bex_def "Bex A P == ? x. x:A & P(x)" |
|
89 |
subset_def "A <= B == ! x:A. x:B" |
|
90 |
Compl_def "Compl(A) == {x. ~x:A}" |
|
91 |
Un_def "A Un B == {x.x:A | x:B}" |
|
92 |
Int_def "A Int B == {x.x:A & x:B}" |
|
93 |
set_diff_def "A - B == {x. x:A & ~x:B}" |
|
94 |
INTER_def "INTER A B == {y. ! x:A. y: B(x)}" |
|
95 |
UNION_def "UNION A B == {y. ? x:A. y: B(x)}" |
|
96 |
INTER1_def "INTER1(B) == INTER {x.True} B" |
|
97 |
UNION1_def "UNION1(B) == UNION {x.True} B" |
|
98 |
Inter_def "Inter(S) == (INT x:S. x)" |
|
99 |
Union_def "Union(S) == (UN x:S. x)" |
|
100 |
Pow_def "Pow(A) == {B. B <= A}" |
|
101 |
empty_def "{} == {x. False}" |
|
102 |
insert_def "insert a B == {x.x=a} Un B" |
|
103 |
image_def "f``A == {y. ? x:A. y=f(x)}" |
|
104 |
inj_def "inj(f) == ! x y. f(x)=f(y) --> x=y" |
|
105 |
inj_onto_def "inj_onto f A == ! x:A. ! y:A. f(x)=f(y) --> x=y" |
|
106 |
surj_def "surj(f) == ! y. ? x. y=f(x)" |
|
107 |
||
1273 | 108 |
(* start 8bit 1 *) |
109 |
(* end 8bit 1 *) |
|
110 |
||
923 | 111 |
end |
112 |
||
113 |
ML |
|
114 |
||
115 |
local |
|
116 |
||
117 |
(* Translates between { e | x1..xn. P} and {u. ? x1..xn. u=e & P} *) |
|
118 |
(* {y. ? x1..xn. y = e & P} is only translated if [0..n] subset bvs(e) *) |
|
119 |
||
120 |
val ex_tr = snd(mk_binder_tr("? ","Ex")); |
|
121 |
||
122 |
fun nvars(Const("_idts",_) $ _ $ idts) = nvars(idts)+1 |
|
123 |
| nvars(_) = 1; |
|
124 |
||
125 |
fun setcompr_tr[e,idts,b] = |
|
126 |
let val eq = Syntax.const("op =") $ Bound(nvars(idts)) $ e |
|
127 |
val P = Syntax.const("op &") $ eq $ b |
|
128 |
val exP = ex_tr [idts,P] |
|
129 |
in Syntax.const("Collect") $ Abs("",dummyT,exP) end; |
|
130 |
||
131 |
val ex_tr' = snd(mk_binder_tr' ("Ex","DUMMY")); |
|
132 |
||
133 |
fun setcompr_tr'[Abs(_,_,P)] = |
|
134 |
let fun ok(Const("Ex",_)$Abs(_,_,P),n) = ok(P,n+1) |
|
135 |
| ok(Const("op &",_) $ (Const("op =",_) $ Bound(m) $ e) $ _, n) = |
|
136 |
if n>0 andalso m=n andalso |
|
137 |
((0 upto (n-1)) subset add_loose_bnos(e,0,[])) |
|
138 |
then () else raise Match |
|
139 |
||
140 |
fun tr'(_ $ abs) = |
|
141 |
let val _ $ idts $ (_ $ (_ $ _ $ e) $ Q) = ex_tr'[abs] |
|
142 |
in Syntax.const("@SetCompr") $ e $ idts $ Q end |
|
143 |
in ok(P,0); tr'(P) end; |
|
144 |
||
145 |
in |
|
146 |
||
147 |
val parse_translation = [("@SetCompr", setcompr_tr)]; |
|
148 |
val print_translation = [("Collect", setcompr_tr')]; |
|
149 |
val print_ast_translation = |
|
150 |
map HOL.alt_ast_tr' [("@Ball", "*Ball"), ("@Bex", "*Bex")]; |
|
151 |
||
152 |
end; |
|
153 |