src/HOL/Set.thy
author wenzelm
Tue Feb 25 16:57:25 1997 +0100 (1997-02-25)
changeset 2684 9781d63ef063
parent 2412 025e80ed698d
child 2912 3fac3e8d5d3e
permissions -rw-r--r--
added proper subset symbols syntax;
     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 
    10 (** Core syntax **)
    11 
    12 types
    13   'a set
    14 
    15 arities
    16   set :: (term) term
    17 
    18 instance
    19   set :: (term) {ord, minus}
    20 
    21 consts
    22   "{}"          :: 'a set                           ("{}")
    23   insert        :: ['a, 'a set] => 'a set
    24   Collect       :: ('a => bool) => 'a set               (*comprehension*)
    25   Compl         :: ('a set) => 'a set                   (*complement*)
    26   Int           :: ['a set, 'a set] => 'a set       (infixl 70)
    27   Un            :: ['a set, 'a set] => 'a set       (infixl 65)
    28   UNION, INTER  :: ['a set, 'a => 'b set] => 'b set     (*general*)
    29   UNION1        :: ['a => 'b set] => 'b set         (binder "UN " 10)
    30   INTER1        :: ['a => 'b set] => 'b set         (binder "INT " 10)
    31   Union, Inter  :: (('a set) set) => 'a set             (*of a set*)
    32   Pow           :: 'a set => 'a set set                 (*powerset*)
    33   range         :: ('a => 'b) => 'b set                 (*of function*)
    34   Ball, Bex     :: ['a set, 'a => bool] => bool         (*bounded quantifiers*)
    35   inj, surj     :: ('a => 'b) => bool                   (*inj/surjective*)
    36   inj_onto      :: ['a => 'b, 'a set] => bool
    37   "``"          :: ['a => 'b, 'a set] => ('b set)   (infixr 90)
    38   (*membership*)
    39   "op :"        :: ['a, 'a set] => bool             ("(_/ : _)" [50, 51] 50)
    40 
    41 
    42 
    43 (** Additional concrete syntax **)
    44 
    45 syntax
    46 
    47   "op :"        :: ['a, 'a set] => bool               ("op :")
    48 
    49   UNIV          :: 'a set
    50 
    51   (* Infix syntax for non-membership *)
    52 
    53   "op ~:"       :: ['a, 'a set] => bool               ("(_/ ~: _)" [50, 51] 50)
    54   "op ~:"       :: ['a, 'a set] => bool               ("op ~:")
    55 
    56   "@Finset"     :: args => 'a set                     ("{(_)}")
    57 
    58   "@Coll"       :: [pttrn, bool] => 'a set            ("(1{_./ _})")
    59   "@SetCompr"   :: ['a, idts, bool] => 'a set         ("(1{_ |/_./ _})")
    60 
    61   (* Big Intersection / Union *)
    62 
    63   "@INTER"      :: [pttrn, 'a set, 'b set] => 'b set  ("(3INT _:_./ _)" 10)
    64   "@UNION"      :: [pttrn, 'a set, 'b set] => 'b set  ("(3UN _:_./ _)" 10)
    65 
    66   (* Bounded Quantifiers *)
    67 
    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)
    72 
    73 translations
    74   "UNIV"        == "Compl {}"
    75   "range f"     == "f``UNIV"
    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 syntax ("" output)
    88   "_setle"      :: ['a set, 'a set] => bool           ("(_/ <= _)" [50, 51] 50)
    89   "_setle"      :: ['a set, 'a set] => bool           ("op <=")
    90   "_setless"    :: ['a set, 'a set] => bool           ("(_/ < _)" [50, 51] 50)
    91   "_setless"    :: ['a set, 'a set] => bool           ("op <")
    92 
    93 syntax (symbols)
    94   "_setle"      :: ['a set, 'a set] => bool           ("(_/ \\<subseteq> _)" [50, 51] 50)
    95   "_setle"      :: ['a set, 'a set] => bool           ("op \\<subseteq>")
    96   "_setless"    :: ['a set, 'a set] => bool           ("(_/ \\<subset> _)" [50, 51] 50)
    97   "_setless"    :: ['a set, 'a set] => bool           ("op \\<subset>")
    98   "op Int"      :: ['a set, 'a set] => 'a set         (infixl "\\<inter>" 70)
    99   "op Un"       :: ['a set, 'a set] => 'a set         (infixl "\\<union>" 65)
   100   "op :"        :: ['a, 'a set] => bool               ("(_/ \\<in> _)" [50, 51] 50)
   101   "op :"        :: ['a, 'a set] => bool               ("op \\<in>")
   102   "op ~:"       :: ['a, 'a set] => bool               ("(_/ \\<notin> _)" [50, 51] 50)
   103   "op ~:"       :: ['a, 'a set] => bool               ("op \\<notin>")
   104   "UN "         :: [idts, bool] => bool               ("(3\\<Union> _./ _)" 10)
   105   "INT "        :: [idts, bool] => bool               ("(3\\<Inter> _./ _)" 10)
   106   "@UNION"      :: [pttrn, 'a set, 'b set] => 'b set  ("(3\\<Union> _\\<in>_./ _)" 10)
   107   "@INTER"      :: [pttrn, 'a set, 'b set] => 'b set  ("(3\\<Inter> _\\<in>_./ _)" 10)
   108   Union         :: (('a set) set) => 'a set           ("\\<Union> _" [90] 90)
   109   Inter         :: (('a set) set) => 'a set           ("\\<Inter> _" [90] 90)
   110   "@Ball"       :: [pttrn, 'a set, bool] => bool      ("(3\\<forall> _\\<in>_./ _)" [0, 0, 10] 10)
   111   "@Bex"        :: [pttrn, 'a set, bool] => bool      ("(3\\<exists> _\\<in>_./ _)" [0, 0, 10] 10)
   112 
   113 syntax (symbols output)
   114   "*Ball"       :: [pttrn, 'a set, bool] => bool      ("(3\\<forall> _\\<in>_./ _)" [0, 0, 10] 10)
   115   "*Bex"        :: [pttrn, 'a set, bool] => bool      ("(3\\<exists> _\\<in>_./ _)" [0, 0, 10] 10)
   116 
   117 translations
   118   "op \\<subseteq>" => "op <="
   119   "op \\<subset>" => "op <"
   120 
   121 
   122 
   123 (** Rules and definitions **)
   124 
   125 rules
   126 
   127   (* Isomorphisms between Predicates and Sets *)
   128 
   129   mem_Collect_eq    "(a : {x.P(x)}) = P(a)"
   130   Collect_mem_eq    "{x.x:A} = A"
   131 
   132 
   133 defs
   134 
   135   Ball_def      "Ball A P       == ! x. x:A --> P(x)"
   136   Bex_def       "Bex A P        == ? x. x:A & P(x)"
   137   subset_def    "A <= B         == ! x:A. x:B"
   138   Compl_def     "Compl A        == {x. ~x:A}"
   139   Un_def        "A Un B         == {x.x:A | x:B}"
   140   Int_def       "A Int B        == {x.x:A & x:B}"
   141   set_diff_def  "A - B          == {x. x:A & ~x:B}"
   142   INTER_def     "INTER A B      == {y. ! x:A. y: B(x)}"
   143   UNION_def     "UNION A B      == {y. ? x:A. y: B(x)}"
   144   INTER1_def    "INTER1 B       == INTER {x.True} B"
   145   UNION1_def    "UNION1 B       == UNION {x.True} B"
   146   Inter_def     "Inter S        == (INT x:S. x)"
   147   Union_def     "Union S        == (UN x:S. x)"
   148   Pow_def       "Pow A          == {B. B <= A}"
   149   empty_def     "{}             == {x. False}"
   150   insert_def    "insert a B     == {x.x=a} Un B"
   151   image_def     "f``A           == {y. ? x:A. y=f(x)}"
   152   inj_def       "inj f          == ! x y. f(x)=f(y) --> x=y"
   153   inj_onto_def  "inj_onto f A   == ! x:A. ! y:A. f(x)=f(y) --> x=y"
   154   surj_def      "surj f         == ! y. ? x. y=f(x)"
   155 
   156 end
   157 
   158 
   159 ML
   160 
   161 local
   162 
   163 (* Set inclusion *)
   164 
   165 fun le_tr' (*op <=*) (Type ("fun", (Type ("set", _) :: _))) ts =
   166       list_comb (Syntax.const "_setle", ts)
   167   | le_tr' (*op <=*) _ _ = raise Match;
   168 
   169 fun less_tr' (*op <*) (Type ("fun", (Type ("set", _) :: _))) ts =
   170       list_comb (Syntax.const "_setless", ts)
   171   | less_tr' (*op <*) _ _ = raise Match;
   172 
   173 
   174 (* Translates between { e | x1..xn. P} and {u. ? x1..xn. u=e & P}      *)
   175 (* {y. ? x1..xn. y = e & P} is only translated if [0..n] subset bvs(e) *)
   176 
   177 val ex_tr = snd(mk_binder_tr("? ","Ex"));
   178 
   179 fun nvars(Const("_idts",_) $ _ $ idts) = nvars(idts)+1
   180   | nvars(_) = 1;
   181 
   182 fun setcompr_tr[e,idts,b] =
   183   let val eq = Syntax.const("op =") $ Bound(nvars(idts)) $ e
   184       val P = Syntax.const("op &") $ eq $ b
   185       val exP = ex_tr [idts,P]
   186   in Syntax.const("Collect") $ Abs("",dummyT,exP) end;
   187 
   188 val ex_tr' = snd(mk_binder_tr' ("Ex","DUMMY"));
   189 
   190 fun setcompr_tr'[Abs(_,_,P)] =
   191   let fun ok(Const("Ex",_)$Abs(_,_,P),n) = ok(P,n+1)
   192         | ok(Const("op &",_) $ (Const("op =",_) $ Bound(m) $ e) $ _, n) =
   193             if n>0 andalso m=n andalso
   194               ((0 upto (n-1)) subset add_loose_bnos(e,0,[]))
   195             then () else raise Match
   196 
   197       fun tr'(_ $ abs) =
   198         let val _ $ idts $ (_ $ (_ $ _ $ e) $ Q) = ex_tr'[abs]
   199         in Syntax.const("@SetCompr") $ e $ idts $ Q end
   200   in ok(P,0); tr'(P) end;
   201 
   202 in
   203 
   204 val parse_translation = [("@SetCompr", setcompr_tr)];
   205 val print_translation = [("Collect", setcompr_tr')];
   206 val typed_print_translation = [("op <=", le_tr'), ("op <", less_tr')];
   207 val print_ast_translation =
   208   map HOL.alt_ast_tr' [("@Ball", "*Ball"), ("@Bex", "*Bex")];
   209 
   210 end;