src/HOL/Set.thy
author regensbu
Fri, 06 Oct 1995 16:17:08 +0100
changeset 1273 6960ec882bca
parent 1068 e0f2dffab506
child 1370 7361ac9b024d
permissions -rw-r--r--
added 8bit pragmas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     1
(*  Title:      HOL/Set.thy
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     3
    Author:     Tobias Nipkow
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     6
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     7
Set = Ord +
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     9
types
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    10
  'a set
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    11
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    12
arities
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    13
  set :: (term) term
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    14
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    15
instance
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    16
  set :: (term) {ord, minus}
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    17
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    18
consts
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    19
  "{}"          :: "'a set"                           ("{}")
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    20
  insert        :: "['a, 'a set] => 'a set"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    21
  Collect       :: "('a => bool) => 'a set"               (*comprehension*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    22
  Compl         :: "('a set) => 'a set"                   (*complement*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    23
  Int           :: "['a set, 'a set] => 'a set"       (infixl 70)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    24
  Un            :: "['a set, 'a set] => 'a set"       (infixl 65)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    25
  UNION, INTER  :: "['a set, 'a => 'b set] => 'b set"     (*general*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    26
  UNION1        :: "['a => 'b set] => 'b set"         (binder "UN " 10)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    27
  INTER1        :: "['a => 'b set] => 'b set"         (binder "INT " 10)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    28
  Union, Inter  :: "(('a set)set) => 'a set"              (*of a set*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    29
  Pow           :: "'a set => 'a set set"                 (*powerset*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    30
  range         :: "('a => 'b) => 'b set"                 (*of function*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    31
  Ball, Bex     :: "['a set, 'a => bool] => bool"         (*bounded quantifiers*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    32
  inj, surj     :: "('a => 'b) => bool"                   (*inj/surjective*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    33
  inj_onto      :: "['a => 'b, 'a set] => bool"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    34
  "``"          :: "['a => 'b, 'a set] => ('b set)"   (infixl 90)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    35
  ":"           :: "['a, 'a set] => bool"             (infixl 50) (*membership*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    36
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    37
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    38
syntax
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    39
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    40
  "~:"          :: "['a, 'a set] => bool"             (infixl 50)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    41
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    42
  "@Finset"     :: "args => 'a set"                   ("{(_)}")
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    43
1068
e0f2dffab506 HOL.thy:
nipkow
parents: 923
diff changeset
    44
  "@Coll"       :: "[pttrn, bool] => 'a set"          ("(1{_./ _})")
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    45
  "@SetCompr"   :: "['a, idts, bool] => 'a set"       ("(1{_ |/_./ _})")
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    46
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
  (* Big Intersection / Union *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    48
1068
e0f2dffab506 HOL.thy:
nipkow
parents: 923
diff changeset
    49
  "@INTER"      :: "[pttrn, 'a set, 'b set] => 'b set"  ("(3INT _:_./ _)" 10)
e0f2dffab506 HOL.thy:
nipkow
parents: 923
diff changeset
    50
  "@UNION"      :: "[pttrn, 'a set, 'b set] => 'b set"  ("(3UN _:_./ _)" 10)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    51
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    52
  (* Bounded Quantifiers *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    53
1068
e0f2dffab506 HOL.thy:
nipkow
parents: 923
diff changeset
    54
  "@Ball"       :: "[pttrn, 'a set, bool] => bool"      ("(3! _:_./ _)" 10)
e0f2dffab506 HOL.thy:
nipkow
parents: 923
diff changeset
    55
  "@Bex"        :: "[pttrn, 'a set, bool] => bool"      ("(3? _:_./ _)" 10)
e0f2dffab506 HOL.thy:
nipkow
parents: 923
diff changeset
    56
  "*Ball"       :: "[pttrn, 'a set, bool] => bool"      ("(3ALL _:_./ _)" 10)
e0f2dffab506 HOL.thy:
nipkow
parents: 923
diff changeset
    57
  "*Bex"        :: "[pttrn, 'a set, bool] => bool"      ("(3EX _:_./ _)" 10)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    58
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    59
translations
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    60
  "x ~: y"      == "~ (x : y)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    61
  "{x, xs}"     == "insert x {xs}"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    62
  "{x}"         == "insert x {}"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    63
  "{x. P}"      == "Collect (%x. P)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    64
  "INT x:A. B"  == "INTER A (%x. B)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    65
  "UN x:A. B"   == "UNION A (%x. B)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    66
  "! x:A. P"    == "Ball A (%x. P)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    67
  "? x:A. P"    == "Bex A (%x. P)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    68
  "ALL x:A. P"  => "Ball A (%x. P)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    69
  "EX x:A. P"   => "Bex A (%x. P)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    70
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    71
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    72
rules
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    73
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    74
  (* Isomorphisms between Predicates and Sets *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    75
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    76
  mem_Collect_eq    "(a : {x.P(x)}) = P(a)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    77
  Collect_mem_eq    "{x.x:A} = A"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    78
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    79
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    80
defs
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    81
  Ball_def      "Ball A P       == ! x. x:A --> P(x)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    82
  Bex_def       "Bex A P        == ? x. x:A & P(x)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    83
  subset_def    "A <= B         == ! x:A. x:B"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    84
  Compl_def     "Compl(A)       == {x. ~x:A}"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    85
  Un_def        "A Un B         == {x.x:A | x:B}"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    86
  Int_def       "A Int B        == {x.x:A & x:B}"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    87
  set_diff_def  "A - B          == {x. x:A & ~x:B}"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    88
  INTER_def     "INTER A B      == {y. ! x:A. y: B(x)}"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    89
  UNION_def     "UNION A B      == {y. ? x:A. y: B(x)}"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    90
  INTER1_def    "INTER1(B)      == INTER {x.True} B"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    91
  UNION1_def    "UNION1(B)      == UNION {x.True} B"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    92
  Inter_def     "Inter(S)       == (INT x:S. x)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    93
  Union_def     "Union(S)       == (UN x:S. x)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    94
  Pow_def       "Pow(A)         == {B. B <= A}"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    95
  empty_def     "{}             == {x. False}"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    96
  insert_def    "insert a B     == {x.x=a} Un B"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    97
  range_def     "range(f)       == {y. ? x. y=f(x)}"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    98
  image_def     "f``A           == {y. ? x:A. y=f(x)}"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    99
  inj_def       "inj(f)         == ! x y. f(x)=f(y) --> x=y"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   100
  inj_onto_def  "inj_onto f A   == ! x:A. ! y:A. f(x)=f(y) --> x=y"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   101
  surj_def      "surj(f)        == ! y. ? x. y=f(x)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   102
1273
6960ec882bca added 8bit pragmas
regensbu
parents: 1068
diff changeset
   103
(* start 8bit 1 *)
6960ec882bca added 8bit pragmas
regensbu
parents: 1068
diff changeset
   104
(* end 8bit 1 *)
6960ec882bca added 8bit pragmas
regensbu
parents: 1068
diff changeset
   105
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   106
end
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   107
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   108
ML
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   109
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   110
local
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   111
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   112
(* Translates between { e | x1..xn. P} and {u. ? x1..xn. u=e & P}      *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   113
(* {y. ? x1..xn. y = e & P} is only translated if [0..n] subset bvs(e) *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   114
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   115
val ex_tr = snd(mk_binder_tr("? ","Ex"));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   116
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   117
fun nvars(Const("_idts",_) $ _ $ idts) = nvars(idts)+1
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   118
  | nvars(_) = 1;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   119
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   120
fun setcompr_tr[e,idts,b] =
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   121
  let val eq = Syntax.const("op =") $ Bound(nvars(idts)) $ e
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   122
      val P = Syntax.const("op &") $ eq $ b
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   123
      val exP = ex_tr [idts,P]
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   124
  in Syntax.const("Collect") $ Abs("",dummyT,exP) end;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   125
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   126
val ex_tr' = snd(mk_binder_tr' ("Ex","DUMMY"));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   127
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   128
fun setcompr_tr'[Abs(_,_,P)] =
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   129
  let fun ok(Const("Ex",_)$Abs(_,_,P),n) = ok(P,n+1)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   130
        | ok(Const("op &",_) $ (Const("op =",_) $ Bound(m) $ e) $ _, n) =
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   131
            if n>0 andalso m=n andalso
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   132
              ((0 upto (n-1)) subset add_loose_bnos(e,0,[]))
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   133
            then () else raise Match
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   134
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   135
      fun tr'(_ $ abs) =
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   136
        let val _ $ idts $ (_ $ (_ $ _ $ e) $ Q) = ex_tr'[abs]
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   137
        in Syntax.const("@SetCompr") $ e $ idts $ Q end
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   138
  in ok(P,0); tr'(P) end;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   139
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   140
in
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   141
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   142
val parse_translation = [("@SetCompr", setcompr_tr)];
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   143
val print_translation = [("Collect", setcompr_tr')];
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   144
val print_ast_translation =
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   145
  map HOL.alt_ast_tr' [("@Ball", "*Ball"), ("@Bex", "*Bex")];
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   146
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   147
end;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   148