author  wenzelm 
Tue, 10 Dec 1996 14:09:32 +0100  
changeset 2368  d394336997cf 
parent 2261  d926157c0a6a 
child 2372  a2999e19703b 
permissions  rwrr 
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 

923  12 
types 
13 
'a set 

14 

15 
arities 

16 
set :: (term) term 

17 

18 
instance 

19 
set :: (term) {ord, minus} 

20 

21 
consts 

1370
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset

22 
"{}" :: 'a set ("{}") 
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset

23 
insert :: ['a, 'a set] => 'a set 
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset

24 
Collect :: ('a => bool) => 'a set (*comprehension*) 
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset

25 
Compl :: ('a set) => 'a set (*complement*) 
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset

26 
Int :: ['a set, 'a set] => 'a set (infixl 70) 
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset

27 
Un :: ['a set, 'a set] => 'a set (infixl 65) 
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset

28 
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

29 
UNION1 :: ['a => 'b set] => 'b set (binder "UN " 10) 
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset

30 
INTER1 :: ['a => 'b set] => 'b set (binder "INT " 10) 
2261  31 
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

32 
Pow :: 'a set => 'a set set (*powerset*) 
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset

33 
range :: ('a => 'b) => 'b set (*of function*) 
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset

34 
Ball, Bex :: ['a set, 'a => bool] => bool (*bounded quantifiers*) 
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset

35 
inj, surj :: ('a => 'b) => bool (*inj/surjective*) 
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset

36 
inj_onto :: ['a => 'b, 'a set] => bool 
1962
e60a230da179
Corrected associativity: must be to right, as the type dictatess
paulson
parents:
1883
diff
changeset

37 
"``" :: ['a => 'b, 'a set] => ('b set) (infixr 90) 
2261  38 
(*membership*) 
39 
"op :" :: ['a, 'a set] => bool ("(_/ : _)" [50, 51] 50) 

923  40 

41 

2261  42 

43 
(** Additional concrete syntax **) 

44 

923  45 
syntax 
46 

2261  47 
"op :" :: ['a, 'a set] => bool ("op :") 
1531  48 

2261  49 
UNIV :: 'a set 
50 

51 
(* Infix syntax for nonmembership *) 

923  52 

2261  53 
"op ~:" :: ['a, 'a set] => bool ("(_/ ~: _)" [50, 51] 50) 
54 
"op ~:" :: ['a, 'a set] => bool ("op ~:") 

923  55 

2261  56 
"@Finset" :: args => 'a set ("{(_)}") 
57 

58 
"@Coll" :: [pttrn, bool] => 'a set ("(1{_./ _})") 

59 
"@SetCompr" :: ['a, idts, bool] => 'a set ("(1{_ /_./ _})") 

923  60 

61 
(* Big Intersection / Union *) 

62 

1370
7361ac9b024d
removed quotes from types in consts and syntax sections
clasohm
parents:
1273
diff
changeset

63 
"@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

64 
"@UNION" :: [pttrn, 'a set, 'b set] => 'b set ("(3UN _:_./ _)" 10) 
923  65 

66 
(* Bounded Quantifiers *) 

67 

2368  68 
"@Ball" :: [pttrn, 'a set, bool] => bool ("(3! _:_./ _)" [0, 0, 10] 10) 
69 
"@Bex" :: [pttrn, 'a set, bool] => bool ("(3? _:_./ _)" [0, 0, 10] 10) 

70 
"*Ball" :: [pttrn, 'a set, bool] => bool ("(3ALL _:_./ _)" [0, 0, 10] 10) 

71 
"*Bex" :: [pttrn, 'a set, bool] => bool ("(3EX _:_./ _)" [0, 0, 10] 10) 

923  72 

73 
translations 

1531  74 
"UNIV" == "Compl {}" 
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)" 

80 
"INT x:A. B" == "INTER A (%x. B)" 

81 
"UN x:A. B" == "UNION A (%x. B)" 

82 
"! x:A. P" == "Ball A (%x. P)" 

83 
"? x:A. P" == "Bex A (%x. P)" 

84 
"ALL x:A. P" => "Ball A (%x. P)" 

85 
"EX x:A. P" => "Bex A (%x. P)" 

86 

87 

2261  88 
syntax (symbols) 
89 
"op Int" :: ['a set, 'a set] => 'a set (infixl "\\<inter>" 70) 

90 
"op Un" :: ['a set, 'a set] => 'a set (infixl "\\<union>" 65) 

91 
"op :" :: ['a, 'a set] => bool ("(_/ \\<in> _)" [50, 51] 50) 

92 
"op :" :: ['a, 'a set] => bool ("op \\<in>") 

93 
"op ~:" :: ['a, 'a set] => bool ("(_/ \\<notin> _)" [50, 51] 50) 

94 
"op ~:" :: ['a, 'a set] => bool ("op \\<notin>") 

95 
"UN " :: [idts, bool] => bool ("(3\\<Union> _./ _)" 10) 

96 
"INT " :: [idts, bool] => bool ("(3\\<Inter> _./ _)" 10) 

97 
"@UNION" :: [pttrn, 'a set, 'b set] => 'b set ("(3\\<Union> _\\<in>_./ _)" 10) 

98 
"@INTER" :: [pttrn, 'a set, 'b set] => 'b set ("(3\\<Inter> _\\<in>_./ _)" 10) 

99 
Union :: (('a set) set) => 'a set ("\\<Union> _" [90] 90) 

100 
Inter :: (('a set) set) => 'a set ("\\<Inter> _" [90] 90) 

2368  101 
"@Ball" :: [pttrn, 'a set, bool] => bool ("(3\\<forall> _\\<in>_./ _)" [0, 0, 10] 10) 
102 
"@Bex" :: [pttrn, 'a set, bool] => bool ("(3\\<exists> _\\<in>_./ _)" [0, 0, 10] 10) 

103 
"*Ball" :: [pttrn, 'a set, bool] => bool ("(3\\<forall> _\\<in>_./ _)" [0, 0, 10] 10) 

104 
"*Bex" :: [pttrn, 'a set, bool] => bool ("(3\\<exists> _\\<in>_./ _)" [0, 0, 10] 10) 

2261  105 

106 

107 

108 
(** Rules and definitions **) 

109 

923  110 
rules 
111 

112 
(* Isomorphisms between Predicates and Sets *) 

113 

114 
mem_Collect_eq "(a : {x.P(x)}) = P(a)" 

115 
Collect_mem_eq "{x.x:A} = A" 

116 

117 

118 
defs 

2261  119 

923  120 
Ball_def "Ball A P == ! x. x:A > P(x)" 
121 
Bex_def "Bex A P == ? x. x:A & P(x)" 

122 
subset_def "A <= B == ! x:A. x:B" 

123 
Compl_def "Compl(A) == {x. ~x:A}" 

124 
Un_def "A Un B == {x.x:A  x:B}" 

125 
Int_def "A Int B == {x.x:A & x:B}" 

126 
set_diff_def "A  B == {x. x:A & ~x:B}" 

127 
INTER_def "INTER A B == {y. ! x:A. y: B(x)}" 

128 
UNION_def "UNION A B == {y. ? x:A. y: B(x)}" 

129 
INTER1_def "INTER1(B) == INTER {x.True} B" 

130 
UNION1_def "UNION1(B) == UNION {x.True} B" 

131 
Inter_def "Inter(S) == (INT x:S. x)" 

132 
Union_def "Union(S) == (UN x:S. x)" 

133 
Pow_def "Pow(A) == {B. B <= A}" 

134 
empty_def "{} == {x. False}" 

135 
insert_def "insert a B == {x.x=a} Un B" 

136 
image_def "f``A == {y. ? x:A. y=f(x)}" 

137 
inj_def "inj(f) == ! x y. f(x)=f(y) > x=y" 

138 
inj_onto_def "inj_onto f A == ! x:A. ! y:A. f(x)=f(y) > x=y" 

139 
surj_def "surj(f) == ! y. ? x. y=f(x)" 

140 

1273  141 
(* start 8bit 1 *) 
142 
(* end 8bit 1 *) 

143 

923  144 
end 
145 

2261  146 

923  147 
ML 
148 

149 
local 

150 

151 
(* Translates between { e  x1..xn. P} and {u. ? x1..xn. u=e & P} *) 

152 
(* {y. ? x1..xn. y = e & P} is only translated if [0..n] subset bvs(e) *) 

153 

154 
val ex_tr = snd(mk_binder_tr("? ","Ex")); 

155 

156 
fun nvars(Const("_idts",_) $ _ $ idts) = nvars(idts)+1 

157 
 nvars(_) = 1; 

158 

159 
fun setcompr_tr[e,idts,b] = 

160 
let val eq = Syntax.const("op =") $ Bound(nvars(idts)) $ e 

161 
val P = Syntax.const("op &") $ eq $ b 

162 
val exP = ex_tr [idts,P] 

163 
in Syntax.const("Collect") $ Abs("",dummyT,exP) end; 

164 

165 
val ex_tr' = snd(mk_binder_tr' ("Ex","DUMMY")); 

166 

167 
fun setcompr_tr'[Abs(_,_,P)] = 

168 
let fun ok(Const("Ex",_)$Abs(_,_,P),n) = ok(P,n+1) 

169 
 ok(Const("op &",_) $ (Const("op =",_) $ Bound(m) $ e) $ _, n) = 

170 
if n>0 andalso m=n andalso 

171 
((0 upto (n1)) subset add_loose_bnos(e,0,[])) 

172 
then () else raise Match 

173 

174 
fun tr'(_ $ abs) = 

175 
let val _ $ idts $ (_ $ (_ $ _ $ e) $ Q) = ex_tr'[abs] 

176 
in Syntax.const("@SetCompr") $ e $ idts $ Q end 

177 
in ok(P,0); tr'(P) end; 

178 

179 
in 

180 

181 
val parse_translation = [("@SetCompr", setcompr_tr)]; 

182 
val print_translation = [("Collect", setcompr_tr')]; 

183 
val print_ast_translation = 

184 
map HOL.alt_ast_tr' [("@Ball", "*Ball"), ("@Bex", "*Bex")]; 

185 

186 
end; 