| author | berghofe | 
| Mon, 29 Jan 2001 13:28:15 +0100 | |
| changeset 10989 | 87f8a7644f91 | 
| parent 10985 | 65a8a0e2d55b | 
| child 11752 | 8941d8d15dc8 | 
| 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 | |
| 5780 
0187f936685a
Moved "instance set:...{power} from Set.thy to RelPow.thy, where is is needed
 paulson parents: 
5492diff
changeset | 21 |   set :: (term) {ord, minus}
 | 
| 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: 
1273diff
changeset | 27 |   "{}"          :: 'a set                           ("{}")
 | 
| 4159 
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
 paulson parents: 
4151diff
changeset | 28 | UNIV :: 'a set | 
| 1370 
7361ac9b024d
removed quotes from types in consts and syntax sections
 clasohm parents: 
1273diff
changeset | 29 | insert :: ['a, 'a set] => 'a set | 
| 
7361ac9b024d
removed quotes from types in consts and syntax sections
 clasohm parents: 
1273diff
changeset | 30 |   Collect       :: ('a => bool) => 'a set               (*comprehension*)
 | 
| 
7361ac9b024d
removed quotes from types in consts and syntax sections
 clasohm parents: 
1273diff
changeset | 31 | Int :: ['a set, 'a set] => 'a set (infixl 70) | 
| 
7361ac9b024d
removed quotes from types in consts and syntax sections
 clasohm parents: 
1273diff
changeset | 32 | Un :: ['a set, 'a set] => 'a set (infixl 65) | 
| 
7361ac9b024d
removed quotes from types in consts and syntax sections
 clasohm parents: 
1273diff
changeset | 33 | UNION, INTER :: ['a set, 'a => 'b set] => 'b set (*general*) | 
| 2261 | 34 |   Union, Inter  :: (('a set) set) => 'a set             (*of a set*)
 | 
| 1370 
7361ac9b024d
removed quotes from types in consts and syntax sections
 clasohm parents: 
1273diff
changeset | 35 | Pow :: 'a set => 'a set set (*powerset*) | 
| 
7361ac9b024d
removed quotes from types in consts and syntax sections
 clasohm parents: 
1273diff
changeset | 36 | Ball, Bex :: ['a set, 'a => bool] => bool (*bounded quantifiers*) | 
| 10832 | 37 |   "image"       :: ['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 | (** Additional concrete syntax **) | 
| 43 | ||
| 923 | 44 | syntax | 
| 10131 | 45 |   range         :: ('a => 'b) => 'b set                 (*of function*)
 | 
| 923 | 46 | |
| 2261 | 47 | (* Infix syntax for non-membership *) | 
| 923 | 48 | |
| 3820 | 49 |   "op ~:"       :: ['a, 'a set] => bool               ("op ~:")
 | 
| 2261 | 50 |   "op ~:"       :: ['a, 'a set] => bool               ("(_/ ~: _)" [50, 51] 50)
 | 
| 923 | 51 | |
| 7238 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 wenzelm parents: 
5931diff
changeset | 52 | |
| 2261 | 53 |   "@Finset"     :: args => 'a set                     ("{(_)}")
 | 
| 54 |   "@Coll"       :: [pttrn, bool] => 'a set            ("(1{_./ _})")
 | |
| 55 |   "@SetCompr"   :: ['a, idts, bool] => 'a set         ("(1{_ |/_./ _})")
 | |
| 923 | 56 | |
| 57 | (* Big Intersection / Union *) | |
| 58 | ||
| 10106 | 59 |   "@INTER1"     :: [pttrns, 'b set] => 'b set         ("(3INT _./ _)" 10)
 | 
| 60 |   "@UNION1"     :: [pttrns, 'b set] => 'b set         ("(3UN _./ _)" 10)
 | |
| 1370 
7361ac9b024d
removed quotes from types in consts and syntax sections
 clasohm parents: 
1273diff
changeset | 61 |   "@INTER"      :: [pttrn, 'a set, 'b set] => 'b set  ("(3INT _:_./ _)" 10)
 | 
| 
7361ac9b024d
removed quotes from types in consts and syntax sections
 clasohm parents: 
1273diff
changeset | 62 |   "@UNION"      :: [pttrn, 'a set, 'b set] => 'b set  ("(3UN _:_./ _)" 10)
 | 
| 923 | 63 | |
| 64 | (* Bounded Quantifiers *) | |
| 7238 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 wenzelm parents: 
5931diff
changeset | 65 |   "_Ball"       :: [pttrn, 'a set, bool] => bool      ("(3ALL _:_./ _)" [0, 0, 10] 10)
 | 
| 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 wenzelm parents: 
5931diff
changeset | 66 |   "_Bex"        :: [pttrn, 'a set, bool] => bool      ("(3EX _:_./ _)" [0, 0, 10] 10)
 | 
| 923 | 67 | |
| 7238 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 wenzelm parents: 
5931diff
changeset | 68 | syntax (HOL) | 
| 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 wenzelm parents: 
5931diff
changeset | 69 |   "_Ball"       :: [pttrn, 'a set, bool] => bool      ("(3! _:_./ _)" [0, 0, 10] 10)
 | 
| 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 wenzelm parents: 
5931diff
changeset | 70 |   "_Bex"        :: [pttrn, 'a set, bool] => bool      ("(3? _:_./ _)" [0, 0, 10] 10)
 | 
| 923 | 71 | |
| 72 | translations | |
| 10832 | 73 | "range f" == "f`UNIV" | 
| 923 | 74 | "x ~: y" == "~ (x : y)" | 
| 75 |   "{x, xs}"     == "insert x {xs}"
 | |
| 76 |   "{x}"         == "insert x {}"
 | |
| 77 |   "{x. P}"      == "Collect (%x. P)"
 | |
| 4159 
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
 paulson parents: 
4151diff
changeset | 78 | "UN x y. B" == "UN x. UN y. B" | 
| 
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
 paulson parents: 
4151diff
changeset | 79 | "UN x. B" == "UNION UNIV (%x. B)" | 
| 7238 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 wenzelm parents: 
5931diff
changeset | 80 | "INT x y. B" == "INT x. INT y. B" | 
| 4159 
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
 paulson parents: 
4151diff
changeset | 81 | "INT x. B" == "INTER UNIV (%x. B)" | 
| 
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
 paulson parents: 
4151diff
changeset | 82 | "UN x:A. B" == "UNION A (%x. B)" | 
| 923 | 83 | "INT x:A. B" == "INTER A (%x. B)" | 
| 7238 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 wenzelm parents: 
5931diff
changeset | 84 | "ALL x:A. P" == "Ball A (%x. P)" | 
| 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 wenzelm parents: 
5931diff
changeset | 85 | "EX x:A. P" == "Bex A (%x. P)" | 
| 923 | 86 | |
| 2388 | 87 | syntax ("" output)
 | 
| 3820 | 88 |   "_setle"      :: ['a set, 'a set] => bool           ("op <=")
 | 
| 2388 | 89 |   "_setle"      :: ['a set, 'a set] => bool           ("(_/ <= _)" [50, 51] 50)
 | 
| 3820 | 90 |   "_setless"    :: ['a set, 'a set] => bool           ("op <")
 | 
| 2684 | 91 |   "_setless"    :: ['a set, 'a set] => bool           ("(_/ < _)" [50, 51] 50)
 | 
| 923 | 92 | |
| 2261 | 93 | syntax (symbols) | 
| 3820 | 94 |   "_setle"      :: ['a set, 'a set] => bool           ("op \\<subseteq>")
 | 
| 2388 | 95 |   "_setle"      :: ['a set, 'a set] => bool           ("(_/ \\<subseteq> _)" [50, 51] 50)
 | 
| 3820 | 96 |   "_setless"    :: ['a set, 'a set] => bool           ("op \\<subset>")
 | 
| 2684 | 97 |   "_setless"    :: ['a set, 'a set] => bool           ("(_/ \\<subset> _)" [50, 51] 50)
 | 
| 2261 | 98 | "op Int" :: ['a set, 'a set] => 'a set (infixl "\\<inter>" 70) | 
| 99 | "op Un" :: ['a set, 'a set] => 'a set (infixl "\\<union>" 65) | |
| 3820 | 100 |   "op :"        :: ['a, 'a set] => bool               ("op \\<in>")
 | 
| 2261 | 101 |   "op :"        :: ['a, 'a set] => bool               ("(_/ \\<in> _)" [50, 51] 50)
 | 
| 3820 | 102 |   "op ~:"       :: ['a, 'a set] => bool               ("op \\<notin>")
 | 
| 2261 | 103 |   "op ~:"       :: ['a, 'a set] => bool               ("(_/ \\<notin> _)" [50, 51] 50)
 | 
| 10106 | 104 |   "@UNION1"     :: [pttrns, 'b set] => 'b set         ("(3\\<Union>_./ _)" 10)
 | 
| 105 |   "@INTER1"     :: [pttrns, 'b set] => 'b set         ("(3\\<Inter>_./ _)" 10)
 | |
| 8148 
5ef0b624aadb
beautified spacing for binders with symbols syntax, analogous to HOL.thy
 oheimb parents: 
8005diff
changeset | 106 |   "@UNION"      :: [pttrn, 'a set, 'b set] => 'b set  ("(3\\<Union>_\\<in>_./ _)" 10)
 | 
| 
5ef0b624aadb
beautified spacing for binders with symbols syntax, analogous to HOL.thy
 oheimb parents: 
8005diff
changeset | 107 |   "@INTER"      :: [pttrn, 'a set, 'b set] => 'b set  ("(3\\<Inter>_\\<in>_./ _)" 10)
 | 
| 
5ef0b624aadb
beautified spacing for binders with symbols syntax, analogous to HOL.thy
 oheimb parents: 
8005diff
changeset | 108 |   Union         :: (('a set) set) => 'a set           ("\\<Union>_" [90] 90)
 | 
| 
5ef0b624aadb
beautified spacing for binders with symbols syntax, analogous to HOL.thy
 oheimb parents: 
8005diff
changeset | 109 |   Inter         :: (('a set) set) => 'a set           ("\\<Inter>_" [90] 90)
 | 
| 
5ef0b624aadb
beautified spacing for binders with symbols syntax, analogous to HOL.thy
 oheimb parents: 
8005diff
changeset | 110 |   "_Ball"       :: [pttrn, 'a set, bool] => bool      ("(3\\<forall>_\\<in>_./ _)" [0, 0, 10] 10)
 | 
| 
5ef0b624aadb
beautified spacing for binders with symbols syntax, analogous to HOL.thy
 oheimb parents: 
8005diff
changeset | 111 |   "_Bex"        :: [pttrn, 'a set, bool] => bool      ("(3\\<exists>_\\<in>_./ _)" [0, 0, 10] 10)
 | 
| 2261 | 112 | |
| 2412 | 113 | translations | 
| 2965 
afbda7e26f15
improved translations for subset symbols syntax: constraints;
 wenzelm parents: 
2912diff
changeset | 114 | "op \\<subseteq>" => "op <= :: [_ set, _ set] => bool" | 
| 
afbda7e26f15
improved translations for subset symbols syntax: constraints;
 wenzelm parents: 
2912diff
changeset | 115 | "op \\<subset>" => "op < :: [_ set, _ set] => bool" | 
| 2412 | 116 | |
| 2261 | 117 | |
| 118 | ||
| 119 | (** Rules and definitions **) | |
| 120 | ||
| 3947 | 121 | local | 
| 122 | ||
| 923 | 123 | rules | 
| 124 | ||
| 125 | (* Isomorphisms between Predicates and Sets *) | |
| 126 | ||
| 3842 | 127 |   mem_Collect_eq    "(a : {x. P(x)}) = P(a)"
 | 
| 128 |   Collect_mem_eq    "{x. x:A} = A"
 | |
| 923 | 129 | |
| 130 | ||
| 131 | defs | |
| 132 | Ball_def "Ball A P == ! x. x:A --> P(x)" | |
| 133 | Bex_def "Bex A P == ? x. x:A & P(x)" | |
| 134 | subset_def "A <= B == ! x:A. x:B" | |
| 3222 
726a9b069947
Distributed Psubset stuff to basic set theory files, incl Finite.
 nipkow parents: 
2965diff
changeset | 135 | psubset_def "A < B == (A::'a set) <= B & ~ A=B" | 
| 5492 | 136 |   Compl_def     "- A            == {x. ~x:A}"
 | 
| 3842 | 137 |   Un_def        "A Un B         == {x. x:A | x:B}"
 | 
| 138 |   Int_def       "A Int B        == {x. x:A & x:B}"
 | |
| 923 | 139 |   set_diff_def  "A - B          == {x. x:A & ~x:B}"
 | 
| 140 |   INTER_def     "INTER A B      == {y. ! x:A. y: B(x)}"
 | |
| 141 |   UNION_def     "UNION A B      == {y. ? x:A. y: B(x)}"
 | |
| 2393 | 142 | Inter_def "Inter S == (INT x:S. x)" | 
| 143 | Union_def "Union S == (UN x:S. x)" | |
| 144 |   Pow_def       "Pow A          == {B. B <= A}"
 | |
| 923 | 145 |   empty_def     "{}             == {x. False}"
 | 
| 4159 
4aff9b7e5597
UNIV now a constant; UNION1, INTER1 now translations and no longer have
 paulson parents: 
4151diff
changeset | 146 |   UNIV_def      "UNIV           == {x. True}"
 | 
| 3842 | 147 |   insert_def    "insert a B     == {x. x=a} Un B"
 | 
| 10832 | 148 |   image_def     "f`A           == {y. ? x:A. y=f(x)}"
 | 
| 1273 | 149 | |
| 7238 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 wenzelm parents: 
5931diff
changeset | 150 | |
| 923 | 151 | end | 
| 152 | ||
| 2261 | 153 | |
| 923 | 154 | ML | 
| 155 | ||
| 156 | local | |
| 157 | ||
| 2388 | 158 | (* Set inclusion *) | 
| 159 | ||
| 4151 | 160 | fun le_tr' _ (*op <=*) (Type ("fun", (Type ("set", _) :: _))) ts =
 | 
| 2388 | 161 | list_comb (Syntax.const "_setle", ts) | 
| 4151 | 162 | | le_tr' _ (*op <=*) _ _ = raise Match; | 
| 2388 | 163 | |
| 4151 | 164 | fun less_tr' _ (*op <*) (Type ("fun", (Type ("set", _) :: _))) ts =
 | 
| 2684 | 165 | list_comb (Syntax.const "_setless", ts) | 
| 4151 | 166 | | less_tr' _ (*op <*) _ _ = raise Match; | 
| 2684 | 167 | |
| 2388 | 168 | |
| 923 | 169 | (* Translates between { e | x1..xn. P} and {u. ? x1..xn. u=e & P}      *)
 | 
| 170 | (* {y. ? x1..xn. y = e & P} is only translated if [0..n] subset bvs(e) *)
 | |
| 171 | ||
| 7238 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 wenzelm parents: 
5931diff
changeset | 172 | val ex_tr = snd(mk_binder_tr("EX ","Ex"));
 | 
| 923 | 173 | |
| 174 | fun nvars(Const("_idts",_) $ _ $ idts) = nvars(idts)+1
 | |
| 175 | | nvars(_) = 1; | |
| 176 | ||
| 177 | fun setcompr_tr[e,idts,b] = | |
| 178 |   let val eq = Syntax.const("op =") $ Bound(nvars(idts)) $ e
 | |
| 179 |       val P = Syntax.const("op &") $ eq $ b
 | |
| 180 | val exP = ex_tr [idts,P] | |
| 181 |   in Syntax.const("Collect") $ Abs("",dummyT,exP) end;
 | |
| 182 | ||
| 183 | val ex_tr' = snd(mk_binder_tr' ("Ex","DUMMY"));
 | |
| 184 | ||
| 185 | fun setcompr_tr'[Abs(_,_,P)] = | |
| 186 |   let fun ok(Const("Ex",_)$Abs(_,_,P),n) = ok(P,n+1)
 | |
| 10985 | 187 |         | ok(Const("op &",_) $ (Const("op =",_) $ Bound(m) $ e) $ P, n) =
 | 
| 188 | if n>0 andalso m=n andalso not(loose_bvar1(P,n)) andalso | |
| 189 | ((0 upto (n-1)) subset add_loose_bnos(e,0,[])) | |
| 923 | 190 | then () else raise Match | 
| 191 | ||
| 192 | fun tr'(_ $ abs) = | |
| 193 | let val _ $ idts $ (_ $ (_ $ _ $ e) $ Q) = ex_tr'[abs] | |
| 194 |         in Syntax.const("@SetCompr") $ e $ idts $ Q end
 | |
| 195 | in ok(P,0); tr'(P) end; | |
| 196 | ||
| 197 | in | |
| 198 | ||
| 199 | val parse_translation = [("@SetCompr", setcompr_tr)];
 | |
| 200 | val print_translation = [("Collect", setcompr_tr')];
 | |
| 2684 | 201 | val typed_print_translation = [("op <=", le_tr'), ("op <", less_tr')];
 | 
| 7238 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 wenzelm parents: 
5931diff
changeset | 202 | |
| 923 | 203 | |
| 204 | end; |