src/HOL/Set.thy
author haftmann
Mon Jul 20 08:31:12 2009 +0200 (2009-07-20)
changeset 32077 3698947146b2
parent 32064 53ca12ff305d
child 32078 1c14f77201d4
permissions -rw-r--r--
closer relation of sets and complete lattices; corresponding consts, defs and syntax at similar places in theory text
clasohm@923
     1
(*  Title:      HOL/Set.thy
wenzelm@12257
     2
    Author:     Tobias Nipkow, Lawrence C Paulson and Markus Wenzel
clasohm@923
     3
*)
clasohm@923
     4
wenzelm@11979
     5
header {* Set theory for higher-order logic *}
wenzelm@11979
     6
nipkow@15131
     7
theory Set
haftmann@30304
     8
imports Lattices
nipkow@15131
     9
begin
wenzelm@11979
    10
wenzelm@11979
    11
text {* A set in HOL is simply a predicate. *}
clasohm@923
    12
haftmann@32077
    13
subsection {* Basic definitions and syntax *}
haftmann@30531
    14
wenzelm@3947
    15
global
wenzelm@3947
    16
berghofe@26800
    17
types 'a set = "'a => bool"
wenzelm@3820
    18
clasohm@923
    19
consts
haftmann@30531
    20
  Collect       :: "('a => bool) => 'a set"              -- "comprehension"
haftmann@30531
    21
  "op :"        :: "'a => 'a set => bool"                -- "membership"
haftmann@30304
    22
haftmann@30304
    23
local
wenzelm@19656
    24
wenzelm@21210
    25
notation
wenzelm@21404
    26
  "op :"  ("op :") and
wenzelm@19656
    27
  "op :"  ("(_/ : _)" [50, 51] 50)
wenzelm@11979
    28
haftmann@32077
    29
defs
haftmann@32077
    30
  mem_def [code]: "x : S == S x"
haftmann@32077
    31
  Collect_def [code]: "Collect P == P"
haftmann@32077
    32
wenzelm@19656
    33
abbreviation
wenzelm@21404
    34
  "not_mem x A == ~ (x : A)" -- "non-membership"
wenzelm@19656
    35
wenzelm@21210
    36
notation
wenzelm@21404
    37
  not_mem  ("op ~:") and
wenzelm@19656
    38
  not_mem  ("(_/ ~: _)" [50, 51] 50)
wenzelm@19656
    39
wenzelm@21210
    40
notation (xsymbols)
wenzelm@21404
    41
  "op :"  ("op \<in>") and
wenzelm@21404
    42
  "op :"  ("(_/ \<in> _)" [50, 51] 50) and
wenzelm@21404
    43
  not_mem  ("op \<notin>") and
haftmann@30304
    44
  not_mem  ("(_/ \<notin> _)" [50, 51] 50)
wenzelm@19656
    45
wenzelm@21210
    46
notation (HTML output)
wenzelm@21404
    47
  "op :"  ("op \<in>") and
wenzelm@21404
    48
  "op :"  ("(_/ \<in> _)" [50, 51] 50) and
wenzelm@21404
    49
  not_mem  ("op \<notin>") and
wenzelm@19656
    50
  not_mem  ("(_/ \<notin> _)" [50, 51] 50)
wenzelm@19656
    51
haftmann@30531
    52
syntax
haftmann@30531
    53
  "@Coll"       :: "pttrn => bool => 'a set"              ("(1{_./ _})")
haftmann@30531
    54
haftmann@30531
    55
translations
haftmann@30531
    56
  "{x. P}"      == "Collect (%x. P)"
haftmann@30531
    57
haftmann@30531
    58
definition Int :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "Int" 70) where
haftmann@30531
    59
  "A Int B \<equiv> {x. x \<in> A \<and> x \<in> B}"
haftmann@30531
    60
haftmann@30531
    61
definition Un :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "Un" 65) where
haftmann@30531
    62
  "A Un B \<equiv> {x. x \<in> A \<or> x \<in> B}"
haftmann@30531
    63
haftmann@30531
    64
notation (xsymbols)
haftmann@30531
    65
  "Int"  (infixl "\<inter>" 70) and
haftmann@30531
    66
  "Un"  (infixl "\<union>" 65)
haftmann@30531
    67
haftmann@30531
    68
notation (HTML output)
haftmann@30531
    69
  "Int"  (infixl "\<inter>" 70) and
haftmann@30531
    70
  "Un"  (infixl "\<union>" 65)
haftmann@30531
    71
haftmann@31456
    72
definition empty :: "'a set" ("{}") where
haftmann@31456
    73
  "empty \<equiv> {x. False}"
haftmann@31456
    74
haftmann@31456
    75
definition insert :: "'a \<Rightarrow> 'a set \<Rightarrow> 'a set" where
haftmann@31456
    76
  "insert a B \<equiv> {x. x = a} \<union> B"
haftmann@31456
    77
haftmann@31456
    78
definition UNIV :: "'a set" where
haftmann@31456
    79
  "UNIV \<equiv> {x. True}"
haftmann@31456
    80
haftmann@31456
    81
syntax
haftmann@31456
    82
  "@Finset"     :: "args => 'a set"                       ("{(_)}")
haftmann@31456
    83
haftmann@31456
    84
translations
haftmann@31456
    85
  "{x, xs}"     == "CONST insert x {xs}"
haftmann@31456
    86
  "{x}"         == "CONST insert x {}"
haftmann@31456
    87
haftmann@32077
    88
global
haftmann@32077
    89
haftmann@32077
    90
consts
haftmann@32077
    91
  Ball          :: "'a set => ('a => bool) => bool"      -- "bounded universal quantifiers"
haftmann@32077
    92
  Bex           :: "'a set => ('a => bool) => bool"      -- "bounded existential quantifiers"
haftmann@32077
    93
  Bex1          :: "'a set => ('a => bool) => bool"      -- "bounded unique existential quantifiers"
haftmann@32077
    94
haftmann@32077
    95
local
haftmann@32077
    96
haftmann@32077
    97
defs
haftmann@32077
    98
  Ball_def:     "Ball A P       == ALL x. x:A --> P(x)"
haftmann@32077
    99
  Bex_def:      "Bex A P        == EX x. x:A & P(x)"
haftmann@32077
   100
  Bex1_def:     "Bex1 A P       == EX! x. x:A & P(x)"
haftmann@32077
   101
haftmann@30531
   102
syntax
haftmann@30531
   103
  "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3ALL _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   104
  "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3EX _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   105
  "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3EX! _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   106
  "_Bleast"     :: "id => 'a set => bool => 'a"           ("(3LEAST _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   107
haftmann@30531
   108
syntax (HOL)
haftmann@30531
   109
  "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3! _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   110
  "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3? _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   111
  "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3?! _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   112
haftmann@30531
   113
syntax (xsymbols)
haftmann@30531
   114
  "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3\<forall>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   115
  "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3\<exists>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   116
  "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3\<exists>!_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   117
  "_Bleast"     :: "id => 'a set => bool => 'a"           ("(3LEAST_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   118
haftmann@30531
   119
syntax (HTML output)
haftmann@30531
   120
  "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3\<forall>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   121
  "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3\<exists>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   122
  "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3\<exists>!_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   123
haftmann@30531
   124
translations
haftmann@30531
   125
  "ALL x:A. P"  == "Ball A (%x. P)"
haftmann@30531
   126
  "EX x:A. P"   == "Bex A (%x. P)"
haftmann@30531
   127
  "EX! x:A. P"  == "Bex1 A (%x. P)"
haftmann@30531
   128
  "LEAST x:A. P" => "LEAST x. x:A & P"
haftmann@30531
   129
haftmann@30531
   130
haftmann@30531
   131
subsection {* Additional concrete syntax *}
haftmann@30531
   132
haftmann@30531
   133
syntax
haftmann@30531
   134
  "@SetCompr"   :: "'a => idts => bool => 'a set"         ("(1{_ |/_./ _})")
haftmann@30531
   135
  "@Collect"    :: "idt => 'a set => bool => 'a set"      ("(1{_ :/ _./ _})")
haftmann@30531
   136
haftmann@30531
   137
syntax (xsymbols)
haftmann@30531
   138
  "@Collect"    :: "idt => 'a set => bool => 'a set"      ("(1{_ \<in>/ _./ _})")
haftmann@30531
   139
haftmann@30531
   140
translations
haftmann@30531
   141
  "{x:A. P}"    => "{x. x:A & P}"
wenzelm@2261
   142
haftmann@21333
   143
abbreviation
wenzelm@21404
   144
  subset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
haftmann@21819
   145
  "subset \<equiv> less"
wenzelm@21404
   146
wenzelm@21404
   147
abbreviation
wenzelm@21404
   148
  subset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
haftmann@21819
   149
  "subset_eq \<equiv> less_eq"
haftmann@21333
   150
haftmann@21333
   151
notation (output)
wenzelm@21404
   152
  subset  ("op <") and
wenzelm@21404
   153
  subset  ("(_/ < _)" [50, 51] 50) and
wenzelm@21404
   154
  subset_eq  ("op <=") and
haftmann@21333
   155
  subset_eq  ("(_/ <= _)" [50, 51] 50)
haftmann@21333
   156
haftmann@21333
   157
notation (xsymbols)
wenzelm@21404
   158
  subset  ("op \<subset>") and
wenzelm@21404
   159
  subset  ("(_/ \<subset> _)" [50, 51] 50) and
wenzelm@21404
   160
  subset_eq  ("op \<subseteq>") and
haftmann@21333
   161
  subset_eq  ("(_/ \<subseteq> _)" [50, 51] 50)
haftmann@21333
   162
haftmann@21333
   163
notation (HTML output)
wenzelm@21404
   164
  subset  ("op \<subset>") and
wenzelm@21404
   165
  subset  ("(_/ \<subset> _)" [50, 51] 50) and
wenzelm@21404
   166
  subset_eq  ("op \<subseteq>") and
haftmann@21333
   167
  subset_eq  ("(_/ \<subseteq> _)" [50, 51] 50)
haftmann@21333
   168
haftmann@21333
   169
abbreviation (input)
haftmann@21819
   170
  supset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
haftmann@21819
   171
  "supset \<equiv> greater"
wenzelm@21404
   172
wenzelm@21404
   173
abbreviation (input)
haftmann@21819
   174
  supset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
haftmann@21819
   175
  "supset_eq \<equiv> greater_eq"
haftmann@21819
   176
haftmann@21819
   177
notation (xsymbols)
haftmann@21819
   178
  supset  ("op \<supset>") and
haftmann@21819
   179
  supset  ("(_/ \<supset> _)" [50, 51] 50) and
haftmann@21819
   180
  supset_eq  ("op \<supseteq>") and
haftmann@21819
   181
  supset_eq  ("(_/ \<supseteq> _)" [50, 51] 50)
haftmann@21333
   182
haftmann@30531
   183
haftmann@30531
   184
haftmann@30531
   185
subsubsection "Bounded quantifiers"
nipkow@14804
   186
wenzelm@19656
   187
syntax (output)
nipkow@14804
   188
  "_setlessAll" :: "[idt, 'a, bool] => bool"  ("(3ALL _<_./ _)"  [0, 0, 10] 10)
nipkow@14804
   189
  "_setlessEx"  :: "[idt, 'a, bool] => bool"  ("(3EX _<_./ _)"  [0, 0, 10] 10)
nipkow@14804
   190
  "_setleAll"   :: "[idt, 'a, bool] => bool"  ("(3ALL _<=_./ _)" [0, 0, 10] 10)
nipkow@14804
   191
  "_setleEx"    :: "[idt, 'a, bool] => bool"  ("(3EX _<=_./ _)" [0, 0, 10] 10)
webertj@20217
   192
  "_setleEx1"   :: "[idt, 'a, bool] => bool"  ("(3EX! _<=_./ _)" [0, 0, 10] 10)
nipkow@14804
   193
nipkow@14804
   194
syntax (xsymbols)
nipkow@14804
   195
  "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subset>_./ _)"  [0, 0, 10] 10)
nipkow@14804
   196
  "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subset>_./ _)"  [0, 0, 10] 10)
nipkow@14804
   197
  "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subseteq>_./ _)" [0, 0, 10] 10)
nipkow@14804
   198
  "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subseteq>_./ _)" [0, 0, 10] 10)
webertj@20217
   199
  "_setleEx1"   :: "[idt, 'a, bool] => bool"   ("(3\<exists>!_\<subseteq>_./ _)" [0, 0, 10] 10)
nipkow@14804
   200
wenzelm@19656
   201
syntax (HOL output)
nipkow@14804
   202
  "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
nipkow@14804
   203
  "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
nipkow@14804
   204
  "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
nipkow@14804
   205
  "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
webertj@20217
   206
  "_setleEx1"   :: "[idt, 'a, bool] => bool"   ("(3?! _<=_./ _)" [0, 0, 10] 10)
nipkow@14804
   207
nipkow@14804
   208
syntax (HTML output)
nipkow@14804
   209
  "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subset>_./ _)"  [0, 0, 10] 10)
nipkow@14804
   210
  "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subset>_./ _)"  [0, 0, 10] 10)
nipkow@14804
   211
  "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subseteq>_./ _)" [0, 0, 10] 10)
nipkow@14804
   212
  "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subseteq>_./ _)" [0, 0, 10] 10)
webertj@20217
   213
  "_setleEx1"   :: "[idt, 'a, bool] => bool"   ("(3\<exists>!_\<subseteq>_./ _)" [0, 0, 10] 10)
nipkow@14804
   214
nipkow@14804
   215
translations
haftmann@30531
   216
 "\<forall>A\<subset>B. P"   =>  "ALL A. A \<subset> B --> P"
haftmann@30531
   217
 "\<exists>A\<subset>B. P"   =>  "EX A. A \<subset> B & P"
haftmann@30531
   218
 "\<forall>A\<subseteq>B. P"   =>  "ALL A. A \<subseteq> B --> P"
haftmann@30531
   219
 "\<exists>A\<subseteq>B. P"   =>  "EX A. A \<subseteq> B & P"
haftmann@30531
   220
 "\<exists>!A\<subseteq>B. P"  =>  "EX! A. A \<subseteq> B & P"
nipkow@14804
   221
nipkow@14804
   222
print_translation {*
nipkow@14804
   223
let
wenzelm@22377
   224
  val Type (set_type, _) = @{typ "'a set"};
wenzelm@22377
   225
  val All_binder = Syntax.binder_name @{const_syntax "All"};
wenzelm@22377
   226
  val Ex_binder = Syntax.binder_name @{const_syntax "Ex"};
wenzelm@22377
   227
  val impl = @{const_syntax "op -->"};
wenzelm@22377
   228
  val conj = @{const_syntax "op &"};
wenzelm@22377
   229
  val sbset = @{const_syntax "subset"};
wenzelm@22377
   230
  val sbset_eq = @{const_syntax "subset_eq"};
haftmann@21819
   231
haftmann@21819
   232
  val trans =
haftmann@21819
   233
   [((All_binder, impl, sbset), "_setlessAll"),
haftmann@21819
   234
    ((All_binder, impl, sbset_eq), "_setleAll"),
haftmann@21819
   235
    ((Ex_binder, conj, sbset), "_setlessEx"),
haftmann@21819
   236
    ((Ex_binder, conj, sbset_eq), "_setleEx")];
haftmann@21819
   237
haftmann@21819
   238
  fun mk v v' c n P =
haftmann@21819
   239
    if v = v' andalso not (Term.exists_subterm (fn Free (x, _) => x = v | _ => false) n)
haftmann@21819
   240
    then Syntax.const c $ Syntax.mark_bound v' $ n $ P else raise Match;
haftmann@21819
   241
haftmann@21819
   242
  fun tr' q = (q,
haftmann@21819
   243
    fn [Const ("_bound", _) $ Free (v, Type (T, _)), Const (c, _) $ (Const (d, _) $ (Const ("_bound", _) $ Free (v', _)) $ n) $ P] =>
haftmann@21819
   244
         if T = (set_type) then case AList.lookup (op =) trans (q, c, d)
haftmann@21819
   245
          of NONE => raise Match
haftmann@21819
   246
           | SOME l => mk v v' l n P
haftmann@21819
   247
         else raise Match
haftmann@21819
   248
     | _ => raise Match);
nipkow@14804
   249
in
haftmann@21819
   250
  [tr' All_binder, tr' Ex_binder]
nipkow@14804
   251
end
nipkow@14804
   252
*}
nipkow@14804
   253
haftmann@30531
   254
wenzelm@11979
   255
text {*
wenzelm@11979
   256
  \medskip Translate between @{text "{e | x1...xn. P}"} and @{text
wenzelm@11979
   257
  "{u. EX x1..xn. u = e & P}"}; @{text "{y. EX x1..xn. y = e & P}"} is
wenzelm@11979
   258
  only translated if @{text "[0..n] subset bvs(e)"}.
wenzelm@11979
   259
*}
wenzelm@11979
   260
wenzelm@11979
   261
parse_translation {*
wenzelm@11979
   262
  let
wenzelm@11979
   263
    val ex_tr = snd (mk_binder_tr ("EX ", "Ex"));
wenzelm@3947
   264
wenzelm@11979
   265
    fun nvars (Const ("_idts", _) $ _ $ idts) = nvars idts + 1
wenzelm@11979
   266
      | nvars _ = 1;
wenzelm@11979
   267
wenzelm@11979
   268
    fun setcompr_tr [e, idts, b] =
wenzelm@11979
   269
      let
wenzelm@11979
   270
        val eq = Syntax.const "op =" $ Bound (nvars idts) $ e;
wenzelm@11979
   271
        val P = Syntax.const "op &" $ eq $ b;
wenzelm@11979
   272
        val exP = ex_tr [idts, P];
wenzelm@17784
   273
      in Syntax.const "Collect" $ Term.absdummy (dummyT, exP) end;
wenzelm@11979
   274
wenzelm@11979
   275
  in [("@SetCompr", setcompr_tr)] end;
wenzelm@11979
   276
*}
clasohm@923
   277
haftmann@30531
   278
(* To avoid eta-contraction of body: *)
haftmann@30531
   279
print_translation {*
haftmann@30531
   280
let
haftmann@30531
   281
  fun btr' syn [A, Abs abs] =
haftmann@30531
   282
    let val (x, t) = atomic_abs_tr' abs
haftmann@30531
   283
    in Syntax.const syn $ x $ A $ t end
haftmann@32077
   284
in [(@{const_syntax Ball}, btr' "_Ball"), (@{const_syntax Bex}, btr' "_Bex")] end
haftmann@30531
   285
*}
haftmann@30531
   286
nipkow@13763
   287
print_translation {*
nipkow@13763
   288
let
nipkow@13763
   289
  val ex_tr' = snd (mk_binder_tr' ("Ex", "DUMMY"));
nipkow@13763
   290
nipkow@13763
   291
  fun setcompr_tr' [Abs (abs as (_, _, P))] =
nipkow@13763
   292
    let
nipkow@13763
   293
      fun check (Const ("Ex", _) $ Abs (_, _, P), n) = check (P, n + 1)
nipkow@13763
   294
        | check (Const ("op &", _) $ (Const ("op =", _) $ Bound m $ e) $ P, n) =
nipkow@13763
   295
            n > 0 andalso m = n andalso not (loose_bvar1 (P, n)) andalso
nipkow@13763
   296
            ((0 upto (n - 1)) subset add_loose_bnos (e, 0, []))
nipkow@13764
   297
        | check _ = false
clasohm@923
   298
wenzelm@11979
   299
        fun tr' (_ $ abs) =
wenzelm@11979
   300
          let val _ $ idts $ (_ $ (_ $ _ $ e) $ Q) = ex_tr' [abs]
wenzelm@11979
   301
          in Syntax.const "@SetCompr" $ e $ idts $ Q end;
nipkow@13763
   302
    in if check (P, 0) then tr' P
nipkow@15535
   303
       else let val (x as _ $ Free(xN,_), t) = atomic_abs_tr' abs
nipkow@15535
   304
                val M = Syntax.const "@Coll" $ x $ t
nipkow@15535
   305
            in case t of
nipkow@15535
   306
                 Const("op &",_)
nipkow@15535
   307
                   $ (Const("op :",_) $ (Const("_bound",_) $ Free(yN,_)) $ A)
nipkow@15535
   308
                   $ P =>
nipkow@15535
   309
                   if xN=yN then Syntax.const "@Collect" $ x $ A $ P else M
nipkow@15535
   310
               | _ => M
nipkow@15535
   311
            end
nipkow@13763
   312
    end;
wenzelm@11979
   313
  in [("Collect", setcompr_tr')] end;
wenzelm@11979
   314
*}
wenzelm@11979
   315
haftmann@30531
   316
haftmann@30531
   317
subsection {* Lemmas and proof tool setup *}
haftmann@30531
   318
haftmann@30531
   319
subsubsection {* Relating predicates and sets *}
haftmann@30531
   320
haftmann@30531
   321
lemma mem_Collect_eq [iff]: "(a : {x. P(x)}) = P(a)"
haftmann@30531
   322
  by (simp add: Collect_def mem_def)
haftmann@30531
   323
haftmann@30531
   324
lemma Collect_mem_eq [simp]: "{x. x:A} = A"
haftmann@30531
   325
  by (simp add: Collect_def mem_def)
haftmann@30531
   326
haftmann@30531
   327
lemma CollectI: "P(a) ==> a : {x. P(x)}"
haftmann@30531
   328
  by simp
haftmann@30531
   329
haftmann@30531
   330
lemma CollectD: "a : {x. P(x)} ==> P(a)"
haftmann@30531
   331
  by simp
haftmann@30531
   332
haftmann@30531
   333
lemma Collect_cong: "(!!x. P x = Q x) ==> {x. P(x)} = {x. Q(x)}"
haftmann@30531
   334
  by simp
haftmann@30531
   335
haftmann@30531
   336
lemmas CollectE = CollectD [elim_format]
haftmann@30531
   337
haftmann@30531
   338
haftmann@30531
   339
subsubsection {* Bounded quantifiers *}
haftmann@30531
   340
wenzelm@11979
   341
lemma ballI [intro!]: "(!!x. x:A ==> P x) ==> ALL x:A. P x"
wenzelm@11979
   342
  by (simp add: Ball_def)
wenzelm@11979
   343
wenzelm@11979
   344
lemmas strip = impI allI ballI
wenzelm@11979
   345
wenzelm@11979
   346
lemma bspec [dest?]: "ALL x:A. P x ==> x:A ==> P x"
wenzelm@11979
   347
  by (simp add: Ball_def)
wenzelm@11979
   348
wenzelm@11979
   349
lemma ballE [elim]: "ALL x:A. P x ==> (P x ==> Q) ==> (x ~: A ==> Q) ==> Q"
wenzelm@11979
   350
  by (unfold Ball_def) blast
wenzelm@22139
   351
wenzelm@31945
   352
ML {* bind_thm ("rev_ballE", Thm.permute_prems 1 1 @{thm ballE}) *}
wenzelm@11979
   353
wenzelm@11979
   354
text {*
wenzelm@11979
   355
  \medskip This tactic takes assumptions @{prop "ALL x:A. P x"} and
wenzelm@11979
   356
  @{prop "a:A"}; creates assumption @{prop "P a"}.
wenzelm@11979
   357
*}
wenzelm@11979
   358
wenzelm@11979
   359
ML {*
wenzelm@22139
   360
  fun ball_tac i = etac @{thm ballE} i THEN contr_tac (i + 1)
wenzelm@11979
   361
*}
wenzelm@11979
   362
wenzelm@11979
   363
text {*
wenzelm@11979
   364
  Gives better instantiation for bound:
wenzelm@11979
   365
*}
wenzelm@11979
   366
wenzelm@26339
   367
declaration {* fn _ =>
wenzelm@26339
   368
  Classical.map_cs (fn cs => cs addbefore ("bspec", datac @{thm bspec} 1))
wenzelm@11979
   369
*}
wenzelm@11979
   370
wenzelm@11979
   371
lemma bexI [intro]: "P x ==> x:A ==> EX x:A. P x"
wenzelm@11979
   372
  -- {* Normally the best argument order: @{prop "P x"} constrains the
wenzelm@11979
   373
    choice of @{prop "x:A"}. *}
wenzelm@11979
   374
  by (unfold Bex_def) blast
wenzelm@11979
   375
wenzelm@13113
   376
lemma rev_bexI [intro?]: "x:A ==> P x ==> EX x:A. P x"
wenzelm@11979
   377
  -- {* The best argument order when there is only one @{prop "x:A"}. *}
wenzelm@11979
   378
  by (unfold Bex_def) blast
wenzelm@11979
   379
wenzelm@11979
   380
lemma bexCI: "(ALL x:A. ~P x ==> P a) ==> a:A ==> EX x:A. P x"
wenzelm@11979
   381
  by (unfold Bex_def) blast
wenzelm@11979
   382
wenzelm@11979
   383
lemma bexE [elim!]: "EX x:A. P x ==> (!!x. x:A ==> P x ==> Q) ==> Q"
wenzelm@11979
   384
  by (unfold Bex_def) blast
wenzelm@11979
   385
wenzelm@11979
   386
lemma ball_triv [simp]: "(ALL x:A. P) = ((EX x. x:A) --> P)"
wenzelm@11979
   387
  -- {* Trival rewrite rule. *}
wenzelm@11979
   388
  by (simp add: Ball_def)
wenzelm@11979
   389
wenzelm@11979
   390
lemma bex_triv [simp]: "(EX x:A. P) = ((EX x. x:A) & P)"
wenzelm@11979
   391
  -- {* Dual form for existentials. *}
wenzelm@11979
   392
  by (simp add: Bex_def)
wenzelm@11979
   393
wenzelm@11979
   394
lemma bex_triv_one_point1 [simp]: "(EX x:A. x = a) = (a:A)"
wenzelm@11979
   395
  by blast
wenzelm@11979
   396
wenzelm@11979
   397
lemma bex_triv_one_point2 [simp]: "(EX x:A. a = x) = (a:A)"
wenzelm@11979
   398
  by blast
wenzelm@11979
   399
wenzelm@11979
   400
lemma bex_one_point1 [simp]: "(EX x:A. x = a & P x) = (a:A & P a)"
wenzelm@11979
   401
  by blast
wenzelm@11979
   402
wenzelm@11979
   403
lemma bex_one_point2 [simp]: "(EX x:A. a = x & P x) = (a:A & P a)"
wenzelm@11979
   404
  by blast
wenzelm@11979
   405
wenzelm@11979
   406
lemma ball_one_point1 [simp]: "(ALL x:A. x = a --> P x) = (a:A --> P a)"
wenzelm@11979
   407
  by blast
wenzelm@11979
   408
wenzelm@11979
   409
lemma ball_one_point2 [simp]: "(ALL x:A. a = x --> P x) = (a:A --> P a)"
wenzelm@11979
   410
  by blast
wenzelm@11979
   411
wenzelm@26480
   412
ML {*
wenzelm@13462
   413
  local
wenzelm@22139
   414
    val unfold_bex_tac = unfold_tac @{thms "Bex_def"};
wenzelm@18328
   415
    fun prove_bex_tac ss = unfold_bex_tac ss THEN Quantifier1.prove_one_point_ex_tac;
wenzelm@11979
   416
    val rearrange_bex = Quantifier1.rearrange_bex prove_bex_tac;
wenzelm@11979
   417
wenzelm@22139
   418
    val unfold_ball_tac = unfold_tac @{thms "Ball_def"};
wenzelm@18328
   419
    fun prove_ball_tac ss = unfold_ball_tac ss THEN Quantifier1.prove_one_point_all_tac;
wenzelm@11979
   420
    val rearrange_ball = Quantifier1.rearrange_ball prove_ball_tac;
wenzelm@11979
   421
  in
wenzelm@18328
   422
    val defBEX_regroup = Simplifier.simproc (the_context ())
wenzelm@13462
   423
      "defined BEX" ["EX x:A. P x & Q x"] rearrange_bex;
wenzelm@18328
   424
    val defBALL_regroup = Simplifier.simproc (the_context ())
wenzelm@13462
   425
      "defined BALL" ["ALL x:A. P x --> Q x"] rearrange_ball;
wenzelm@11979
   426
  end;
wenzelm@13462
   427
wenzelm@13462
   428
  Addsimprocs [defBALL_regroup, defBEX_regroup];
wenzelm@11979
   429
*}
wenzelm@11979
   430
haftmann@30531
   431
haftmann@30531
   432
subsubsection {* Congruence rules *}
wenzelm@11979
   433
berghofe@16636
   434
lemma ball_cong:
wenzelm@11979
   435
  "A = B ==> (!!x. x:B ==> P x = Q x) ==>
wenzelm@11979
   436
    (ALL x:A. P x) = (ALL x:B. Q x)"
wenzelm@11979
   437
  by (simp add: Ball_def)
wenzelm@11979
   438
berghofe@16636
   439
lemma strong_ball_cong [cong]:
berghofe@16636
   440
  "A = B ==> (!!x. x:B =simp=> P x = Q x) ==>
berghofe@16636
   441
    (ALL x:A. P x) = (ALL x:B. Q x)"
berghofe@16636
   442
  by (simp add: simp_implies_def Ball_def)
berghofe@16636
   443
berghofe@16636
   444
lemma bex_cong:
wenzelm@11979
   445
  "A = B ==> (!!x. x:B ==> P x = Q x) ==>
wenzelm@11979
   446
    (EX x:A. P x) = (EX x:B. Q x)"
wenzelm@11979
   447
  by (simp add: Bex_def cong: conj_cong)
regensbu@1273
   448
berghofe@16636
   449
lemma strong_bex_cong [cong]:
berghofe@16636
   450
  "A = B ==> (!!x. x:B =simp=> P x = Q x) ==>
berghofe@16636
   451
    (EX x:A. P x) = (EX x:B. Q x)"
berghofe@16636
   452
  by (simp add: simp_implies_def Bex_def cong: conj_cong)
berghofe@16636
   453
haftmann@30531
   454
haftmann@30531
   455
subsubsection {* Subsets *}
haftmann@30531
   456
haftmann@30531
   457
lemma subsetI [atp,intro!]: "(!!x. x:A ==> x:B) ==> A \<subseteq> B"
haftmann@30531
   458
  by (auto simp add: mem_def intro: predicate1I)
haftmann@30352
   459
wenzelm@11979
   460
text {*
haftmann@30531
   461
  \medskip Map the type @{text "'a set => anything"} to just @{typ
haftmann@30531
   462
  'a}; for overloading constants whose first argument has type @{typ
haftmann@30531
   463
  "'a set"}.
wenzelm@11979
   464
*}
wenzelm@11979
   465
haftmann@30596
   466
lemma subsetD [elim, intro?]: "A \<subseteq> B ==> c \<in> A ==> c \<in> B"
haftmann@30531
   467
  -- {* Rule in Modus Ponens style. *}
haftmann@30531
   468
  by (unfold mem_def) blast
haftmann@30531
   469
haftmann@30596
   470
lemma rev_subsetD [intro?]: "c \<in> A ==> A \<subseteq> B ==> c \<in> B"
haftmann@30531
   471
  -- {* The same, with reversed premises for use with @{text erule} --
haftmann@30531
   472
      cf @{text rev_mp}. *}
haftmann@30531
   473
  by (rule subsetD)
haftmann@30531
   474
wenzelm@11979
   475
text {*
haftmann@30531
   476
  \medskip Converts @{prop "A \<subseteq> B"} to @{prop "x \<in> A ==> x \<in> B"}.
haftmann@30531
   477
*}
haftmann@30531
   478
haftmann@30531
   479
ML {*
haftmann@30531
   480
  fun impOfSubs th = th RSN (2, @{thm rev_subsetD})
wenzelm@11979
   481
*}
wenzelm@11979
   482
haftmann@30531
   483
lemma subsetCE [elim]: "A \<subseteq>  B ==> (c \<notin> A ==> P) ==> (c \<in> B ==> P) ==> P"
haftmann@30531
   484
  -- {* Classical elimination rule. *}
haftmann@30531
   485
  by (unfold mem_def) blast
haftmann@30531
   486
haftmann@30531
   487
lemma subset_eq: "A \<le> B = (\<forall>x\<in>A. x \<in> B)" by blast
wenzelm@2388
   488
wenzelm@11979
   489
text {*
haftmann@30531
   490
  \medskip Takes assumptions @{prop "A \<subseteq> B"}; @{prop "c \<in> A"} and
haftmann@30531
   491
  creates the assumption @{prop "c \<in> B"}.
haftmann@30352
   492
*}
haftmann@30352
   493
haftmann@30352
   494
ML {*
haftmann@30531
   495
  fun set_mp_tac i = etac @{thm subsetCE} i THEN mp_tac i
wenzelm@11979
   496
*}
wenzelm@11979
   497
haftmann@30531
   498
lemma contra_subsetD: "A \<subseteq> B ==> c \<notin> B ==> c \<notin> A"
haftmann@30531
   499
  by blast
haftmann@30531
   500
haftmann@30531
   501
lemma subset_refl [simp,atp]: "A \<subseteq> A"
haftmann@30531
   502
  by fast
haftmann@30531
   503
haftmann@30531
   504
lemma subset_trans: "A \<subseteq> B ==> B \<subseteq> C ==> A \<subseteq> C"
haftmann@30531
   505
  by blast
haftmann@30531
   506
haftmann@30531
   507
haftmann@30531
   508
subsubsection {* Equality *}
haftmann@30531
   509
haftmann@30531
   510
lemma set_ext: assumes prem: "(!!x. (x:A) = (x:B))" shows "A = B"
haftmann@30531
   511
  apply (rule prem [THEN ext, THEN arg_cong, THEN box_equals])
haftmann@30531
   512
   apply (rule Collect_mem_eq)
haftmann@30531
   513
  apply (rule Collect_mem_eq)
haftmann@30531
   514
  done
haftmann@30531
   515
haftmann@30531
   516
(* Due to Brian Huffman *)
haftmann@30531
   517
lemma expand_set_eq: "(A = B) = (ALL x. (x:A) = (x:B))"
haftmann@30531
   518
by(auto intro:set_ext)
haftmann@30531
   519
haftmann@30531
   520
lemma subset_antisym [intro!]: "A \<subseteq> B ==> B \<subseteq> A ==> A = B"
haftmann@30531
   521
  -- {* Anti-symmetry of the subset relation. *}
haftmann@30531
   522
  by (iprover intro: set_ext subsetD)
haftmann@30531
   523
haftmann@30531
   524
text {*
haftmann@30531
   525
  \medskip Equality rules from ZF set theory -- are they appropriate
haftmann@30531
   526
  here?
haftmann@30531
   527
*}
haftmann@30531
   528
haftmann@30531
   529
lemma equalityD1: "A = B ==> A \<subseteq> B"
haftmann@30531
   530
  by (simp add: subset_refl)
haftmann@30531
   531
haftmann@30531
   532
lemma equalityD2: "A = B ==> B \<subseteq> A"
haftmann@30531
   533
  by (simp add: subset_refl)
haftmann@30531
   534
haftmann@30531
   535
text {*
haftmann@30531
   536
  \medskip Be careful when adding this to the claset as @{text
haftmann@30531
   537
  subset_empty} is in the simpset: @{prop "A = {}"} goes to @{prop "{}
haftmann@30531
   538
  \<subseteq> A"} and @{prop "A \<subseteq> {}"} and then back to @{prop "A = {}"}!
haftmann@30352
   539
*}
haftmann@30352
   540
haftmann@30531
   541
lemma equalityE: "A = B ==> (A \<subseteq> B ==> B \<subseteq> A ==> P) ==> P"
haftmann@30531
   542
  by (simp add: subset_refl)
haftmann@30531
   543
haftmann@30531
   544
lemma equalityCE [elim]:
haftmann@30531
   545
    "A = B ==> (c \<in> A ==> c \<in> B ==> P) ==> (c \<notin> A ==> c \<notin> B ==> P) ==> P"
haftmann@30531
   546
  by blast
haftmann@30531
   547
haftmann@30531
   548
lemma eqset_imp_iff: "A = B ==> (x : A) = (x : B)"
haftmann@30531
   549
  by simp
haftmann@30531
   550
haftmann@30531
   551
lemma eqelem_imp_iff: "x = y ==> (x : A) = (y : A)"
haftmann@30531
   552
  by simp
haftmann@30531
   553
haftmann@30531
   554
haftmann@30531
   555
subsubsection {* The universal set -- UNIV *}
haftmann@30531
   556
haftmann@30531
   557
lemma UNIV_I [simp]: "x : UNIV"
haftmann@30531
   558
  by (simp add: UNIV_def)
haftmann@30531
   559
haftmann@30531
   560
declare UNIV_I [intro]  -- {* unsafe makes it less likely to cause problems *}
haftmann@30531
   561
haftmann@30531
   562
lemma UNIV_witness [intro?]: "EX x. x : UNIV"
haftmann@30531
   563
  by simp
haftmann@30531
   564
haftmann@30531
   565
lemma subset_UNIV [simp]: "A \<subseteq> UNIV"
haftmann@30531
   566
  by (rule subsetI) (rule UNIV_I)
haftmann@30531
   567
haftmann@30531
   568
text {*
haftmann@30531
   569
  \medskip Eta-contracting these two rules (to remove @{text P})
haftmann@30531
   570
  causes them to be ignored because of their interaction with
haftmann@30531
   571
  congruence rules.
haftmann@30531
   572
*}
haftmann@30531
   573
haftmann@30531
   574
lemma ball_UNIV [simp]: "Ball UNIV P = All P"
haftmann@30531
   575
  by (simp add: Ball_def)
haftmann@30531
   576
haftmann@30531
   577
lemma bex_UNIV [simp]: "Bex UNIV P = Ex P"
haftmann@30531
   578
  by (simp add: Bex_def)
haftmann@30531
   579
haftmann@30531
   580
lemma UNIV_eq_I: "(\<And>x. x \<in> A) \<Longrightarrow> UNIV = A"
haftmann@30531
   581
  by auto
haftmann@30531
   582
haftmann@30531
   583
haftmann@30531
   584
subsubsection {* The empty set *}
haftmann@30531
   585
haftmann@30531
   586
lemma empty_iff [simp]: "(c : {}) = False"
haftmann@30531
   587
  by (simp add: empty_def)
haftmann@30531
   588
haftmann@30531
   589
lemma emptyE [elim!]: "a : {} ==> P"
haftmann@30531
   590
  by simp
haftmann@30531
   591
haftmann@30531
   592
lemma empty_subsetI [iff]: "{} \<subseteq> A"
haftmann@30531
   593
    -- {* One effect is to delete the ASSUMPTION @{prop "{} <= A"} *}
haftmann@30531
   594
  by blast
haftmann@30531
   595
haftmann@30531
   596
lemma equals0I: "(!!y. y \<in> A ==> False) ==> A = {}"
haftmann@30531
   597
  by blast
haftmann@30531
   598
haftmann@30531
   599
lemma equals0D: "A = {} ==> a \<notin> A"
haftmann@30531
   600
    -- {* Use for reasoning about disjointness: @{prop "A Int B = {}"} *}
haftmann@30531
   601
  by blast
haftmann@30531
   602
haftmann@30531
   603
lemma ball_empty [simp]: "Ball {} P = True"
haftmann@30531
   604
  by (simp add: Ball_def)
haftmann@30531
   605
haftmann@30531
   606
lemma bex_empty [simp]: "Bex {} P = False"
haftmann@30531
   607
  by (simp add: Bex_def)
haftmann@30531
   608
haftmann@30531
   609
lemma UNIV_not_empty [iff]: "UNIV ~= {}"
haftmann@30531
   610
  by (blast elim: equalityE)
haftmann@30531
   611
haftmann@30531
   612
haftmann@30531
   613
subsubsection {* The Powerset operator -- Pow *}
haftmann@30531
   614
haftmann@32077
   615
definition Pow :: "'a set => 'a set set" where
haftmann@32077
   616
  Pow_def: "Pow A = {B. B \<le> A}"
haftmann@32077
   617
haftmann@30531
   618
lemma Pow_iff [iff]: "(A \<in> Pow B) = (A \<subseteq> B)"
haftmann@30531
   619
  by (simp add: Pow_def)
haftmann@30531
   620
haftmann@30531
   621
lemma PowI: "A \<subseteq> B ==> A \<in> Pow B"
haftmann@30531
   622
  by (simp add: Pow_def)
haftmann@30531
   623
haftmann@30531
   624
lemma PowD: "A \<in> Pow B ==> A \<subseteq> B"
haftmann@30531
   625
  by (simp add: Pow_def)
haftmann@30531
   626
haftmann@30531
   627
lemma Pow_bottom: "{} \<in> Pow B"
haftmann@30531
   628
  by simp
haftmann@30531
   629
haftmann@30531
   630
lemma Pow_top: "A \<in> Pow A"
haftmann@30531
   631
  by (simp add: subset_refl)
haftmann@30531
   632
haftmann@30531
   633
haftmann@30531
   634
subsubsection {* Set complement *}
haftmann@30531
   635
haftmann@30531
   636
lemma Compl_iff [simp]: "(c \<in> -A) = (c \<notin> A)"
haftmann@30531
   637
  by (simp add: mem_def fun_Compl_def bool_Compl_def)
haftmann@30531
   638
haftmann@30531
   639
lemma ComplI [intro!]: "(c \<in> A ==> False) ==> c \<in> -A"
haftmann@30531
   640
  by (unfold mem_def fun_Compl_def bool_Compl_def) blast
clasohm@923
   641
wenzelm@11979
   642
text {*
haftmann@30531
   643
  \medskip This form, with negated conclusion, works well with the
haftmann@30531
   644
  Classical prover.  Negated assumptions behave like formulae on the
haftmann@30531
   645
  right side of the notional turnstile ... *}
haftmann@30531
   646
haftmann@30531
   647
lemma ComplD [dest!]: "c : -A ==> c~:A"
haftmann@30531
   648
  by (simp add: mem_def fun_Compl_def bool_Compl_def)
haftmann@30531
   649
haftmann@30531
   650
lemmas ComplE = ComplD [elim_format]
haftmann@30531
   651
haftmann@30531
   652
lemma Compl_eq: "- A = {x. ~ x : A}" by blast
haftmann@30531
   653
haftmann@30531
   654
haftmann@30531
   655
subsubsection {* Binary union -- Un *}
haftmann@30531
   656
haftmann@30531
   657
lemma Un_iff [simp]: "(c : A Un B) = (c:A | c:B)"
haftmann@30531
   658
  by (unfold Un_def) blast
haftmann@30531
   659
haftmann@30531
   660
lemma UnI1 [elim?]: "c:A ==> c : A Un B"
haftmann@30531
   661
  by simp
haftmann@30531
   662
haftmann@30531
   663
lemma UnI2 [elim?]: "c:B ==> c : A Un B"
haftmann@30531
   664
  by simp
haftmann@30531
   665
haftmann@30531
   666
text {*
haftmann@30531
   667
  \medskip Classical introduction rule: no commitment to @{prop A} vs
haftmann@30531
   668
  @{prop B}.
wenzelm@11979
   669
*}
wenzelm@11979
   670
haftmann@30531
   671
lemma UnCI [intro!]: "(c~:B ==> c:A) ==> c : A Un B"
haftmann@30531
   672
  by auto
haftmann@30531
   673
haftmann@30531
   674
lemma UnE [elim!]: "c : A Un B ==> (c:A ==> P) ==> (c:B ==> P) ==> P"
haftmann@30531
   675
  by (unfold Un_def) blast
haftmann@30531
   676
haftmann@30531
   677
haftmann@30531
   678
subsubsection {* Binary intersection -- Int *}
haftmann@30531
   679
haftmann@30531
   680
lemma Int_iff [simp]: "(c : A Int B) = (c:A & c:B)"
haftmann@30531
   681
  by (unfold Int_def) blast
haftmann@30531
   682
haftmann@30531
   683
lemma IntI [intro!]: "c:A ==> c:B ==> c : A Int B"
haftmann@30531
   684
  by simp
haftmann@30531
   685
haftmann@30531
   686
lemma IntD1: "c : A Int B ==> c:A"
haftmann@30531
   687
  by simp
haftmann@30531
   688
haftmann@30531
   689
lemma IntD2: "c : A Int B ==> c:B"
haftmann@30531
   690
  by simp
haftmann@30531
   691
haftmann@30531
   692
lemma IntE [elim!]: "c : A Int B ==> (c:A ==> c:B ==> P) ==> P"
haftmann@30531
   693
  by simp
haftmann@30531
   694
haftmann@30531
   695
haftmann@30531
   696
subsubsection {* Set difference *}
haftmann@30531
   697
haftmann@30531
   698
lemma Diff_iff [simp]: "(c : A - B) = (c:A & c~:B)"
haftmann@30531
   699
  by (simp add: mem_def fun_diff_def bool_diff_def)
haftmann@30531
   700
haftmann@30531
   701
lemma DiffI [intro!]: "c : A ==> c ~: B ==> c : A - B"
haftmann@30531
   702
  by simp
haftmann@30531
   703
haftmann@30531
   704
lemma DiffD1: "c : A - B ==> c : A"
haftmann@30531
   705
  by simp
haftmann@30531
   706
haftmann@30531
   707
lemma DiffD2: "c : A - B ==> c : B ==> P"
haftmann@30531
   708
  by simp
haftmann@30531
   709
haftmann@30531
   710
lemma DiffE [elim!]: "c : A - B ==> (c:A ==> c~:B ==> P) ==> P"
haftmann@30531
   711
  by simp
haftmann@30531
   712
haftmann@30531
   713
lemma set_diff_eq: "A - B = {x. x : A & ~ x : B}" by blast
haftmann@30531
   714
haftmann@30531
   715
lemma Compl_eq_Diff_UNIV: "-A = (UNIV - A)"
haftmann@30531
   716
by blast
haftmann@30531
   717
haftmann@30531
   718
haftmann@31456
   719
subsubsection {* Augmenting a set -- @{const insert} *}
haftmann@30531
   720
haftmann@30531
   721
lemma insert_iff [simp]: "(a : insert b A) = (a = b | a:A)"
haftmann@30531
   722
  by (unfold insert_def) blast
haftmann@30531
   723
haftmann@30531
   724
lemma insertI1: "a : insert a B"
haftmann@30531
   725
  by simp
haftmann@30531
   726
haftmann@30531
   727
lemma insertI2: "a : B ==> a : insert b B"
haftmann@30531
   728
  by simp
haftmann@30531
   729
haftmann@30531
   730
lemma insertE [elim!]: "a : insert b A ==> (a = b ==> P) ==> (a:A ==> P) ==> P"
haftmann@30531
   731
  by (unfold insert_def) blast
haftmann@30531
   732
haftmann@30531
   733
lemma insertCI [intro!]: "(a~:B ==> a = b) ==> a: insert b B"
haftmann@30531
   734
  -- {* Classical introduction rule. *}
haftmann@30531
   735
  by auto
haftmann@30531
   736
haftmann@30531
   737
lemma subset_insert_iff: "(A \<subseteq> insert x B) = (if x:A then A - {x} \<subseteq> B else A \<subseteq> B)"
haftmann@30531
   738
  by auto
haftmann@30531
   739
haftmann@30531
   740
lemma set_insert:
haftmann@30531
   741
  assumes "x \<in> A"
haftmann@30531
   742
  obtains B where "A = insert x B" and "x \<notin> B"
haftmann@30531
   743
proof
haftmann@30531
   744
  from assms show "A = insert x (A - {x})" by blast
haftmann@30531
   745
next
haftmann@30531
   746
  show "x \<notin> A - {x}" by blast
haftmann@30531
   747
qed
haftmann@30531
   748
haftmann@30531
   749
lemma insert_ident: "x ~: A ==> x ~: B ==> (insert x A = insert x B) = (A = B)"
haftmann@30531
   750
by auto
haftmann@30531
   751
haftmann@30531
   752
subsubsection {* Singletons, using insert *}
haftmann@30531
   753
haftmann@30531
   754
lemma singletonI [intro!,noatp]: "a : {a}"
haftmann@30531
   755
    -- {* Redundant? But unlike @{text insertCI}, it proves the subgoal immediately! *}
haftmann@30531
   756
  by (rule insertI1)
haftmann@30531
   757
haftmann@30531
   758
lemma singletonD [dest!,noatp]: "b : {a} ==> b = a"
haftmann@30531
   759
  by blast
haftmann@30531
   760
haftmann@30531
   761
lemmas singletonE = singletonD [elim_format]
haftmann@30531
   762
haftmann@30531
   763
lemma singleton_iff: "(b : {a}) = (b = a)"
haftmann@30531
   764
  by blast
haftmann@30531
   765
haftmann@30531
   766
lemma singleton_inject [dest!]: "{a} = {b} ==> a = b"
haftmann@30531
   767
  by blast
haftmann@30531
   768
haftmann@30531
   769
lemma singleton_insert_inj_eq [iff,noatp]:
haftmann@30531
   770
     "({b} = insert a A) = (a = b & A \<subseteq> {b})"
haftmann@30531
   771
  by blast
haftmann@30531
   772
haftmann@30531
   773
lemma singleton_insert_inj_eq' [iff,noatp]:
haftmann@30531
   774
     "(insert a A = {b}) = (a = b & A \<subseteq> {b})"
haftmann@30531
   775
  by blast
haftmann@30531
   776
haftmann@30531
   777
lemma subset_singletonD: "A \<subseteq> {x} ==> A = {} | A = {x}"
haftmann@30531
   778
  by fast
haftmann@30531
   779
haftmann@30531
   780
lemma singleton_conv [simp]: "{x. x = a} = {a}"
haftmann@30531
   781
  by blast
haftmann@30531
   782
haftmann@30531
   783
lemma singleton_conv2 [simp]: "{x. a = x} = {a}"
haftmann@30531
   784
  by blast
haftmann@30531
   785
haftmann@30531
   786
lemma diff_single_insert: "A - {x} \<subseteq> B ==> x \<in> A ==> A \<subseteq> insert x B"
haftmann@30531
   787
  by blast
haftmann@30531
   788
haftmann@30531
   789
lemma doubleton_eq_iff: "({a,b} = {c,d}) = (a=c & b=d | a=d & b=c)"
haftmann@30531
   790
  by (blast elim: equalityE)
haftmann@30531
   791
wenzelm@11979
   792
haftmann@32077
   793
subsubsection {* Image of a set under a function *}
haftmann@32077
   794
haftmann@32077
   795
text {*
haftmann@32077
   796
  Frequently @{term b} does not have the syntactic form of @{term "f x"}.
haftmann@32077
   797
*}
haftmann@32077
   798
haftmann@32077
   799
definition image :: "('a => 'b) => 'a set => 'b set" (infixr "`" 90) where
haftmann@32077
   800
  image_def [noatp]: "f ` A = {y. EX x:A. y = f(x)}"
haftmann@32077
   801
haftmann@32077
   802
abbreviation
haftmann@32077
   803
  range :: "('a => 'b) => 'b set" where -- "of function"
haftmann@32077
   804
  "range f == f ` UNIV"
haftmann@32077
   805
haftmann@32077
   806
lemma image_eqI [simp, intro]: "b = f x ==> x:A ==> b : f`A"
haftmann@32077
   807
  by (unfold image_def) blast
haftmann@32077
   808
haftmann@32077
   809
lemma imageI: "x : A ==> f x : f ` A"
haftmann@32077
   810
  by (rule image_eqI) (rule refl)
haftmann@32077
   811
haftmann@32077
   812
lemma rev_image_eqI: "x:A ==> b = f x ==> b : f`A"
haftmann@32077
   813
  -- {* This version's more effective when we already have the
haftmann@32077
   814
    required @{term x}. *}
haftmann@32077
   815
  by (unfold image_def) blast
haftmann@32077
   816
haftmann@32077
   817
lemma imageE [elim!]:
haftmann@32077
   818
  "b : (%x. f x)`A ==> (!!x. b = f x ==> x:A ==> P) ==> P"
haftmann@32077
   819
  -- {* The eta-expansion gives variable-name preservation. *}
haftmann@32077
   820
  by (unfold image_def) blast
haftmann@32077
   821
haftmann@32077
   822
lemma image_Un: "f`(A Un B) = f`A Un f`B"
haftmann@32077
   823
  by blast
haftmann@32077
   824
haftmann@32077
   825
lemma image_iff: "(z : f`A) = (EX x:A. z = f x)"
haftmann@32077
   826
  by blast
haftmann@32077
   827
haftmann@32077
   828
lemma image_subset_iff: "(f`A \<subseteq> B) = (\<forall>x\<in>A. f x \<in> B)"
haftmann@32077
   829
  -- {* This rewrite rule would confuse users if made default. *}
haftmann@32077
   830
  by blast
haftmann@32077
   831
haftmann@32077
   832
lemma subset_image_iff: "(B \<subseteq> f`A) = (EX AA. AA \<subseteq> A & B = f`AA)"
haftmann@32077
   833
  apply safe
haftmann@32077
   834
   prefer 2 apply fast
haftmann@32077
   835
  apply (rule_tac x = "{a. a : A & f a : B}" in exI, fast)
haftmann@32077
   836
  done
haftmann@32077
   837
haftmann@32077
   838
lemma image_subsetI: "(!!x. x \<in> A ==> f x \<in> B) ==> f`A \<subseteq> B"
haftmann@32077
   839
  -- {* Replaces the three steps @{text subsetI}, @{text imageE},
haftmann@32077
   840
    @{text hypsubst}, but breaks too many existing proofs. *}
haftmann@32077
   841
  by blast
wenzelm@11979
   842
wenzelm@11979
   843
text {*
haftmann@32077
   844
  \medskip Range of a function -- just a translation for image!
haftmann@32077
   845
*}
haftmann@32077
   846
haftmann@32077
   847
lemma range_eqI: "b = f x ==> b \<in> range f"
haftmann@32077
   848
  by simp
haftmann@32077
   849
haftmann@32077
   850
lemma rangeI: "f x \<in> range f"
haftmann@32077
   851
  by simp
haftmann@32077
   852
haftmann@32077
   853
lemma rangeE [elim?]: "b \<in> range (\<lambda>x. f x) ==> (!!x. b = f x ==> P) ==> P"
haftmann@32077
   854
  by blast
haftmann@32077
   855
haftmann@32077
   856
haftmann@32077
   857
subsection {* Complete lattices *}
haftmann@32077
   858
haftmann@32077
   859
notation
haftmann@32077
   860
  less_eq  (infix "\<sqsubseteq>" 50) and
haftmann@32077
   861
  less (infix "\<sqsubset>" 50) and
haftmann@32077
   862
  inf  (infixl "\<sqinter>" 70) and
haftmann@32077
   863
  sup  (infixl "\<squnion>" 65)
haftmann@32077
   864
haftmann@32077
   865
class complete_lattice = lattice + bot + top +
haftmann@32077
   866
  fixes Inf :: "'a set \<Rightarrow> 'a" ("\<Sqinter>_" [900] 900)
haftmann@32077
   867
    and Sup :: "'a set \<Rightarrow> 'a" ("\<Squnion>_" [900] 900)
haftmann@32077
   868
  assumes Inf_lower: "x \<in> A \<Longrightarrow> \<Sqinter>A \<sqsubseteq> x"
haftmann@32077
   869
     and Inf_greatest: "(\<And>x. x \<in> A \<Longrightarrow> z \<sqsubseteq> x) \<Longrightarrow> z \<sqsubseteq> \<Sqinter>A"
haftmann@32077
   870
  assumes Sup_upper: "x \<in> A \<Longrightarrow> x \<sqsubseteq> \<Squnion>A"
haftmann@32077
   871
     and Sup_least: "(\<And>x. x \<in> A \<Longrightarrow> x \<sqsubseteq> z) \<Longrightarrow> \<Squnion>A \<sqsubseteq> z"
haftmann@32077
   872
begin
haftmann@32077
   873
haftmann@32077
   874
lemma Inf_Sup: "\<Sqinter>A = \<Squnion>{b. \<forall>a \<in> A. b \<le> a}"
haftmann@32077
   875
  by (auto intro: antisym Inf_lower Inf_greatest Sup_upper Sup_least)
haftmann@32077
   876
haftmann@32077
   877
lemma Sup_Inf:  "\<Squnion>A = \<Sqinter>{b. \<forall>a \<in> A. a \<le> b}"
haftmann@32077
   878
  by (auto intro: antisym Inf_lower Inf_greatest Sup_upper Sup_least)
haftmann@32077
   879
haftmann@32077
   880
lemma Inf_Univ: "\<Sqinter>UNIV = \<Squnion>{}"
haftmann@32077
   881
  unfolding Sup_Inf by (auto simp add: UNIV_def)
haftmann@32077
   882
haftmann@32077
   883
lemma Sup_Univ: "\<Squnion>UNIV = \<Sqinter>{}"
haftmann@32077
   884
  unfolding Inf_Sup by (auto simp add: UNIV_def)
haftmann@32077
   885
haftmann@32077
   886
lemma Inf_insert: "\<Sqinter>insert a A = a \<sqinter> \<Sqinter>A"
haftmann@32077
   887
  by (auto intro: le_infI le_infI1 le_infI2 antisym Inf_greatest Inf_lower)
haftmann@32077
   888
haftmann@32077
   889
lemma Sup_insert: "\<Squnion>insert a A = a \<squnion> \<Squnion>A"
haftmann@32077
   890
  by (auto intro: le_supI le_supI1 le_supI2 antisym Sup_least Sup_upper)
haftmann@32077
   891
haftmann@32077
   892
lemma Inf_singleton [simp]:
haftmann@32077
   893
  "\<Sqinter>{a} = a"
haftmann@32077
   894
  by (auto intro: antisym Inf_lower Inf_greatest)
haftmann@32077
   895
haftmann@32077
   896
lemma Sup_singleton [simp]:
haftmann@32077
   897
  "\<Squnion>{a} = a"
haftmann@32077
   898
  by (auto intro: antisym Sup_upper Sup_least)
haftmann@32077
   899
haftmann@32077
   900
lemma Inf_insert_simp:
haftmann@32077
   901
  "\<Sqinter>insert a A = (if A = {} then a else a \<sqinter> \<Sqinter>A)"
haftmann@32077
   902
  by (cases "A = {}") (simp_all, simp add: Inf_insert)
haftmann@32077
   903
haftmann@32077
   904
lemma Sup_insert_simp:
haftmann@32077
   905
  "\<Squnion>insert a A = (if A = {} then a else a \<squnion> \<Squnion>A)"
haftmann@32077
   906
  by (cases "A = {}") (simp_all, simp add: Sup_insert)
haftmann@32077
   907
haftmann@32077
   908
lemma Inf_binary:
haftmann@32077
   909
  "\<Sqinter>{a, b} = a \<sqinter> b"
haftmann@32077
   910
  by (auto simp add: Inf_insert_simp)
haftmann@32077
   911
haftmann@32077
   912
lemma Sup_binary:
haftmann@32077
   913
  "\<Squnion>{a, b} = a \<squnion> b"
haftmann@32077
   914
  by (auto simp add: Sup_insert_simp)
haftmann@32077
   915
haftmann@32077
   916
lemma bot_def:
haftmann@32077
   917
  "bot = \<Squnion>{}"
haftmann@32077
   918
  by (auto intro: antisym Sup_least)
haftmann@32077
   919
haftmann@32077
   920
lemma top_def:
haftmann@32077
   921
  "top = \<Sqinter>{}"
haftmann@32077
   922
  by (auto intro: antisym Inf_greatest)
haftmann@32077
   923
haftmann@32077
   924
lemma sup_bot [simp]:
haftmann@32077
   925
  "x \<squnion> bot = x"
haftmann@32077
   926
  using bot_least [of x] by (simp add: le_iff_sup sup_commute)
haftmann@32077
   927
haftmann@32077
   928
lemma inf_top [simp]:
haftmann@32077
   929
  "x \<sqinter> top = x"
haftmann@32077
   930
  using top_greatest [of x] by (simp add: le_iff_inf inf_commute)
haftmann@32077
   931
haftmann@32077
   932
definition SUPR :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a" where
haftmann@32077
   933
  "SUPR A f == \<Squnion> (f ` A)"
haftmann@32077
   934
haftmann@32077
   935
definition INFI :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a" where
haftmann@32077
   936
  "INFI A f == \<Sqinter> (f ` A)"
haftmann@32077
   937
haftmann@32077
   938
end
haftmann@32077
   939
haftmann@32077
   940
syntax
haftmann@32077
   941
  "_SUP1"     :: "pttrns => 'b => 'b"           ("(3SUP _./ _)" [0, 10] 10)
haftmann@32077
   942
  "_SUP"      :: "pttrn => 'a set => 'b => 'b"  ("(3SUP _:_./ _)" [0, 10] 10)
haftmann@32077
   943
  "_INF1"     :: "pttrns => 'b => 'b"           ("(3INF _./ _)" [0, 10] 10)
haftmann@32077
   944
  "_INF"      :: "pttrn => 'a set => 'b => 'b"  ("(3INF _:_./ _)" [0, 10] 10)
haftmann@32077
   945
haftmann@32077
   946
translations
haftmann@32077
   947
  "SUP x y. B"   == "SUP x. SUP y. B"
haftmann@32077
   948
  "SUP x. B"     == "CONST SUPR CONST UNIV (%x. B)"
haftmann@32077
   949
  "SUP x. B"     == "SUP x:CONST UNIV. B"
haftmann@32077
   950
  "SUP x:A. B"   == "CONST SUPR A (%x. B)"
haftmann@32077
   951
  "INF x y. B"   == "INF x. INF y. B"
haftmann@32077
   952
  "INF x. B"     == "CONST INFI CONST UNIV (%x. B)"
haftmann@32077
   953
  "INF x. B"     == "INF x:CONST UNIV. B"
haftmann@32077
   954
  "INF x:A. B"   == "CONST INFI A (%x. B)"
haftmann@32077
   955
haftmann@32077
   956
(* To avoid eta-contraction of body: *)
haftmann@32077
   957
print_translation {*
haftmann@32077
   958
let
haftmann@32077
   959
  fun btr' syn (A :: Abs abs :: ts) =
haftmann@32077
   960
    let val (x,t) = atomic_abs_tr' abs
haftmann@32077
   961
    in list_comb (Syntax.const syn $ x $ A $ t, ts) end
haftmann@32077
   962
  val const_syntax_name = Sign.const_syntax_name @{theory} o fst o dest_Const
haftmann@32077
   963
in
haftmann@32077
   964
[(const_syntax_name @{term SUPR}, btr' "_SUP"),(const_syntax_name @{term "INFI"}, btr' "_INF")]
haftmann@32077
   965
end
wenzelm@11979
   966
*}
wenzelm@11979
   967
haftmann@32077
   968
context complete_lattice
haftmann@32077
   969
begin
haftmann@32077
   970
haftmann@32077
   971
lemma le_SUPI: "i : A \<Longrightarrow> M i \<le> (SUP i:A. M i)"
haftmann@32077
   972
  by (auto simp add: SUPR_def intro: Sup_upper)
haftmann@32077
   973
haftmann@32077
   974
lemma SUP_leI: "(\<And>i. i : A \<Longrightarrow> M i \<le> u) \<Longrightarrow> (SUP i:A. M i) \<le> u"
haftmann@32077
   975
  by (auto simp add: SUPR_def intro: Sup_least)
haftmann@32077
   976
haftmann@32077
   977
lemma INF_leI: "i : A \<Longrightarrow> (INF i:A. M i) \<le> M i"
haftmann@32077
   978
  by (auto simp add: INFI_def intro: Inf_lower)
haftmann@32077
   979
haftmann@32077
   980
lemma le_INFI: "(\<And>i. i : A \<Longrightarrow> u \<le> M i) \<Longrightarrow> u \<le> (INF i:A. M i)"
haftmann@32077
   981
  by (auto simp add: INFI_def intro: Inf_greatest)
haftmann@32077
   982
haftmann@32077
   983
lemma SUP_const[simp]: "A \<noteq> {} \<Longrightarrow> (SUP i:A. M) = M"
haftmann@32077
   984
  by (auto intro: antisym SUP_leI le_SUPI)
haftmann@32077
   985
haftmann@32077
   986
lemma INF_const[simp]: "A \<noteq> {} \<Longrightarrow> (INF i:A. M) = M"
haftmann@32077
   987
  by (auto intro: antisym INF_leI le_INFI)
haftmann@32077
   988
haftmann@32077
   989
end
haftmann@32077
   990
haftmann@32077
   991
haftmann@32077
   992
subsection {* Bool as complete lattice *}
haftmann@32077
   993
haftmann@32077
   994
instantiation bool :: complete_lattice
haftmann@32077
   995
begin
haftmann@32077
   996
haftmann@32077
   997
definition
haftmann@32077
   998
  Inf_bool_def: "\<Sqinter>A \<longleftrightarrow> (\<forall>x\<in>A. x)"
haftmann@32077
   999
haftmann@32077
  1000
definition
haftmann@32077
  1001
  Sup_bool_def: "\<Squnion>A \<longleftrightarrow> (\<exists>x\<in>A. x)"
haftmann@32077
  1002
haftmann@32077
  1003
instance proof
haftmann@32077
  1004
qed (auto simp add: Inf_bool_def Sup_bool_def le_bool_def)
haftmann@32077
  1005
haftmann@32077
  1006
end
haftmann@32077
  1007
haftmann@32077
  1008
lemma Inf_empty_bool [simp]:
haftmann@32077
  1009
  "\<Sqinter>{}"
haftmann@32077
  1010
  unfolding Inf_bool_def by auto
haftmann@32077
  1011
haftmann@32077
  1012
lemma not_Sup_empty_bool [simp]:
haftmann@32077
  1013
  "\<not> \<Squnion>{}"
haftmann@32077
  1014
  unfolding Sup_bool_def by auto
haftmann@32077
  1015
haftmann@32077
  1016
haftmann@32077
  1017
subsection {* Fun as complete lattice *}
haftmann@32077
  1018
haftmann@32077
  1019
instantiation "fun" :: (type, complete_lattice) complete_lattice
haftmann@32077
  1020
begin
haftmann@32077
  1021
haftmann@32077
  1022
definition
haftmann@32077
  1023
  Inf_fun_def [code del]: "\<Sqinter>A = (\<lambda>x. \<Sqinter>{y. \<exists>f\<in>A. y = f x})"
haftmann@32077
  1024
haftmann@32077
  1025
definition
haftmann@32077
  1026
  Sup_fun_def [code del]: "\<Squnion>A = (\<lambda>x. \<Squnion>{y. \<exists>f\<in>A. y = f x})"
haftmann@32077
  1027
haftmann@32077
  1028
instance proof
haftmann@32077
  1029
qed (auto simp add: Inf_fun_def Sup_fun_def le_fun_def
haftmann@32077
  1030
  intro: Inf_lower Sup_upper Inf_greatest Sup_least)
haftmann@32077
  1031
haftmann@32077
  1032
end
haftmann@32077
  1033
haftmann@32077
  1034
lemma Inf_empty_fun:
haftmann@32077
  1035
  "\<Sqinter>{} = (\<lambda>_. \<Sqinter>{})"
haftmann@32077
  1036
  by rule (simp add: Inf_fun_def, simp add: empty_def)
haftmann@32077
  1037
haftmann@32077
  1038
lemma Sup_empty_fun:
haftmann@32077
  1039
  "\<Squnion>{} = (\<lambda>_. \<Squnion>{})"
haftmann@32077
  1040
  by rule (simp add: Sup_fun_def, simp add: empty_def)
haftmann@32077
  1041
haftmann@32077
  1042
haftmann@32077
  1043
subsection {* Set as lattice *}
haftmann@32077
  1044
haftmann@32077
  1045
definition INTER :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b set) \<Rightarrow> 'b set" where
haftmann@32077
  1046
  "INTER A B \<equiv> {y. \<forall>x\<in>A. y \<in> B x}"
haftmann@32077
  1047
haftmann@32077
  1048
definition UNION :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b set) \<Rightarrow> 'b set" where
haftmann@32077
  1049
  "UNION A B \<equiv> {y. \<exists>x\<in>A. y \<in> B x}"
haftmann@32077
  1050
haftmann@32077
  1051
definition Inter :: "'a set set \<Rightarrow> 'a set" where
haftmann@32077
  1052
  "Inter S \<equiv> INTER S (\<lambda>x. x)"
haftmann@32077
  1053
haftmann@32077
  1054
definition Union :: "'a set set \<Rightarrow> 'a set" where
haftmann@32077
  1055
  "Union S \<equiv> UNION S (\<lambda>x. x)"
haftmann@32077
  1056
haftmann@32077
  1057
notation (xsymbols)
haftmann@32077
  1058
  Inter  ("\<Inter>_" [90] 90) and
haftmann@32077
  1059
  Union  ("\<Union>_" [90] 90)
haftmann@32077
  1060
haftmann@32077
  1061
syntax
haftmann@32077
  1062
  "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3INT _./ _)" [0, 10] 10)
haftmann@32077
  1063
  "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3UN _./ _)" [0, 10] 10)
haftmann@32077
  1064
  "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3INT _:_./ _)" [0, 10] 10)
haftmann@32077
  1065
  "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3UN _:_./ _)" [0, 10] 10)
haftmann@32077
  1066
haftmann@32077
  1067
syntax (xsymbols)
haftmann@32077
  1068
  "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3\<Inter>_./ _)" [0, 10] 10)
haftmann@32077
  1069
  "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3\<Union>_./ _)" [0, 10] 10)
haftmann@32077
  1070
  "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Inter>_\<in>_./ _)" [0, 10] 10)
haftmann@32077
  1071
  "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Union>_\<in>_./ _)" [0, 10] 10)
haftmann@32077
  1072
haftmann@32077
  1073
syntax (latex output)
haftmann@32077
  1074
  "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3\<Inter>(00\<^bsub>_\<^esub>)/ _)" [0, 10] 10)
haftmann@32077
  1075
  "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3\<Union>(00\<^bsub>_\<^esub>)/ _)" [0, 10] 10)
haftmann@32077
  1076
  "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Inter>(00\<^bsub>_\<in>_\<^esub>)/ _)" [0, 10] 10)
haftmann@32077
  1077
  "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Union>(00\<^bsub>_\<in>_\<^esub>)/ _)" [0, 10] 10)
haftmann@32077
  1078
haftmann@32077
  1079
translations
haftmann@32077
  1080
  "INT x y. B"  == "INT x. INT y. B"
haftmann@32077
  1081
  "INT x. B"    == "CONST INTER CONST UNIV (%x. B)"
haftmann@32077
  1082
  "INT x. B"    == "INT x:CONST UNIV. B"
haftmann@32077
  1083
  "INT x:A. B"  == "CONST INTER A (%x. B)"
haftmann@32077
  1084
  "UN x y. B"   == "UN x. UN y. B"
haftmann@32077
  1085
  "UN x. B"     == "CONST UNION CONST UNIV (%x. B)"
haftmann@32077
  1086
  "UN x. B"     == "UN x:CONST UNIV. B"
haftmann@32077
  1087
  "UN x:A. B"   == "CONST UNION A (%x. B)"
haftmann@32077
  1088
haftmann@32077
  1089
text {*
haftmann@32077
  1090
  Note the difference between ordinary xsymbol syntax of indexed
haftmann@32077
  1091
  unions and intersections (e.g.\ @{text"\<Union>a\<^isub>1\<in>A\<^isub>1. B"})
haftmann@32077
  1092
  and their \LaTeX\ rendition: @{term"\<Union>a\<^isub>1\<in>A\<^isub>1. B"}. The
haftmann@32077
  1093
  former does not make the index expression a subscript of the
haftmann@32077
  1094
  union/intersection symbol because this leads to problems with nested
haftmann@32077
  1095
  subscripts in Proof General.
haftmann@32077
  1096
*}
haftmann@32077
  1097
haftmann@32077
  1098
(* To avoid eta-contraction of body: *)
haftmann@32077
  1099
print_translation {*
haftmann@32077
  1100
let
haftmann@32077
  1101
  fun btr' syn [A, Abs abs] =
haftmann@32077
  1102
    let val (x, t) = atomic_abs_tr' abs
haftmann@32077
  1103
    in Syntax.const syn $ x $ A $ t end
haftmann@32077
  1104
in [(@{const_syntax UNION}, btr' "@UNION"),(@{const_syntax INTER}, btr' "@INTER")] end
haftmann@32077
  1105
*}
haftmann@32077
  1106
haftmann@32077
  1107
lemma Inter_image_eq [simp]:
haftmann@32077
  1108
  "\<Inter>(B`A) = (\<Inter>x\<in>A. B x)"
haftmann@32077
  1109
  by (auto simp add: Inter_def INTER_def image_def)
haftmann@32077
  1110
haftmann@32077
  1111
lemma Union_image_eq [simp]:
haftmann@32077
  1112
  "\<Union>(B`A) = (\<Union>x\<in>A. B x)"
haftmann@32077
  1113
  by (auto simp add: Union_def UNION_def image_def)
haftmann@32077
  1114
haftmann@32077
  1115
lemma inf_set_eq: "A \<sqinter> B = A \<inter> B"
haftmann@32077
  1116
  by (simp add: inf_fun_eq inf_bool_eq Int_def Collect_def mem_def)
haftmann@32077
  1117
haftmann@32077
  1118
lemma sup_set_eq: "A \<squnion> B = A \<union> B"
haftmann@32077
  1119
  by (simp add: sup_fun_eq sup_bool_eq Un_def Collect_def mem_def)
haftmann@32077
  1120
haftmann@32077
  1121
lemma mono_Int: "mono f \<Longrightarrow> f (A \<inter> B) \<subseteq> f A \<inter> f B"
haftmann@32077
  1122
  apply (fold inf_set_eq sup_set_eq)
haftmann@32077
  1123
  apply (erule mono_inf)
haftmann@32077
  1124
  done
haftmann@32077
  1125
haftmann@32077
  1126
lemma mono_Un: "mono f \<Longrightarrow> f A \<union> f B \<subseteq> f (A \<union> B)"
haftmann@32077
  1127
  apply (fold inf_set_eq sup_set_eq)
haftmann@32077
  1128
  apply (erule mono_sup)
haftmann@32077
  1129
  done
haftmann@32077
  1130
haftmann@32077
  1131
lemma top_set_eq: "top = UNIV"
haftmann@32077
  1132
  by (iprover intro!: subset_antisym subset_UNIV top_greatest)
haftmann@32077
  1133
haftmann@32077
  1134
lemma bot_set_eq: "bot = {}"
haftmann@32077
  1135
  by (iprover intro!: subset_antisym empty_subsetI bot_least)
haftmann@32077
  1136
haftmann@32077
  1137
lemma Inter_eq:
haftmann@32077
  1138
  "\<Inter>A = {x. \<forall>B \<in> A. x \<in> B}"
haftmann@32077
  1139
  by (simp add: Inter_def INTER_def)
haftmann@32077
  1140
haftmann@32077
  1141
lemma Union_eq:
haftmann@32077
  1142
  "\<Union>A = {x. \<exists>B \<in> A. x \<in> B}"
haftmann@32077
  1143
  by (simp add: Union_def UNION_def)
haftmann@32077
  1144
haftmann@32077
  1145
lemma Inf_set_eq:
haftmann@32077
  1146
  "\<Sqinter>S = \<Inter>S"
haftmann@32077
  1147
proof (rule set_ext)
haftmann@32077
  1148
  fix x
haftmann@32077
  1149
  have "(\<forall>Q\<in>{P. \<exists>A\<in>S. P \<longleftrightarrow> x \<in> A}. Q) \<longleftrightarrow> (\<forall>A\<in>S. x \<in> A)"
haftmann@32077
  1150
    by auto
haftmann@32077
  1151
  then show "x \<in> \<Sqinter>S \<longleftrightarrow> x \<in> \<Inter>S"
haftmann@32077
  1152
    by (simp add: Inter_eq Inf_fun_def Inf_bool_def) (simp add: mem_def)
haftmann@32077
  1153
qed
haftmann@32077
  1154
haftmann@32077
  1155
lemma Sup_set_eq:
haftmann@32077
  1156
  "\<Squnion>S = \<Union>S"
haftmann@32077
  1157
proof (rule set_ext)
haftmann@32077
  1158
  fix x
haftmann@32077
  1159
  have "(\<exists>Q\<in>{P. \<exists>A\<in>S. P \<longleftrightarrow> x \<in> A}. Q) \<longleftrightarrow> (\<exists>A\<in>S. x \<in> A)"
haftmann@32077
  1160
    by auto
haftmann@32077
  1161
  then show "x \<in> \<Squnion>S \<longleftrightarrow> x \<in> \<Union>S"
haftmann@32077
  1162
    by (simp add: Union_eq Sup_fun_def Sup_bool_def) (simp add: mem_def)
haftmann@32077
  1163
qed
haftmann@32077
  1164
haftmann@32077
  1165
lemma INFI_set_eq:
haftmann@32077
  1166
  "(INF x:S. f x) = (\<Inter>x\<in>S. f x)"
haftmann@32077
  1167
  by (simp add: INFI_def Inf_set_eq)
haftmann@32077
  1168
haftmann@32077
  1169
lemma SUPR_set_eq:
haftmann@32077
  1170
  "(SUP x:S. f x) = (\<Union>x\<in>S. f x)"
haftmann@32077
  1171
  by (simp add: SUPR_def Sup_set_eq)
haftmann@32077
  1172
  
haftmann@32077
  1173
no_notation
haftmann@32077
  1174
  less_eq  (infix "\<sqsubseteq>" 50) and
haftmann@32077
  1175
  less (infix "\<sqsubset>" 50) and
haftmann@32077
  1176
  inf  (infixl "\<sqinter>" 70) and
haftmann@32077
  1177
  sup  (infixl "\<squnion>" 65) and
haftmann@32077
  1178
  Inf  ("\<Sqinter>_" [900] 900) and
haftmann@32077
  1179
  Sup  ("\<Squnion>_" [900] 900)
haftmann@32077
  1180
haftmann@32077
  1181
haftmann@32077
  1182
subsubsection {* Unions of families *}
haftmann@32077
  1183
paulson@24286
  1184
declare UNION_def [noatp]
paulson@24286
  1185
wenzelm@11979
  1186
lemma UN_iff [simp]: "(b: (UN x:A. B x)) = (EX x:A. b: B x)"
wenzelm@11979
  1187
  by (unfold UNION_def) blast
wenzelm@11979
  1188
wenzelm@11979
  1189
lemma UN_I [intro]: "a:A ==> b: B a ==> b: (UN x:A. B x)"
wenzelm@11979
  1190
  -- {* The order of the premises presupposes that @{term A} is rigid;
wenzelm@11979
  1191
    @{term b} may be flexible. *}
wenzelm@11979
  1192
  by auto
wenzelm@11979
  1193
wenzelm@11979
  1194
lemma UN_E [elim!]: "b : (UN x:A. B x) ==> (!!x. x:A ==> b: B x ==> R) ==> R"
wenzelm@11979
  1195
  by (unfold UNION_def) blast
clasohm@923
  1196
wenzelm@11979
  1197
lemma UN_cong [cong]:
wenzelm@11979
  1198
    "A = B ==> (!!x. x:B ==> C x = D x) ==> (UN x:A. C x) = (UN x:B. D x)"
wenzelm@11979
  1199
  by (simp add: UNION_def)
wenzelm@11979
  1200
berghofe@29691
  1201
lemma strong_UN_cong:
berghofe@29691
  1202
    "A = B ==> (!!x. x:B =simp=> C x = D x) ==> (UN x:A. C x) = (UN x:B. D x)"
berghofe@29691
  1203
  by (simp add: UNION_def simp_implies_def)
berghofe@29691
  1204
haftmann@32077
  1205
lemma image_eq_UN: "f`A = (UN x:A. {f x})"
haftmann@32077
  1206
  by blast
haftmann@32077
  1207
wenzelm@11979
  1208
wenzelm@11979
  1209
subsubsection {* Intersections of families *}
wenzelm@11979
  1210
wenzelm@11979
  1211
lemma INT_iff [simp]: "(b: (INT x:A. B x)) = (ALL x:A. b: B x)"
wenzelm@11979
  1212
  by (unfold INTER_def) blast
clasohm@923
  1213
wenzelm@11979
  1214
lemma INT_I [intro!]: "(!!x. x:A ==> b: B x) ==> b : (INT x:A. B x)"
wenzelm@11979
  1215
  by (unfold INTER_def) blast
wenzelm@11979
  1216
wenzelm@11979
  1217
lemma INT_D [elim]: "b : (INT x:A. B x) ==> a:A ==> b: B a"
wenzelm@11979
  1218
  by auto
wenzelm@11979
  1219
wenzelm@11979
  1220
lemma INT_E [elim]: "b : (INT x:A. B x) ==> (b: B a ==> R) ==> (a~:A ==> R) ==> R"
wenzelm@11979
  1221
  -- {* "Classical" elimination -- by the Excluded Middle on @{prop "a:A"}. *}
wenzelm@11979
  1222
  by (unfold INTER_def) blast
wenzelm@11979
  1223
wenzelm@11979
  1224
lemma INT_cong [cong]:
wenzelm@11979
  1225
    "A = B ==> (!!x. x:B ==> C x = D x) ==> (INT x:A. C x) = (INT x:B. D x)"
wenzelm@11979
  1226
  by (simp add: INTER_def)
wenzelm@7238
  1227
clasohm@923
  1228
wenzelm@11979
  1229
subsubsection {* Union *}
wenzelm@11979
  1230
paulson@24286
  1231
lemma Union_iff [simp,noatp]: "(A : Union C) = (EX X:C. A:X)"
wenzelm@11979
  1232
  by (unfold Union_def) blast
wenzelm@11979
  1233
wenzelm@11979
  1234
lemma UnionI [intro]: "X:C ==> A:X ==> A : Union C"
wenzelm@11979
  1235
  -- {* The order of the premises presupposes that @{term C} is rigid;
wenzelm@11979
  1236
    @{term A} may be flexible. *}
wenzelm@11979
  1237
  by auto
wenzelm@11979
  1238
wenzelm@11979
  1239
lemma UnionE [elim!]: "A : Union C ==> (!!X. A:X ==> X:C ==> R) ==> R"
wenzelm@11979
  1240
  by (unfold Union_def) blast
wenzelm@11979
  1241
wenzelm@11979
  1242
wenzelm@11979
  1243
subsubsection {* Inter *}
wenzelm@11979
  1244
paulson@24286
  1245
lemma Inter_iff [simp,noatp]: "(A : Inter C) = (ALL X:C. A:X)"
wenzelm@11979
  1246
  by (unfold Inter_def) blast
wenzelm@11979
  1247
wenzelm@11979
  1248
lemma InterI [intro!]: "(!!X. X:C ==> A:X) ==> A : Inter C"
wenzelm@11979
  1249
  by (simp add: Inter_def)
wenzelm@11979
  1250
wenzelm@11979
  1251
text {*
wenzelm@11979
  1252
  \medskip A ``destruct'' rule -- every @{term X} in @{term C}
wenzelm@11979
  1253
  contains @{term A} as an element, but @{prop "A:X"} can hold when
wenzelm@11979
  1254
  @{prop "X:C"} does not!  This rule is analogous to @{text spec}.
wenzelm@11979
  1255
*}
wenzelm@11979
  1256
wenzelm@11979
  1257
lemma InterD [elim]: "A : Inter C ==> X:C ==> A:X"
wenzelm@11979
  1258
  by auto
wenzelm@11979
  1259
wenzelm@11979
  1260
lemma InterE [elim]: "A : Inter C ==> (X~:C ==> R) ==> (A:X ==> R) ==> R"
wenzelm@11979
  1261
  -- {* ``Classical'' elimination rule -- does not require proving
wenzelm@11979
  1262
    @{prop "X:C"}. *}
wenzelm@11979
  1263
  by (unfold Inter_def) blast
wenzelm@11979
  1264
haftmann@30531
  1265
haftmann@30531
  1266
subsubsection {* Set reasoning tools *}
haftmann@30531
  1267
nipkow@31166
  1268
text{* Elimination of @{text"{x. \<dots> & x=t & \<dots>}"}. *}
nipkow@31166
  1269
nipkow@31197
  1270
lemma Collect_conv_if: "{x. x=a & P x} = (if P a then {a} else {})"
nipkow@31197
  1271
by auto
nipkow@31197
  1272
nipkow@31197
  1273
lemma Collect_conv_if2: "{x. a=x & P x} = (if P a then {a} else {})"
nipkow@31166
  1274
by auto
nipkow@31166
  1275
nipkow@31197
  1276
text {*
nipkow@31197
  1277
Simproc for pulling @{text "x=t"} in @{text "{x. \<dots> & x=t & \<dots>}"}
nipkow@31197
  1278
to the front (and similarly for @{text "t=x"}):
nipkow@31197
  1279
*}
nipkow@31166
  1280
nipkow@31166
  1281
ML{*
nipkow@31166
  1282
  local
nipkow@31166
  1283
    val Coll_perm_tac = rtac @{thm Collect_cong} 1 THEN rtac @{thm iffI} 1 THEN
nipkow@31166
  1284
    ALLGOALS(EVERY'[REPEAT_DETERM o (etac @{thm conjE}),
nipkow@31166
  1285
                    DEPTH_SOLVE_1 o (ares_tac [@{thm conjI}])])
nipkow@31166
  1286
  in
nipkow@31166
  1287
    val defColl_regroup = Simplifier.simproc (the_context ())
nipkow@31166
  1288
      "defined Collect" ["{x. P x & Q x}"]
nipkow@31166
  1289
      (Quantifier1.rearrange_Coll Coll_perm_tac)
nipkow@31166
  1290
  end;
nipkow@31166
  1291
nipkow@31166
  1292
  Addsimprocs [defColl_regroup];
nipkow@31166
  1293
*}
nipkow@31166
  1294
haftmann@30531
  1295
text {*
haftmann@30531
  1296
  Rewrite rules for boolean case-splitting: faster than @{text
haftmann@30531
  1297
  "split_if [split]"}.
haftmann@30531
  1298
*}
haftmann@30531
  1299
haftmann@30531
  1300
lemma split_if_eq1: "((if Q then x else y) = b) = ((Q --> x = b) & (~ Q --> y = b))"
haftmann@30531
  1301
  by (rule split_if)
haftmann@30531
  1302
haftmann@30531
  1303
lemma split_if_eq2: "(a = (if Q then x else y)) = ((Q --> a = x) & (~ Q --> a = y))"
haftmann@30531
  1304
  by (rule split_if)
haftmann@30531
  1305
haftmann@30531
  1306
text {*
haftmann@30531
  1307
  Split ifs on either side of the membership relation.  Not for @{text
haftmann@30531
  1308
  "[simp]"} -- can cause goals to blow up!
haftmann@30531
  1309
*}
haftmann@30531
  1310
haftmann@30531
  1311
lemma split_if_mem1: "((if Q then x else y) : b) = ((Q --> x : b) & (~ Q --> y : b))"
haftmann@30531
  1312
  by (rule split_if)
haftmann@30531
  1313
haftmann@30531
  1314
lemma split_if_mem2: "(a : (if Q then x else y)) = ((Q --> a : x) & (~ Q --> a : y))"
haftmann@30531
  1315
  by (rule split_if [where P="%S. a : S"])
haftmann@30531
  1316
haftmann@30531
  1317
lemmas split_ifs = if_bool_eq_conj split_if_eq1 split_if_eq2 split_if_mem1 split_if_mem2
haftmann@30531
  1318
haftmann@30531
  1319
(*Would like to add these, but the existing code only searches for the
haftmann@30531
  1320
  outer-level constant, which in this case is just "op :"; we instead need
haftmann@30531
  1321
  to use term-nets to associate patterns with rules.  Also, if a rule fails to
haftmann@30531
  1322
  apply, then the formula should be kept.
haftmann@30531
  1323
  [("HOL.uminus", Compl_iff RS iffD1), ("HOL.minus", [Diff_iff RS iffD1]),
haftmann@30531
  1324
   ("Int", [IntD1,IntD2]),
haftmann@30531
  1325
   ("Collect", [CollectD]), ("Inter", [InterD]), ("INTER", [INT_D])]
haftmann@30531
  1326
 *)
haftmann@30531
  1327
haftmann@30531
  1328
ML {*
haftmann@30531
  1329
  val mksimps_pairs = [(@{const_name Ball}, @{thms bspec})] @ mksimps_pairs;
haftmann@30531
  1330
*}
haftmann@30531
  1331
declaration {* fn _ =>
haftmann@30531
  1332
  Simplifier.map_ss (fn ss => ss setmksimps (mksimps mksimps_pairs))
haftmann@30531
  1333
*}
haftmann@30531
  1334
haftmann@30531
  1335
haftmann@30531
  1336
subsubsection {* The ``proper subset'' relation *}
haftmann@30531
  1337
haftmann@30531
  1338
lemma psubsetI [intro!,noatp]: "A \<subseteq> B ==> A \<noteq> B ==> A \<subset> B"
haftmann@30531
  1339
  by (unfold less_le) blast
haftmann@30531
  1340
haftmann@30531
  1341
lemma psubsetE [elim!,noatp]: 
haftmann@30531
  1342
    "[|A \<subset> B;  [|A \<subseteq> B; ~ (B\<subseteq>A)|] ==> R|] ==> R"
haftmann@30531
  1343
  by (unfold less_le) blast
haftmann@30531
  1344
haftmann@30531
  1345
lemma psubset_insert_iff:
haftmann@30531
  1346
  "(A \<subset> insert x B) = (if x \<in> B then A \<subset> B else if x \<in> A then A - {x} \<subset> B else A \<subseteq> B)"
haftmann@30531
  1347
  by (auto simp add: less_le subset_insert_iff)
haftmann@30531
  1348
haftmann@30531
  1349
lemma psubset_eq: "(A \<subset> B) = (A \<subseteq> B & A \<noteq> B)"
haftmann@30531
  1350
  by (simp only: less_le)
haftmann@30531
  1351
haftmann@30531
  1352
lemma psubset_imp_subset: "A \<subset> B ==> A \<subseteq> B"
haftmann@30531
  1353
  by (simp add: psubset_eq)
haftmann@30531
  1354
haftmann@30531
  1355
lemma psubset_trans: "[| A \<subset> B; B \<subset> C |] ==> A \<subset> C"
haftmann@30531
  1356
apply (unfold less_le)
haftmann@30531
  1357
apply (auto dest: subset_antisym)
haftmann@30531
  1358
done
haftmann@30531
  1359
haftmann@30531
  1360
lemma psubsetD: "[| A \<subset> B; c \<in> A |] ==> c \<in> B"
haftmann@30531
  1361
apply (unfold less_le)
haftmann@30531
  1362
apply (auto dest: subsetD)
haftmann@30531
  1363
done
haftmann@30531
  1364
haftmann@30531
  1365
lemma psubset_subset_trans: "A \<subset> B ==> B \<subseteq> C ==> A \<subset> C"
haftmann@30531
  1366
  by (auto simp add: psubset_eq)
haftmann@30531
  1367
haftmann@30531
  1368
lemma subset_psubset_trans: "A \<subseteq> B ==> B \<subset> C ==> A \<subset> C"
haftmann@30531
  1369
  by (auto simp add: psubset_eq)
haftmann@30531
  1370
haftmann@30531
  1371
lemma psubset_imp_ex_mem: "A \<subset> B ==> \<exists>b. b \<in> (B - A)"
haftmann@30531
  1372
  by (unfold less_le) blast
haftmann@30531
  1373
haftmann@30531
  1374
lemma atomize_ball:
haftmann@30531
  1375
    "(!!x. x \<in> A ==> P x) == Trueprop (\<forall>x\<in>A. P x)"
haftmann@30531
  1376
  by (simp only: Ball_def atomize_all atomize_imp)
haftmann@30531
  1377
haftmann@30531
  1378
lemmas [symmetric, rulify] = atomize_ball
haftmann@30531
  1379
  and [symmetric, defn] = atomize_ball
haftmann@30531
  1380
haftmann@30531
  1381
haftmann@30531
  1382
subsection {* Further set-theory lemmas *}
haftmann@30531
  1383
haftmann@30531
  1384
subsubsection {* Derived rules involving subsets. *}
haftmann@30531
  1385
haftmann@30531
  1386
text {* @{text insert}. *}
haftmann@30531
  1387
haftmann@30531
  1388
lemma subset_insertI: "B \<subseteq> insert a B"
haftmann@30531
  1389
  by (rule subsetI) (erule insertI2)
haftmann@30531
  1390
haftmann@30531
  1391
lemma subset_insertI2: "A \<subseteq> B \<Longrightarrow> A \<subseteq> insert b B"
haftmann@30531
  1392
  by blast
haftmann@30531
  1393
haftmann@30531
  1394
lemma subset_insert: "x \<notin> A ==> (A \<subseteq> insert x B) = (A \<subseteq> B)"
haftmann@30531
  1395
  by blast
wenzelm@12897
  1396
wenzelm@12897
  1397
wenzelm@12897
  1398
text {* \medskip Big Union -- least upper bound of a set. *}
wenzelm@12897
  1399
wenzelm@12897
  1400
lemma Union_upper: "B \<in> A ==> B \<subseteq> Union A"
nipkow@17589
  1401
  by (iprover intro: subsetI UnionI)
wenzelm@12897
  1402
wenzelm@12897
  1403
lemma Union_least: "(!!X. X \<in> A ==> X \<subseteq> C) ==> Union A \<subseteq> C"
nipkow@17589
  1404
  by (iprover intro: subsetI elim: UnionE dest: subsetD)
wenzelm@12897
  1405
wenzelm@12897
  1406
wenzelm@12897
  1407
text {* \medskip General union. *}
wenzelm@12897
  1408
wenzelm@12897
  1409
lemma UN_upper: "a \<in> A ==> B a \<subseteq> (\<Union>x\<in>A. B x)"
wenzelm@12897
  1410
  by blast
wenzelm@12897
  1411
wenzelm@12897
  1412
lemma UN_least: "(!!x. x \<in> A ==> B x \<subseteq> C) ==> (\<Union>x\<in>A. B x) \<subseteq> C"
nipkow@17589
  1413
  by (iprover intro: subsetI elim: UN_E dest: subsetD)
wenzelm@12897
  1414
wenzelm@12897
  1415
wenzelm@12897
  1416
text {* \medskip Big Intersection -- greatest lower bound of a set. *}
wenzelm@12897
  1417
wenzelm@12897
  1418
lemma Inter_lower: "B \<in> A ==> Inter A \<subseteq> B"
wenzelm@12897
  1419
  by blast
wenzelm@12897
  1420
ballarin@14551
  1421
lemma Inter_subset:
ballarin@14551
  1422
  "[| !!X. X \<in> A ==> X \<subseteq> B; A ~= {} |] ==> \<Inter>A \<subseteq> B"
ballarin@14551
  1423
  by blast
ballarin@14551
  1424
wenzelm@12897
  1425
lemma Inter_greatest: "(!!X. X \<in> A ==> C \<subseteq> X) ==> C \<subseteq> Inter A"
nipkow@17589
  1426
  by (iprover intro: InterI subsetI dest: subsetD)
wenzelm@12897
  1427
wenzelm@12897
  1428
lemma INT_lower: "a \<in> A ==> (\<Inter>x\<in>A. B x) \<subseteq> B a"
wenzelm@12897
  1429
  by blast
wenzelm@12897
  1430
wenzelm@12897
  1431
lemma INT_greatest: "(!!x. x \<in> A ==> C \<subseteq> B x) ==> C \<subseteq> (\<Inter>x\<in>A. B x)"
nipkow@17589
  1432
  by (iprover intro: INT_I subsetI dest: subsetD)
wenzelm@12897
  1433
haftmann@30531
  1434
haftmann@30531
  1435
text {* \medskip Finite Union -- the least upper bound of two sets. *}
haftmann@30531
  1436
haftmann@30531
  1437
lemma Un_upper1: "A \<subseteq> A \<union> B"
haftmann@30531
  1438
  by blast
haftmann@30531
  1439
haftmann@30531
  1440
lemma Un_upper2: "B \<subseteq> A \<union> B"
haftmann@30531
  1441
  by blast
haftmann@30531
  1442
haftmann@30531
  1443
lemma Un_least: "A \<subseteq> C ==> B \<subseteq> C ==> A \<union> B \<subseteq> C"
haftmann@30531
  1444
  by blast
haftmann@30531
  1445
haftmann@30531
  1446
haftmann@30531
  1447
text {* \medskip Finite Intersection -- the greatest lower bound of two sets. *}
haftmann@30531
  1448
haftmann@30531
  1449
lemma Int_lower1: "A \<inter> B \<subseteq> A"
haftmann@30531
  1450
  by blast
haftmann@30531
  1451
haftmann@30531
  1452
lemma Int_lower2: "A \<inter> B \<subseteq> B"
haftmann@30531
  1453
  by blast
haftmann@30531
  1454
haftmann@30531
  1455
lemma Int_greatest: "C \<subseteq> A ==> C \<subseteq> B ==> C \<subseteq> A \<inter> B"
haftmann@30531
  1456
  by blast
haftmann@30531
  1457
haftmann@30531
  1458
haftmann@30531
  1459
text {* \medskip Set difference. *}
haftmann@30531
  1460
haftmann@30531
  1461
lemma Diff_subset: "A - B \<subseteq> A"
haftmann@30531
  1462
  by blast
haftmann@30531
  1463
haftmann@30531
  1464
lemma Diff_subset_conv: "(A - B \<subseteq> C) = (A \<subseteq> B \<union> C)"
haftmann@30531
  1465
by blast
haftmann@30531
  1466
haftmann@30531
  1467
haftmann@30531
  1468
subsubsection {* Equalities involving union, intersection, inclusion, etc. *}
haftmann@30531
  1469
haftmann@30531
  1470
text {* @{text "{}"}. *}
haftmann@30531
  1471
haftmann@30531
  1472
lemma Collect_const [simp]: "{s. P} = (if P then UNIV else {})"
haftmann@30531
  1473
  -- {* supersedes @{text "Collect_False_empty"} *}
haftmann@30531
  1474
  by auto
haftmann@30531
  1475
haftmann@30531
  1476
lemma subset_empty [simp]: "(A \<subseteq> {}) = (A = {})"
haftmann@30531
  1477
  by blast
haftmann@30531
  1478
haftmann@30531
  1479
lemma not_psubset_empty [iff]: "\<not> (A < {})"
haftmann@30531
  1480
  by (unfold less_le) blast
haftmann@30531
  1481
haftmann@30531
  1482
lemma Collect_empty_eq [simp]: "(Collect P = {}) = (\<forall>x. \<not> P x)"
haftmann@30531
  1483
by blast
haftmann@30531
  1484
haftmann@30531
  1485
lemma empty_Collect_eq [simp]: "({} = Collect P) = (\<forall>x. \<not> P x)"
haftmann@30531
  1486
by blast
haftmann@30531
  1487
haftmann@30531
  1488
lemma Collect_neg_eq: "{x. \<not> P x} = - {x. P x}"
haftmann@30531
  1489
  by blast
haftmann@30531
  1490
haftmann@30531
  1491
lemma Collect_disj_eq: "{x. P x | Q x} = {x. P x} \<union> {x. Q x}"
haftmann@30531
  1492
  by blast
haftmann@30531
  1493
haftmann@30531
  1494
lemma Collect_imp_eq: "{x. P x --> Q x} = -{x. P x} \<union> {x. Q x}"
haftmann@30531
  1495
  by blast
haftmann@30531
  1496
haftmann@30531
  1497
lemma Collect_conj_eq: "{x. P x & Q x} = {x. P x} \<inter> {x. Q x}"
wenzelm@12897
  1498
  by blast
wenzelm@12897
  1499
wenzelm@12897
  1500
lemma Collect_all_eq: "{x. \<forall>y. P x y} = (\<Inter>y. {x. P x y})"
wenzelm@12897
  1501
  by blast
wenzelm@12897
  1502
wenzelm@12897
  1503
lemma Collect_ball_eq: "{x. \<forall>y\<in>A. P x y} = (\<Inter>y\<in>A. {x. P x y})"
wenzelm@12897
  1504
  by blast
wenzelm@12897
  1505
paulson@24286
  1506
lemma Collect_ex_eq [noatp]: "{x. \<exists>y. P x y} = (\<Union>y. {x. P x y})"
wenzelm@12897
  1507
  by blast
wenzelm@12897
  1508
paulson@24286
  1509
lemma Collect_bex_eq [noatp]: "{x. \<exists>y\<in>A. P x y} = (\<Union>y\<in>A. {x. P x y})"
wenzelm@12897
  1510
  by blast
wenzelm@12897
  1511
wenzelm@12897
  1512
haftmann@30531
  1513
text {* \medskip @{text insert}. *}
haftmann@30531
  1514
haftmann@30531
  1515
lemma insert_is_Un: "insert a A = {a} Un A"
haftmann@30531
  1516
  -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a {}"} *}
haftmann@30531
  1517
  by blast
haftmann@30531
  1518
haftmann@30531
  1519
lemma insert_not_empty [simp]: "insert a A \<noteq> {}"
haftmann@30531
  1520
  by blast
haftmann@30531
  1521
haftmann@30531
  1522
lemmas empty_not_insert = insert_not_empty [symmetric, standard]
haftmann@30531
  1523
declare empty_not_insert [simp]
haftmann@30531
  1524
haftmann@30531
  1525
lemma insert_absorb: "a \<in> A ==> insert a A = A"
haftmann@30531
  1526
  -- {* @{text "[simp]"} causes recursive calls when there are nested inserts *}
haftmann@30531
  1527
  -- {* with \emph{quadratic} running time *}
haftmann@30531
  1528
  by blast
haftmann@30531
  1529
haftmann@30531
  1530
lemma insert_absorb2 [simp]: "insert x (insert x A) = insert x A"
haftmann@30531
  1531
  by blast
haftmann@30531
  1532
haftmann@30531
  1533
lemma insert_commute: "insert x (insert y A) = insert y (insert x A)"
haftmann@30531
  1534
  by blast
haftmann@30531
  1535
haftmann@30531
  1536
lemma insert_subset [simp]: "(insert x A \<subseteq> B) = (x \<in> B & A \<subseteq> B)"
haftmann@30531
  1537
  by blast
haftmann@30531
  1538
haftmann@30531
  1539
lemma mk_disjoint_insert: "a \<in> A ==> \<exists>B. A = insert a B & a \<notin> B"
haftmann@30531
  1540
  -- {* use new @{text B} rather than @{text "A - {a}"} to avoid infinite unfolding *}
haftmann@30531
  1541
  apply (rule_tac x = "A - {a}" in exI, blast)
haftmann@30531
  1542
  done
haftmann@30531
  1543
haftmann@30531
  1544
lemma insert_Collect: "insert a (Collect P) = {u. u \<noteq> a --> P u}"
haftmann@30531
  1545
  by auto
haftmann@30531
  1546
haftmann@30531
  1547
lemma UN_insert_distrib: "u \<in> A ==> (\<Union>x\<in>A. insert a (B x)) = insert a (\<Union>x\<in>A. B x)"
haftmann@30531
  1548
  by blast
haftmann@30531
  1549
haftmann@30531
  1550
lemma insert_inter_insert[simp]: "insert a A \<inter> insert a B = insert a (A \<inter> B)"
mehta@14742
  1551
  by blast
nipkow@14302
  1552
haftmann@30531
  1553
lemma insert_disjoint [simp,noatp]:
haftmann@30531
  1554
 "(insert a A \<inter> B = {}) = (a \<notin> B \<and> A \<inter> B = {})"
haftmann@30531
  1555
 "({} = insert a A \<inter> B) = (a \<notin> B \<and> {} = A \<inter> B)"
haftmann@30531
  1556
  by auto
haftmann@30531
  1557
haftmann@30531
  1558
lemma disjoint_insert [simp,noatp]:
haftmann@30531
  1559
 "(B \<inter> insert a A = {}) = (a \<notin> B \<and> B \<inter> A = {})"
haftmann@30531
  1560
 "({} = A \<inter> insert b B) = (b \<notin> A \<and> {} = A \<inter> B)"
haftmann@30531
  1561
  by auto
haftmann@30531
  1562
haftmann@30531
  1563
text {* \medskip @{text image}. *}
haftmann@30531
  1564
haftmann@30531
  1565
lemma image_empty [simp]: "f`{} = {}"
haftmann@30531
  1566
  by blast
haftmann@30531
  1567
haftmann@30531
  1568
lemma image_insert [simp]: "f ` insert a B = insert (f a) (f`B)"
haftmann@30531
  1569
  by blast
haftmann@30531
  1570
haftmann@30531
  1571
lemma image_constant: "x \<in> A ==> (\<lambda>x. c) ` A = {c}"
haftmann@30531
  1572
  by auto
haftmann@30531
  1573
haftmann@30531
  1574
lemma image_constant_conv: "(%x. c) ` A = (if A = {} then {} else {c})"
haftmann@30531
  1575
by auto
haftmann@30531
  1576
haftmann@30531
  1577
lemma image_image: "f ` (g ` A) = (\<lambda>x. f (g x)) ` A"
nipkow@31441
  1578
by blast
haftmann@30531
  1579
haftmann@30531
  1580
lemma insert_image [simp]: "x \<in> A ==> insert (f x) (f`A) = f`A"
nipkow@31441
  1581
by blast
haftmann@30531
  1582
haftmann@30531
  1583
lemma image_is_empty [iff]: "(f`A = {}) = (A = {})"
nipkow@31441
  1584
by blast
nipkow@31441
  1585
nipkow@31441
  1586
lemma empty_is_image[iff]: "({} = f ` A) = (A = {})"
nipkow@31441
  1587
by blast
haftmann@30531
  1588
haftmann@30531
  1589
haftmann@30531
  1590
lemma image_Collect [noatp]: "f ` {x. P x} = {f x | x. P x}"
haftmann@30531
  1591
  -- {* NOT suitable as a default simprule: the RHS isn't simpler than the LHS,
haftmann@30531
  1592
      with its implicit quantifier and conjunction.  Also image enjoys better
haftmann@30531
  1593
      equational properties than does the RHS. *}
haftmann@30531
  1594
  by blast
haftmann@30531
  1595
haftmann@30531
  1596
lemma if_image_distrib [simp]:
haftmann@30531
  1597
  "(\<lambda>x. if P x then f x else g x) ` S
haftmann@30531
  1598
    = (f ` (S \<inter> {x. P x})) \<union> (g ` (S \<inter> {x. \<not> P x}))"
haftmann@30531
  1599
  by (auto simp add: image_def)
haftmann@30531
  1600
haftmann@30531
  1601
lemma image_cong: "M = N ==> (!!x. x \<in> N ==> f x = g x) ==> f`M = g`N"
haftmann@30531
  1602
  by (simp add: image_def)
haftmann@30531
  1603
haftmann@30531
  1604
haftmann@30531
  1605
text {* \medskip @{text range}. *}
haftmann@30531
  1606
paulson@24286
  1607
lemma full_SetCompr_eq [noatp]: "{u. \<exists>x. u = f x} = range f"
wenzelm@12897
  1608
  by auto
wenzelm@12897
  1609
huffman@27418
  1610
lemma range_composition: "range (\<lambda>x. f (g x)) = f`range g"
paulson@14208
  1611
by (subst image_image, simp)
wenzelm@12897
  1612
wenzelm@12897
  1613
wenzelm@12897
  1614
text {* \medskip @{text Int} *}
wenzelm@12897
  1615
wenzelm@12897
  1616
lemma Int_absorb [simp]: "A \<inter> A = A"
wenzelm@12897
  1617
  by blast
wenzelm@12897
  1618
wenzelm@12897
  1619
lemma Int_left_absorb: "A \<inter> (A \<inter> B) = A \<inter> B"
wenzelm@12897
  1620
  by blast
wenzelm@12897
  1621
wenzelm@12897
  1622
lemma Int_commute: "A \<inter> B = B \<inter> A"
wenzelm@12897
  1623
  by blast
wenzelm@12897
  1624
wenzelm@12897
  1625
lemma Int_left_commute: "A \<inter> (B \<inter> C) = B \<inter> (A \<inter> C)"
wenzelm@12897
  1626
  by blast
wenzelm@12897
  1627
wenzelm@12897
  1628
lemma Int_assoc: "(A \<inter> B) \<inter> C = A \<inter> (B \<inter> C)"
wenzelm@12897
  1629
  by blast
wenzelm@12897
  1630
wenzelm@12897
  1631
lemmas Int_ac = Int_assoc Int_left_absorb Int_commute Int_left_commute
wenzelm@12897
  1632
  -- {* Intersection is an AC-operator *}
wenzelm@12897
  1633
wenzelm@12897
  1634
lemma Int_absorb1: "B \<subseteq> A ==> A \<inter> B = B"
wenzelm@12897
  1635
  by blast
wenzelm@12897
  1636
wenzelm@12897
  1637
lemma Int_absorb2: "A \<subseteq> B ==> A \<inter> B = A"
wenzelm@12897
  1638
  by blast
wenzelm@12897
  1639
wenzelm@12897
  1640
lemma Int_empty_left [simp]: "{} \<inter> B = {}"
wenzelm@12897
  1641
  by blast
wenzelm@12897
  1642
wenzelm@12897
  1643
lemma Int_empty_right [simp]: "A \<inter> {} = {}"
wenzelm@12897
  1644
  by blast
wenzelm@12897
  1645
wenzelm@12897
  1646
lemma disjoint_eq_subset_Compl: "(A \<inter> B = {}) = (A \<subseteq> -B)"
wenzelm@12897
  1647
  by blast
wenzelm@12897
  1648
wenzelm@12897
  1649
lemma disjoint_iff_not_equal: "(A \<inter> B = {}) = (\<forall>x\<in>A. \<forall>y\<in>B. x \<noteq> y)"
wenzelm@12897
  1650
  by blast
wenzelm@12897
  1651
wenzelm@12897
  1652
lemma Int_UNIV_left [simp]: "UNIV \<inter> B = B"
wenzelm@12897
  1653
  by blast
wenzelm@12897
  1654
wenzelm@12897
  1655
lemma Int_UNIV_right [simp]: "A \<inter> UNIV = A"
wenzelm@12897
  1656
  by blast
wenzelm@12897
  1657
wenzelm@12897
  1658
lemma Int_eq_Inter: "A \<inter> B = \<Inter>{A, B}"
wenzelm@12897
  1659
  by blast
wenzelm@12897
  1660
wenzelm@12897
  1661
lemma Int_Un_distrib: "A \<inter> (B \<union> C) = (A \<inter> B) \<union> (A \<inter> C)"
wenzelm@12897
  1662
  by blast
wenzelm@12897
  1663
wenzelm@12897
  1664
lemma Int_Un_distrib2: "(B \<union> C) \<inter> A = (B \<inter> A) \<union> (C \<inter> A)"
wenzelm@12897
  1665
  by blast
wenzelm@12897
  1666
paulson@24286
  1667
lemma Int_UNIV [simp,noatp]: "(A \<inter> B = UNIV) = (A = UNIV & B = UNIV)"
wenzelm@12897
  1668
  by blast
wenzelm@12897
  1669
paulson@15102
  1670
lemma Int_subset_iff [simp]: "(C \<subseteq> A \<inter> B) = (C \<subseteq> A & C \<subseteq> B)"
wenzelm@12897
  1671
  by blast
wenzelm@12897
  1672
wenzelm@12897
  1673
lemma Int_Collect: "(x \<in> A \<inter> {x. P x}) = (x \<in> A & P x)"
wenzelm@12897
  1674
  by blast
wenzelm@12897
  1675
wenzelm@12897
  1676
wenzelm@12897
  1677
text {* \medskip @{text Un}. *}
wenzelm@12897
  1678
wenzelm@12897
  1679
lemma Un_absorb [simp]: "A \<union> A = A"
wenzelm@12897
  1680
  by blast
wenzelm@12897
  1681
wenzelm@12897
  1682
lemma Un_left_absorb: "A \<union> (A \<union> B) = A \<union> B"
wenzelm@12897
  1683
  by blast
wenzelm@12897
  1684
wenzelm@12897
  1685
lemma Un_commute: "A \<union> B = B \<union> A"
wenzelm@12897
  1686
  by blast
wenzelm@12897
  1687
wenzelm@12897
  1688
lemma Un_left_commute: "A \<union> (B \<union> C) = B \<union> (A \<union> C)"
wenzelm@12897
  1689
  by blast
wenzelm@12897
  1690
wenzelm@12897
  1691
lemma Un_assoc: "(A \<union> B) \<union> C = A \<union> (B \<union> C)"
wenzelm@12897
  1692
  by blast
wenzelm@12897
  1693
wenzelm@12897
  1694
lemmas Un_ac = Un_assoc Un_left_absorb Un_commute Un_left_commute
wenzelm@12897
  1695
  -- {* Union is an AC-operator *}
wenzelm@12897
  1696
wenzelm@12897
  1697
lemma Un_absorb1: "A \<subseteq> B ==> A \<union> B = B"
wenzelm@12897
  1698
  by blast
wenzelm@12897
  1699
wenzelm@12897
  1700
lemma Un_absorb2: "B \<subseteq> A ==> A \<union> B = A"
wenzelm@12897
  1701
  by blast
wenzelm@12897
  1702
wenzelm@12897
  1703
lemma Un_empty_left [simp]: "{} \<union> B = B"
wenzelm@12897
  1704
  by blast
wenzelm@12897
  1705
wenzelm@12897
  1706
lemma Un_empty_right [simp]: "A \<union> {} = A"
wenzelm@12897
  1707
  by blast
wenzelm@12897
  1708
wenzelm@12897
  1709
lemma Un_UNIV_left [simp]: "UNIV \<union> B = UNIV"
wenzelm@12897
  1710
  by blast
wenzelm@12897
  1711
wenzelm@12897
  1712
lemma Un_UNIV_right [simp]: "A \<union> UNIV = UNIV"
wenzelm@12897
  1713
  by blast
wenzelm@12897
  1714
wenzelm@12897
  1715
lemma Un_eq_Union: "A \<union> B = \<Union>{A, B}"
wenzelm@12897
  1716
  by blast
wenzelm@12897
  1717
wenzelm@12897
  1718
lemma Un_insert_left [simp]: "(insert a B) \<union> C = insert a (B \<union> C)"
wenzelm@12897
  1719
  by blast
wenzelm@12897
  1720
wenzelm@12897
  1721
lemma Un_insert_right [simp]: "A \<union> (insert a B) = insert a (A \<union> B)"
wenzelm@12897
  1722
  by blast
wenzelm@12897
  1723
wenzelm@12897
  1724
lemma Int_insert_left:
wenzelm@12897
  1725
    "(insert a B) Int C = (if a \<in> C then insert a (B \<inter> C) else B \<inter> C)"
wenzelm@12897
  1726
  by auto
wenzelm@12897
  1727
wenzelm@12897
  1728
lemma Int_insert_right:
wenzelm@12897
  1729
    "A \<inter> (insert a B) = (if a \<in> A then insert a (A \<inter> B) else A \<inter> B)"
wenzelm@12897
  1730
  by auto
wenzelm@12897
  1731
wenzelm@12897
  1732
lemma Un_Int_distrib: "A \<union> (B \<inter> C) = (A \<union> B) \<inter> (A \<union> C)"
wenzelm@12897
  1733
  by blast
wenzelm@12897
  1734
wenzelm@12897
  1735
lemma Un_Int_distrib2: "(B \<inter> C) \<union> A = (B \<union> A) \<inter> (C \<union> A)"
wenzelm@12897
  1736
  by blast
wenzelm@12897
  1737
wenzelm@12897
  1738
lemma Un_Int_crazy:
wenzelm@12897
  1739
    "(A \<inter> B) \<union> (B \<inter> C) \<union> (C \<inter> A) = (A \<union> B) \<inter> (B \<union> C) \<inter> (C \<union> A)"
wenzelm@12897
  1740
  by blast
wenzelm@12897
  1741
wenzelm@12897
  1742
lemma subset_Un_eq: "(A \<subseteq> B) = (A \<union> B = B)"
wenzelm@12897
  1743
  by blast
wenzelm@12897
  1744
wenzelm@12897
  1745
lemma Un_empty [iff]: "(A \<union> B = {}) = (A = {} & B = {})"
wenzelm@12897
  1746
  by blast
paulson@15102
  1747
paulson@15102
  1748
lemma Un_subset_iff [simp]: "(A \<union> B \<subseteq> C) = (A \<subseteq> C & B \<subseteq> C)"
wenzelm@12897
  1749
  by blast
wenzelm@12897
  1750
wenzelm@12897
  1751
lemma Un_Diff_Int: "(A - B) \<union> (A \<inter> B) = A"
wenzelm@12897
  1752
  by blast
wenzelm@12897
  1753
paulson@22172
  1754
lemma Diff_Int2: "A \<inter> C - B \<inter> C = A \<inter> C - B"
paulson@22172
  1755
  by blast
paulson@22172
  1756
wenzelm@12897
  1757
wenzelm@12897
  1758
text {* \medskip Set complement *}
wenzelm@12897
  1759
wenzelm@12897
  1760
lemma Compl_disjoint [simp]: "A \<inter> -A = {}"
wenzelm@12897
  1761
  by blast
wenzelm@12897
  1762
wenzelm@12897
  1763
lemma Compl_disjoint2 [simp]: "-A \<inter> A = {}"
wenzelm@12897
  1764
  by blast
wenzelm@12897
  1765
paulson@13818
  1766
lemma Compl_partition: "A \<union> -A = UNIV"
paulson@13818
  1767
  by blast
paulson@13818
  1768
paulson@13818
  1769
lemma Compl_partition2: "-A \<union> A = UNIV"
wenzelm@12897
  1770
  by blast
wenzelm@12897
  1771
wenzelm@12897
  1772
lemma double_complement [simp]: "- (-A) = (A::'a set)"
wenzelm@12897
  1773
  by blast
wenzelm@12897
  1774
wenzelm@12897
  1775
lemma Compl_Un [simp]: "-(A \<union> B) = (-A) \<inter> (-B)"
wenzelm@12897
  1776
  by blast
wenzelm@12897
  1777
wenzelm@12897
  1778
lemma Compl_Int [simp]: "-(A \<inter> B) = (-A) \<union> (-B)"
wenzelm@12897
  1779
  by blast
wenzelm@12897
  1780
wenzelm@12897
  1781
lemma Compl_UN [simp]: "-(\<Union>x\<in>A. B x) = (\<Inter>x\<in>A. -B x)"
wenzelm@12897
  1782
  by blast
wenzelm@12897
  1783
wenzelm@12897
  1784
lemma Compl_INT [simp]: "-(\<Inter>x\<in>A. B x) = (\<Union>x\<in>A. -B x)"
wenzelm@12897
  1785
  by blast
wenzelm@12897
  1786
wenzelm@12897
  1787
lemma subset_Compl_self_eq: "(A \<subseteq> -A) = (A = {})"
wenzelm@12897
  1788
  by blast
wenzelm@12897
  1789
wenzelm@12897
  1790
lemma Un_Int_assoc_eq: "((A \<inter> B) \<union> C = A \<inter> (B \<union> C)) = (C \<subseteq> A)"
wenzelm@12897
  1791
  -- {* Halmos, Naive Set Theory, page 16. *}
wenzelm@12897
  1792
  by blast
wenzelm@12897
  1793
wenzelm@12897
  1794
lemma Compl_UNIV_eq [simp]: "-UNIV = {}"
wenzelm@12897
  1795
  by blast
wenzelm@12897
  1796
wenzelm@12897
  1797
lemma Compl_empty_eq [simp]: "-{} = UNIV"
wenzelm@12897
  1798
  by blast
wenzelm@12897
  1799
wenzelm@12897
  1800
lemma Compl_subset_Compl_iff [iff]: "(-A \<subseteq> -B) = (B \<subseteq> A)"
wenzelm@12897
  1801
  by blast
wenzelm@12897
  1802
wenzelm@12897
  1803
lemma Compl_eq_Compl_iff [iff]: "(-A = -B) = (A = (B::'a set))"
wenzelm@12897
  1804
  by blast
wenzelm@12897
  1805
wenzelm@12897
  1806
wenzelm@12897
  1807
text {* \medskip @{text Union}. *}
wenzelm@12897
  1808
wenzelm@12897
  1809
lemma Union_empty [simp]: "Union({}) = {}"
wenzelm@12897
  1810
  by blast
wenzelm@12897
  1811
wenzelm@12897
  1812
lemma Union_UNIV [simp]: "Union UNIV = UNIV"
wenzelm@12897
  1813
  by blast
wenzelm@12897
  1814
wenzelm@12897
  1815
lemma Union_insert [simp]: "Union (insert a B) = a \<union> \<Union>B"
wenzelm@12897
  1816
  by blast
wenzelm@12897
  1817
wenzelm@12897
  1818
lemma Union_Un_distrib [simp]: "\<Union>(A Un B) = \<Union>A \<union> \<Union>B"
wenzelm@12897
  1819
  by blast
wenzelm@12897
  1820
wenzelm@12897
  1821
lemma Union_Int_subset: "\<Union>(A \<inter> B) \<subseteq> \<Union>A \<inter> \<Union>B"
wenzelm@12897
  1822
  by blast
wenzelm@12897
  1823
paulson@24286
  1824
lemma Union_empty_conv [simp,noatp]: "(\<Union>A = {}) = (\<forall>x\<in>A. x = {})"
nipkow@13653
  1825
  by blast
nipkow@13653
  1826
paulson@24286
  1827
lemma empty_Union_conv [simp,noatp]: "({} = \<Union>A) = (\<forall>x\<in>A. x = {})"
nipkow@13653
  1828
  by blast
wenzelm@12897
  1829
wenzelm@12897
  1830
lemma Union_disjoint: "(\<Union>C \<inter> A = {}) = (\<forall>B\<in>C. B \<inter> A = {})"
wenzelm@12897
  1831
  by blast
wenzelm@12897
  1832
wenzelm@12897
  1833
wenzelm@12897
  1834
text {* \medskip @{text Inter}. *}
wenzelm@12897
  1835
wenzelm@12897
  1836
lemma Inter_empty [simp]: "\<Inter>{} = UNIV"
wenzelm@12897
  1837
  by blast
wenzelm@12897
  1838
wenzelm@12897
  1839
lemma Inter_UNIV [simp]: "\<Inter>UNIV = {}"
wenzelm@12897
  1840
  by blast
wenzelm@12897
  1841
wenzelm@12897
  1842
lemma Inter_insert [simp]: "\<Inter>(insert a B) = a \<inter> \<Inter>B"
wenzelm@12897
  1843
  by blast
wenzelm@12897
  1844
wenzelm@12897
  1845
lemma Inter_Un_subset: "\<Inter>A \<union> \<Inter>B \<subseteq> \<Inter>(A \<inter> B)"
wenzelm@12897
  1846
  by blast
wenzelm@12897
  1847
wenzelm@12897
  1848
lemma Inter_Un_distrib: "\<Inter>(A \<union> B) = \<Inter>A \<inter> \<Inter>B"
wenzelm@12897
  1849
  by blast
wenzelm@12897
  1850
paulson@24286
  1851
lemma Inter_UNIV_conv [simp,noatp]:
nipkow@13653
  1852
  "(\<Inter>A = UNIV) = (\<forall>x\<in>A. x = UNIV)"
nipkow@13653
  1853
  "(UNIV = \<Inter>A) = (\<forall>x\<in>A. x = UNIV)"
paulson@14208
  1854
  by blast+
nipkow@13653
  1855
wenzelm@12897
  1856
wenzelm@12897
  1857
text {*
wenzelm@12897
  1858
  \medskip @{text UN} and @{text INT}.
wenzelm@12897
  1859
wenzelm@12897
  1860
  Basic identities: *}
wenzelm@12897
  1861
paulson@24286
  1862
lemma UN_empty [simp,noatp]: "(\<Union>x\<in>{}. B x) = {}"
wenzelm@12897
  1863
  by blast
wenzelm@12897
  1864
wenzelm@12897
  1865
lemma UN_empty2 [simp]: "(\<Union>x\<in>A. {}) = {}"
wenzelm@12897
  1866
  by blast
wenzelm@12897
  1867
wenzelm@12897
  1868
lemma UN_singleton [simp]: "(\<Union>x\<in>A. {x}) = A"
wenzelm@12897
  1869
  by blast
wenzelm@12897
  1870
wenzelm@12897
  1871
lemma UN_absorb: "k \<in> I ==> A k \<union> (\<Union>i\<in>I. A i) = (\<Union>i\<in>I. A i)"
paulson@15102
  1872
  by auto
wenzelm@12897
  1873
wenzelm@12897
  1874
lemma INT_empty [simp]: "(\<Inter>x\<in>{}. B x) = UNIV"
wenzelm@12897
  1875
  by blast
wenzelm@12897
  1876
wenzelm@12897
  1877
lemma INT_absorb: "k \<in> I ==> A k \<inter> (\<Inter>i\<in>I. A i) = (\<Inter>i\<in>I. A i)"
wenzelm@12897
  1878
  by blast
wenzelm@12897
  1879
wenzelm@12897
  1880
lemma UN_insert [simp]: "(\<Union>x\<in>insert a A. B x) = B a \<union> UNION A B"
wenzelm@12897
  1881
  by blast
wenzelm@12897
  1882
nipkow@24331
  1883
lemma UN_Un[simp]: "(\<Union>i \<in> A \<union> B. M i) = (\<Union>i\<in>A. M i) \<union> (\<Union>i\<in>B. M i)"
wenzelm@12897
  1884
  by blast
wenzelm@12897
  1885
wenzelm@12897
  1886
lemma UN_UN_flatten: "(\<Union>x \<in> (\<Union>y\<in>A. B y). C x) = (\<Union>y\<in>A. \<Union>x\<in>B y. C x)"
wenzelm@12897
  1887
  by blast
wenzelm@12897
  1888
wenzelm@12897
  1889
lemma UN_subset_iff: "((\<Union>i\<in>I. A i) \<subseteq> B) = (\<forall>i\<in>I. A i \<subseteq> B)"
wenzelm@12897
  1890
  by blast
wenzelm@12897
  1891
wenzelm@12897
  1892
lemma INT_subset_iff: "(B \<subseteq> (\<Inter>i\<in>I. A i)) = (\<forall>i\<in>I. B \<subseteq> A i)"
wenzelm@12897
  1893
  by blast
wenzelm@12897
  1894
wenzelm@12897
  1895
lemma INT_insert [simp]: "(\<Inter>x \<in> insert a A. B x) = B a \<inter> INTER A B"
wenzelm@12897
  1896
  by blast
wenzelm@12897
  1897
wenzelm@12897
  1898
lemma INT_Un: "(\<Inter>i \<in> A \<union> B. M i) = (\<Inter>i \<in> A. M i) \<inter> (\<Inter>i\<in>B. M i)"
wenzelm@12897
  1899
  by blast
wenzelm@12897
  1900
wenzelm@12897
  1901
lemma INT_insert_distrib:
wenzelm@12897
  1902
    "u \<in> A ==> (\<Inter>x\<in>A. insert a (B x)) = insert a (\<Inter>x\<in>A. B x)"
wenzelm@12897
  1903
  by blast
wenzelm@12897
  1904
wenzelm@12897
  1905
lemma image_Union: "f ` \<Union>S = (\<Union>x\<in>S. f ` x)"
wenzelm@12897
  1906
  by blast
wenzelm@12897
  1907
wenzelm@12897
  1908
lemma UN_constant [simp]: "(\<Union>y\<in>A. c) = (if A = {} then {} else c)"
wenzelm@12897
  1909
  by auto
wenzelm@12897
  1910
wenzelm@12897
  1911
lemma INT_constant [simp]: "(\<Inter>y\<in>A. c) = (if A = {} then UNIV else c)"
wenzelm@12897
  1912
  by auto
wenzelm@12897
  1913
wenzelm@12897
  1914
lemma UN_eq: "(\<Union>x\<in>A. B x) = \<Union>({Y. \<exists>x\<in>A. Y = B x})"
wenzelm@12897
  1915
  by blast
wenzelm@12897
  1916
wenzelm@12897
  1917
lemma INT_eq: "(\<Inter>x\<in>A. B x) = \<Inter>({Y. \<exists>x\<in>A. Y = B x})"
wenzelm@12897
  1918
  -- {* Look: it has an \emph{existential} quantifier *}
wenzelm@12897
  1919
  by blast
wenzelm@12897
  1920
paulson@18447
  1921
lemma UNION_empty_conv[simp]:
nipkow@13653
  1922
  "({} = (UN x:A. B x)) = (\<forall>x\<in>A. B x = {})"
nipkow@13653
  1923
  "((UN x:A. B x) = {}) = (\<forall>x\<in>A. B x = {})"
nipkow@13653
  1924
by blast+
nipkow@13653
  1925
paulson@18447
  1926
lemma INTER_UNIV_conv[simp]:
nipkow@13653
  1927
 "(UNIV = (INT x:A. B x)) = (\<forall>x\<in>A. B x = UNIV)"
nipkow@13653
  1928
 "((INT x:A. B x) = UNIV) = (\<forall>x\<in>A. B x = UNIV)"
nipkow@13653
  1929
by blast+
wenzelm@12897
  1930
wenzelm@12897
  1931
wenzelm@12897
  1932
text {* \medskip Distributive laws: *}
wenzelm@12897
  1933
wenzelm@12897
  1934
lemma Int_Union: "A \<inter> \<Union>B = (\<Union>C\<in>B. A \<inter> C)"
wenzelm@12897
  1935
  by blast
wenzelm@12897
  1936
wenzelm@12897
  1937
lemma Int_Union2: "\<Union>B \<inter> A = (\<Union>C\<in>B. C \<inter> A)"
wenzelm@12897
  1938
  by blast
wenzelm@12897
  1939
wenzelm@12897
  1940
lemma Un_Union_image: "(\<Union>x\<in>C. A x \<union> B x) = \<Union>(A`C) \<union> \<Union>(B`C)"
wenzelm@12897
  1941
  -- {* Devlin, Fundamentals of Contemporary Set Theory, page 12, exercise 5: *}
wenzelm@12897
  1942
  -- {* Union of a family of unions *}
wenzelm@12897
  1943
  by blast
wenzelm@12897
  1944
wenzelm@12897
  1945
lemma UN_Un_distrib: "(\<Union>i\<in>I. A i \<union> B i) = (\<Union>i\<in>I. A i) \<union> (\<Union>i\<in>I. B i)"
wenzelm@12897
  1946
  -- {* Equivalent version *}
wenzelm@12897
  1947
  by blast
wenzelm@12897
  1948
wenzelm@12897
  1949
lemma Un_Inter: "A \<union> \<Inter>B = (\<Inter>C\<in>B. A \<union> C)"
wenzelm@12897
  1950
  by blast
wenzelm@12897
  1951
wenzelm@12897
  1952
lemma Int_Inter_image: "(\<Inter>x\<in>C. A x \<inter> B x) = \<Inter>(A`C) \<inter> \<Inter>(B`C)"
wenzelm@12897
  1953
  by blast
wenzelm@12897
  1954
wenzelm@12897
  1955
lemma INT_Int_distrib: "(\<Inter>i\<in>I. A i \<inter> B i) = (\<Inter>i\<in>I. A i) \<inter> (\<Inter>i\<in>I. B i)"
wenzelm@12897
  1956
  -- {* Equivalent version *}
wenzelm@12897
  1957
  by blast
wenzelm@12897
  1958
wenzelm@12897
  1959
lemma Int_UN_distrib: "B \<inter> (\<Union>i\<in>I. A i) = (\<Union>i\<in>I. B \<inter> A i)"
wenzelm@12897
  1960
  -- {* Halmos, Naive Set Theory, page 35. *}
wenzelm@12897
  1961
  by blast
wenzelm@12897
  1962
wenzelm@12897
  1963
lemma Un_INT_distrib: "B \<union> (\<Inter>i\<in>I. A i) = (\<Inter>i\<in>I. B \<union> A i)"
wenzelm@12897
  1964
  by blast
wenzelm@12897
  1965
wenzelm@12897
  1966
lemma Int_UN_distrib2: "(\<Union>i\<in>I. A i) \<inter> (\<Union>j\<in>J. B j) = (\<Union>i\<in>I. \<Union>j\<in>J. A i \<inter> B j)"
wenzelm@12897
  1967
  by blast
wenzelm@12897
  1968
wenzelm@12897
  1969
lemma Un_INT_distrib2: "(\<Inter>i\<in>I. A i) \<union> (\<Inter>j\<in>J. B j) = (\<Inter>i\<in>I. \<Inter>j\<in>J. A i \<union> B j)"
wenzelm@12897
  1970
  by blast
wenzelm@12897
  1971
wenzelm@12897
  1972
wenzelm@12897
  1973
text {* \medskip Bounded quantifiers.
wenzelm@12897
  1974
wenzelm@12897
  1975
  The following are not added to the default simpset because
wenzelm@12897
  1976
  (a) they duplicate the body and (b) there are no similar rules for @{text Int}. *}
wenzelm@12897
  1977
wenzelm@12897
  1978
lemma ball_Un: "(\<forall>x \<in> A \<union> B. P x) = ((\<forall>x\<in>A. P x) & (\<forall>x\<in>B. P x))"
wenzelm@12897
  1979
  by blast
wenzelm@12897
  1980
wenzelm@12897
  1981
lemma bex_Un: "(\<exists>x \<in> A \<union> B. P x) = ((\<exists>x\<in>A. P x) | (\<exists>x\<in>B. P x))"
wenzelm@12897
  1982
  by blast
wenzelm@12897
  1983
wenzelm@12897
  1984
lemma ball_UN: "(\<forall>z \<in> UNION A B. P z) = (\<forall>x\<in>A. \<forall>z \<in> B x. P z)"
wenzelm@12897
  1985
  by blast
wenzelm@12897
  1986
wenzelm@12897
  1987
lemma bex_UN: "(\<exists>z \<in> UNION A B. P z) = (\<exists>x\<in>A. \<exists>z\<in>B x. P z)"
wenzelm@12897
  1988
  by blast
wenzelm@12897
  1989
wenzelm@12897
  1990
wenzelm@12897
  1991
text {* \medskip Set difference. *}
wenzelm@12897
  1992
wenzelm@12897
  1993
lemma Diff_eq: "A - B = A \<inter> (-B)"
wenzelm@12897
  1994
  by blast
wenzelm@12897
  1995
paulson@24286
  1996
lemma Diff_eq_empty_iff [simp,noatp]: "(A - B = {}) = (A \<subseteq> B)"
wenzelm@12897
  1997
  by blast
wenzelm@12897
  1998
wenzelm@12897
  1999
lemma Diff_cancel [simp]: "A - A = {}"
wenzelm@12897
  2000
  by blast
wenzelm@12897
  2001
nipkow@14302
  2002
lemma Diff_idemp [simp]: "(A - B) - B = A - (B::'a set)"
nipkow@14302
  2003
by blast
nipkow@14302
  2004
wenzelm@12897
  2005
lemma Diff_triv: "A \<inter> B = {} ==> A - B = A"
wenzelm@12897
  2006
  by (blast elim: equalityE)
wenzelm@12897
  2007
wenzelm@12897
  2008
lemma empty_Diff [simp]: "{} - A = {}"
wenzelm@12897
  2009
  by blast
wenzelm@12897
  2010
wenzelm@12897
  2011
lemma Diff_empty [simp]: "A - {} = A"
wenzelm@12897
  2012
  by blast
wenzelm@12897
  2013
wenzelm@12897
  2014
lemma Diff_UNIV [simp]: "A - UNIV = {}"
wenzelm@12897
  2015
  by blast
wenzelm@12897
  2016
paulson@24286
  2017
lemma Diff_insert0 [simp,noatp]: "x \<notin> A ==> A - insert x B = A - B"
wenzelm@12897
  2018
  by blast
wenzelm@12897
  2019
wenzelm@12897
  2020
lemma Diff_insert: "A - insert a B = A - B - {a}"
wenzelm@12897
  2021
  -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}
wenzelm@12897
  2022
  by blast
wenzelm@12897
  2023
wenzelm@12897
  2024
lemma Diff_insert2: "A - insert a B = A - {a} - B"
wenzelm@12897
  2025
  -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}
wenzelm@12897
  2026
  by blast
wenzelm@12897
  2027
wenzelm@12897
  2028
lemma insert_Diff_if: "insert x A - B = (if x \<in> B then A - B else insert x (A - B))"
wenzelm@12897
  2029
  by auto
wenzelm@12897
  2030
wenzelm@12897
  2031
lemma insert_Diff1 [simp]: "x \<in> B ==> insert x A - B = A - B"
wenzelm@12897
  2032
  by blast
wenzelm@12897
  2033
nipkow@14302
  2034
lemma insert_Diff_single[simp]: "insert a (A - {a}) = insert a A"
nipkow@14302
  2035
by blast
nipkow@14302
  2036
wenzelm@12897
  2037
lemma insert_Diff: "a \<in> A ==> insert a (A - {a}) = A"
wenzelm@12897
  2038
  by blast
wenzelm@12897
  2039
wenzelm@12897
  2040
lemma Diff_insert_absorb: "x \<notin> A ==> (insert x A) - {x} = A"
wenzelm@12897
  2041
  by auto
wenzelm@12897
  2042
wenzelm@12897
  2043
lemma Diff_disjoint [simp]: "A \<inter> (B - A) = {}"
wenzelm@12897
  2044
  by blast
wenzelm@12897
  2045
wenzelm@12897
  2046
lemma Diff_partition: "A \<subseteq> B ==> A \<union> (B - A) = B"
wenzelm@12897
  2047
  by blast
wenzelm@12897
  2048
wenzelm@12897
  2049
lemma double_diff: "A \<subseteq> B ==> B \<subseteq> C ==> B - (C - A) = A"
wenzelm@12897
  2050
  by blast
wenzelm@12897
  2051
wenzelm@12897
  2052
lemma Un_Diff_cancel [simp]: "A \<union> (B - A) = A \<union> B"
wenzelm@12897
  2053
  by blast
wenzelm@12897
  2054
wenzelm@12897
  2055
lemma Un_Diff_cancel2 [simp]: "(B - A) \<union> A = B \<union> A"
wenzelm@12897
  2056
  by blast
wenzelm@12897
  2057
wenzelm@12897
  2058
lemma Diff_Un: "A - (B \<union> C) = (A - B) \<inter> (A - C)"
wenzelm@12897
  2059
  by blast
wenzelm@12897
  2060
wenzelm@12897
  2061
lemma Diff_Int: "A - (B \<inter> C) = (A - B) \<union> (A - C)"
wenzelm@12897
  2062
  by blast
wenzelm@12897
  2063
wenzelm@12897
  2064
lemma Un_Diff: "(A \<union> B) - C = (A - C) \<union> (B - C)"
wenzelm@12897
  2065
  by blast
wenzelm@12897
  2066
wenzelm@12897
  2067
lemma Int_Diff: "(A \<inter> B) - C = A \<inter> (B - C)"
wenzelm@12897
  2068
  by blast
wenzelm@12897
  2069
wenzelm@12897
  2070
lemma Diff_Int_distrib: "C \<inter> (A - B) = (C \<inter> A) - (C \<inter> B)"
wenzelm@12897
  2071
  by blast
wenzelm@12897
  2072
wenzelm@12897
  2073
lemma Diff_Int_distrib2: "(A - B) \<inter> C = (A \<inter> C) - (B \<inter> C)"
wenzelm@12897
  2074
  by blast
wenzelm@12897
  2075
wenzelm@12897
  2076
lemma Diff_Compl [simp]: "A - (- B) = A \<inter> B"
wenzelm@12897
  2077
  by auto
wenzelm@12897
  2078
wenzelm@12897
  2079
lemma Compl_Diff_eq [simp]: "- (A - B) = -A \<union> B"
wenzelm@12897
  2080
  by blast
wenzelm@12897
  2081
wenzelm@12897
  2082
wenzelm@12897
  2083
text {* \medskip Quantification over type @{typ bool}. *}
wenzelm@12897
  2084
wenzelm@12897
  2085
lemma bool_induct: "P True \<Longrightarrow> P False \<Longrightarrow> P x"
haftmann@21549
  2086
  by (cases x) auto
haftmann@21549
  2087
haftmann@21549
  2088
lemma all_bool_eq: "(\<forall>b. P b) \<longleftrightarrow> P True \<and> P False"
haftmann@21549
  2089
  by (auto intro: bool_induct)
haftmann@21549
  2090
haftmann@21549
  2091
lemma bool_contrapos: "P x \<Longrightarrow> \<not> P False \<Longrightarrow> P True"
haftmann@21549
  2092
  by (cases x) auto
haftmann@21549
  2093
haftmann@21549
  2094
lemma ex_bool_eq: "(\<exists>b. P b) \<longleftrightarrow> P True \<or> P False"
haftmann@21549
  2095
  by (auto intro: bool_contrapos)
wenzelm@12897
  2096
wenzelm@12897
  2097
lemma Un_eq_UN: "A \<union> B = (\<Union>b. if b then A else B)"
wenzelm@12897
  2098
  by (auto simp add: split_if_mem2)
wenzelm@12897
  2099
wenzelm@12897
  2100
lemma UN_bool_eq: "(\<Union>b::bool. A b) = (A True \<union> A False)"
haftmann@21549
  2101
  by (auto intro: bool_contrapos)
wenzelm@12897
  2102
wenzelm@12897
  2103
lemma INT_bool_eq: "(\<Inter>b::bool. A b) = (A True \<inter> A False)"
haftmann@21549
  2104
  by (auto intro: bool_induct)
wenzelm@12897
  2105
wenzelm@12897
  2106
text {* \medskip @{text Pow} *}
wenzelm@12897
  2107
wenzelm@12897
  2108
lemma Pow_empty [simp]: "Pow {} = {{}}"
wenzelm@12897
  2109
  by (auto simp add: Pow_def)
wenzelm@12897
  2110
wenzelm@12897
  2111
lemma Pow_insert: "Pow (insert a A) = Pow A \<union> (insert a ` Pow A)"
wenzelm@12897
  2112
  by (blast intro: image_eqI [where ?x = "u - {a}", standard])
wenzelm@12897
  2113
wenzelm@12897
  2114
lemma Pow_Compl: "Pow (- A) = {-B | B. A \<in> Pow B}"
wenzelm@12897
  2115
  by (blast intro: exI [where ?x = "- u", standard])
wenzelm@12897
  2116
wenzelm@12897
  2117
lemma Pow_UNIV [simp]: "Pow UNIV = UNIV"
wenzelm@12897
  2118
  by blast
wenzelm@12897
  2119
wenzelm@12897
  2120
lemma Un_Pow_subset: "Pow A \<union> Pow B \<subseteq> Pow (A \<union> B)"
wenzelm@12897
  2121
  by blast
wenzelm@12897
  2122
wenzelm@12897
  2123
lemma UN_Pow_subset: "(\<Union>x\<in>A. Pow (B x)) \<subseteq> Pow (\<Union>x\<in>A. B x)"
wenzelm@12897
  2124
  by blast
wenzelm@12897
  2125
wenzelm@12897
  2126
lemma subset_Pow_Union: "A \<subseteq> Pow (\<Union>A)"
wenzelm@12897
  2127
  by blast
wenzelm@12897
  2128
wenzelm@12897
  2129
lemma Union_Pow_eq [simp]: "\<Union>(Pow A) = A"
wenzelm@12897
  2130
  by blast
wenzelm@12897
  2131
wenzelm@12897
  2132
lemma Pow_Int_eq [simp]: "Pow (A \<inter> B) = Pow A \<inter> Pow B"
wenzelm@12897
  2133
  by blast
wenzelm@12897
  2134
wenzelm@12897
  2135
lemma Pow_INT_eq: "Pow (\<Inter>x\<in>A. B x) = (\<Inter>x\<in>A. Pow (B x))"
wenzelm@12897
  2136
  by blast
wenzelm@12897
  2137
wenzelm@12897
  2138
wenzelm@12897
  2139
text {* \medskip Miscellany. *}
wenzelm@12897
  2140
wenzelm@12897
  2141
lemma set_eq_subset: "(A = B) = (A \<subseteq> B & B \<subseteq> A)"
wenzelm@12897
  2142
  by blast
wenzelm@12897
  2143
wenzelm@12897
  2144
lemma subset_iff: "(A \<subseteq> B) = (\<forall>t. t \<in> A --> t \<in> B)"
wenzelm@12897
  2145
  by blast
wenzelm@12897
  2146
wenzelm@12897
  2147
lemma subset_iff_psubset_eq: "(A \<subseteq> B) = ((A \<subset> B) | (A = B))"
berghofe@26800
  2148
  by (unfold less_le) blast
wenzelm@12897
  2149
paulson@18447
  2150
lemma all_not_in_conv [simp]: "(\<forall>x. x \<notin> A) = (A = {})"
wenzelm@12897
  2151
  by blast
wenzelm@12897
  2152
paulson@13831
  2153
lemma ex_in_conv: "(\<exists>x. x \<in> A) = (A \<noteq> {})"
paulson@13831
  2154
  by blast
paulson@13831
  2155
wenzelm@12897
  2156
lemma distinct_lemma: "f x \<noteq> f y ==> x \<noteq> y"
nipkow@17589
  2157
  by iprover
wenzelm@12897
  2158
wenzelm@12897
  2159
paulson@13860
  2160
text {* \medskip Miniscoping: pushing in quantifiers and big Unions
paulson@13860
  2161
           and Intersections. *}
wenzelm@12897
  2162
wenzelm@12897
  2163
lemma UN_simps [simp]:
wenzelm@12897
  2164
  "!!a B C. (UN x:C. insert a (B x)) = (if C={} then {} else insert a (UN x:C. B x))"
wenzelm@12897
  2165
  "!!A B C. (UN x:C. A x Un B)   = ((if C={} then {} else (UN x:C. A x) Un B))"
wenzelm@12897
  2166
  "!!A B C. (UN x:C. A Un B x)   = ((if C={} then {} else A Un (UN x:C. B x)))"
wenzelm@12897
  2167
  "!!A B C. (UN x:C. A x Int B)  = ((UN x:C. A x) Int B)"
wenzelm@12897
  2168
  "!!A B C. (UN x:C. A Int B x)  = (A Int (UN x:C. B x))"
wenzelm@12897
  2169
  "!!A B C. (UN x:C. A x - B)    = ((UN x:C. A x) - B)"
wenzelm@12897
  2170
  "!!A B C. (UN x:C. A - B x)    = (A - (INT x:C. B x))"
wenzelm@12897
  2171
  "!!A B. (UN x: Union A. B x) = (UN y:A. UN x:y. B x)"
wenzelm@12897
  2172
  "!!A B C. (UN z: UNION A B. C z) = (UN  x:A. UN z: B(x). C z)"
wenzelm@12897
  2173
  "!!A B f. (UN x:f`A. B x)     = (UN a:A. B (f a))"
wenzelm@12897
  2174
  by auto
wenzelm@12897
  2175
wenzelm@12897
  2176
lemma INT_simps [simp]:
wenzelm@12897
  2177
  "!!A B C. (INT x:C. A x Int B) = (if C={} then UNIV else (INT x:C. A x) Int B)"
wenzelm@12897
  2178
  "!!A B C. (INT x:C. A Int B x) = (if C={} then UNIV else A Int (INT x:C. B x))"
wenzelm@12897
  2179
  "!!A B C. (INT x:C. A x - B)   = (if C={} then UNIV else (INT x:C. A x) - B)"
wenzelm@12897
  2180
  "!!A B C. (INT x:C. A - B x)   = (if C={} then UNIV else A - (UN x:C. B x))"
wenzelm@12897
  2181
  "!!a B C. (INT x:C. insert a (B x)) = insert a (INT x:C. B x)"
wenzelm@12897
  2182
  "!!A B C. (INT x:C. A x Un B)  = ((INT x:C. A x) Un B)"
wenzelm@12897
  2183
  "!!A B C. (INT x:C. A Un B x)  = (A Un (INT x:C. B x))"
wenzelm@12897
  2184
  "!!A B. (INT x: Union A. B x) = (INT y:A. INT x:y. B x)"
wenzelm@12897
  2185
  "!!A B C. (INT z: UNION A B. C z) = (INT x:A. INT z: B(x). C z)"
wenzelm@12897
  2186
  "!!A B f. (INT x:f`A. B x)    = (INT a:A. B (f a))"
wenzelm@12897
  2187
  by auto
wenzelm@12897
  2188
paulson@24286
  2189
lemma ball_simps [simp,noatp]:
wenzelm@12897
  2190
  "!!A P Q. (ALL x:A. P x | Q) = ((ALL x:A. P x) | Q)"
wenzelm@12897
  2191
  "!!A P Q. (ALL x:A. P | Q x) = (P | (ALL x:A. Q x))"
wenzelm@12897
  2192
  "!!A P Q. (ALL x:A. P --> Q x) = (P --> (ALL x:A. Q x))"
wenzelm@12897
  2193
  "!!A P Q. (ALL x:A. P x --> Q) = ((EX x:A. P x) --> Q)"
wenzelm@12897
  2194
  "!!P. (ALL x:{}. P x) = True"
wenzelm@12897
  2195
  "!!P. (ALL x:UNIV. P x) = (ALL x. P x)"
wenzelm@12897
  2196
  "!!a B P. (ALL x:insert a B. P x) = (P a & (ALL x:B. P x))"
wenzelm@12897
  2197
  "!!A P. (ALL x:Union A. P x) = (ALL y:A. ALL x:y. P x)"
wenzelm@12897
  2198
  "!!A B P. (ALL x: UNION A B. P x) = (ALL a:A. ALL x: B a. P x)"
wenzelm@12897
  2199
  "!!P Q. (ALL x:Collect Q. P x) = (ALL x. Q x --> P x)"
wenzelm@12897
  2200
  "!!A P f. (ALL x:f`A. P x) = (ALL x:A. P (f x))"
wenzelm@12897
  2201
  "!!A P. (~(ALL x:A. P x)) = (EX x:A. ~P x)"
wenzelm@12897
  2202
  by auto
wenzelm@12897
  2203
paulson@24286
  2204
lemma bex_simps [simp,noatp]:
wenzelm@12897
  2205
  "!!A P Q. (EX x:A. P x & Q) = ((EX x:A. P x) & Q)"
wenzelm@12897
  2206
  "!!A P Q. (EX x:A. P & Q x) = (P & (EX x:A. Q x))"
wenzelm@12897
  2207
  "!!P. (EX x:{}. P x) = False"
wenzelm@12897
  2208
  "!!P. (EX x:UNIV. P x) = (EX x. P x)"
wenzelm@12897
  2209
  "!!a B P. (EX x:insert a B. P x) = (P(a) | (EX x:B. P x))"
wenzelm@12897
  2210
  "!!A P. (EX x:Union A. P x) = (EX y:A. EX x:y. P x)"
wenzelm@12897
  2211
  "!!A B P. (EX x: UNION A B. P x) = (EX a:A. EX x:B a. P x)"
wenzelm@12897
  2212
  "!!P Q. (EX x:Collect Q. P x) = (EX x. Q x & P x)"
wenzelm@12897
  2213
  "!!A P f. (EX x:f`A. P x) = (EX x:A. P (f x))"
wenzelm@12897
  2214
  "!!A P. (~(EX x:A. P x)) = (ALL x:A. ~P x)"
wenzelm@12897
  2215
  by auto
wenzelm@12897
  2216
wenzelm@12897
  2217
lemma ball_conj_distrib:
wenzelm@12897
  2218
  "(ALL x:A. P x & Q x) = ((ALL x:A. P x) & (ALL x:A. Q x))"
wenzelm@12897
  2219
  by blast
wenzelm@12897
  2220
wenzelm@12897
  2221
lemma bex_disj_distrib:
wenzelm@12897
  2222
  "(EX x:A. P x | Q x) = ((EX x:A. P x) | (EX x:A. Q x))"
wenzelm@12897
  2223
  by blast
wenzelm@12897
  2224
wenzelm@12897
  2225
paulson@13860
  2226
text {* \medskip Maxiscoping: pulling out big Unions and Intersections. *}
paulson@13860
  2227
paulson@13860
  2228
lemma UN_extend_simps:
paulson@13860
  2229
  "!!a B C. insert a (UN x:C. B x) = (if C={} then {a} else (UN x:C. insert a (B x)))"
paulson@13860
  2230
  "!!A B C. (UN x:C. A x) Un B    = (if C={} then B else (UN x:C. A x Un B))"
paulson@13860
  2231
  "!!A B C. A Un (UN x:C. B x)   = (if C={} then A else (UN x:C. A Un B x))"
paulson@13860
  2232
  "!!A B C. ((UN x:C. A x) Int B) = (UN x:C. A x Int B)"
paulson@13860
  2233
  "!!A B C. (A Int (UN x:C. B x)) = (UN x:C. A Int B x)"
paulson@13860
  2234
  "!!A B C. ((UN x:C. A x) - B) = (UN x:C. A x - B)"
paulson@13860
  2235
  "!!A B C. (A - (INT x:C. B x)) = (UN x:C. A - B x)"
paulson@13860
  2236
  "!!A B. (UN y:A. UN x:y. B x) = (UN x: Union A. B x)"
paulson@13860
  2237
  "!!A B C. (UN  x:A. UN z: B(x). C z) = (UN z: UNION A B. C z)"
paulson@13860
  2238
  "!!A B f. (UN a:A. B (f a)) = (UN x:f`A. B x)"
paulson@13860
  2239
  by auto
paulson@13860
  2240
paulson@13860
  2241
lemma INT_extend_simps:
paulson@13860
  2242
  "!!A B C. (INT x:C. A x) Int B = (if C={} then B else (INT x:C. A x Int B))"
paulson@13860
  2243
  "!!A B C. A Int (INT x:C. B x) = (if C={} then A else (INT x:C. A Int B x))"
paulson@13860
  2244
  "!!A B C. (INT x:C. A x) - B   = (if C={} then UNIV-B else (INT x:C. A x - B))"
paulson@13860
  2245
  "!!A B C. A - (UN x:C. B x)   = (if C={} then A else (INT x:C. A - B x))"
paulson@13860
  2246
  "!!a B C. insert a (INT x:C. B x) = (INT x:C. insert a (B x))"
paulson@13860
  2247
  "!!A B C. ((INT x:C. A x) Un B)  = (INT x:C. A x Un B)"
paulson@13860
  2248
  "!!A B C. A Un (INT x:C. B x)  = (INT x:C. A Un B x)"
paulson@13860
  2249
  "!!A B. (INT y:A. INT x:y. B x) = (INT x: Union A. B x)"
paulson@13860
  2250
  "!!A B C. (INT x:A. INT z: B(x). C z) = (INT z: UNION A B. C z)"
paulson@13860
  2251
  "!!A B f. (INT a:A. B (f a))    = (INT x:f`A. B x)"
paulson@13860
  2252
  by auto
paulson@13860
  2253
paulson@13860
  2254
wenzelm@12897
  2255
subsubsection {* Monotonicity of various operations *}
wenzelm@12897
  2256
wenzelm@12897
  2257
lemma image_mono: "A \<subseteq> B ==> f`A \<subseteq> f`B"
wenzelm@12897
  2258
  by blast
wenzelm@12897
  2259
wenzelm@12897
  2260
lemma Pow_mono: "A \<subseteq> B ==> Pow A \<subseteq> Pow B"
wenzelm@12897
  2261
  by blast
wenzelm@12897
  2262
wenzelm@12897
  2263
lemma Union_mono: "A \<subseteq> B ==> \<Union>A \<subseteq> \<Union>B"
wenzelm@12897
  2264
  by blast
wenzelm@12897
  2265
wenzelm@12897
  2266
lemma Inter_anti_mono: "B \<subseteq> A ==> \<Inter>A \<subseteq> \<Inter>B"
wenzelm@12897
  2267
  by blast
wenzelm@12897
  2268
wenzelm@12897
  2269
lemma UN_mono:
wenzelm@12897
  2270
  "A \<subseteq> B ==> (!!x. x \<in> A ==> f x \<subseteq> g x) ==>
wenzelm@12897
  2271
    (\<Union>x\<in>A. f x) \<subseteq> (\<Union>x\<in>B. g x)"
wenzelm@12897
  2272
  by (blast dest: subsetD)
wenzelm@12897
  2273
wenzelm@12897
  2274
lemma INT_anti_mono:
wenzelm@12897
  2275
  "B \<subseteq> A ==> (!!x. x \<in> A ==> f x \<subseteq> g x) ==>
wenzelm@12897
  2276
    (\<Inter>x\<in>A. f x) \<subseteq> (\<Inter>x\<in>A. g x)"
wenzelm@12897
  2277
  -- {* The last inclusion is POSITIVE! *}
wenzelm@12897
  2278
  by (blast dest: subsetD)
wenzelm@12897
  2279
wenzelm@12897
  2280
lemma insert_mono: "C \<subseteq> D ==> insert a C \<subseteq> insert a D"
wenzelm@12897
  2281
  by blast
wenzelm@12897
  2282
wenzelm@12897
  2283
lemma Un_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<union> B \<subseteq> C \<union> D"
wenzelm@12897
  2284
  by blast
wenzelm@12897
  2285
wenzelm@12897
  2286
lemma Int_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<inter> B \<subseteq> C \<inter> D"
wenzelm@12897
  2287
  by blast
wenzelm@12897
  2288
wenzelm@12897
  2289
lemma Diff_mono: "A \<subseteq> C ==> D \<subseteq> B ==> A - B \<subseteq> C - D"
wenzelm@12897
  2290
  by blast
wenzelm@12897
  2291
wenzelm@12897
  2292
lemma Compl_anti_mono: "A \<subseteq> B ==> -B \<subseteq> -A"
wenzelm@12897
  2293
  by blast
wenzelm@12897
  2294
wenzelm@12897
  2295
text {* \medskip Monotonicity of implications. *}
wenzelm@12897
  2296
wenzelm@12897
  2297
lemma in_mono: "A \<subseteq> B ==> x \<in> A --> x \<in> B"
wenzelm@12897
  2298
  apply (rule impI)
paulson@14208
  2299
  apply (erule subsetD, assumption)
wenzelm@12897
  2300
  done
wenzelm@12897
  2301
wenzelm@12897
  2302
lemma conj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 & P2) --> (Q1 & Q2)"
nipkow@17589
  2303
  by iprover
wenzelm@12897
  2304
wenzelm@12897
  2305
lemma disj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 | P2) --> (Q1 | Q2)"
nipkow@17589
  2306
  by iprover
wenzelm@12897
  2307
wenzelm@12897
  2308
lemma imp_mono: "Q1 --> P1 ==> P2 --> Q2 ==> (P1 --> P2) --> (Q1 --> Q2)"
nipkow@17589
  2309
  by iprover
wenzelm@12897
  2310
wenzelm@12897
  2311
lemma imp_refl: "P --> P" ..
wenzelm@12897
  2312
wenzelm@12897
  2313
lemma ex_mono: "(!!x. P x --> Q x) ==> (EX x. P x) --> (EX x. Q x)"
nipkow@17589
  2314
  by iprover
wenzelm@12897
  2315
wenzelm@12897
  2316
lemma all_mono: "(!!x. P x --> Q x) ==> (ALL x. P x) --> (ALL x. Q x)"
nipkow@17589
  2317
  by iprover
wenzelm@12897
  2318
wenzelm@12897
  2319
lemma Collect_mono: "(!!x. P x --> Q x) ==> Collect P \<subseteq> Collect Q"
wenzelm@12897
  2320
  by blast
wenzelm@12897
  2321
wenzelm@12897
  2322
lemma Int_Collect_mono:
wenzelm@12897
  2323
    "A \<subseteq> B ==> (!!x. x \<in> A ==> P x --> Q x) ==> A \<inter> Collect P \<subseteq> B \<inter> Collect Q"
wenzelm@12897
  2324
  by blast
wenzelm@12897
  2325
wenzelm@12897
  2326
lemmas basic_monos =
wenzelm@12897
  2327
  subset_refl imp_refl disj_mono conj_mono
wenzelm@12897
  2328
  ex_mono Collect_mono in_mono
wenzelm@12897
  2329
wenzelm@12897
  2330
lemma eq_to_mono: "a = b ==> c = d ==> b --> d ==> a --> c"
nipkow@17589
  2331
  by iprover
wenzelm@12897
  2332
wenzelm@12897
  2333
lemma eq_to_mono2: "a = b ==> c = d ==> ~ b --> ~ d ==> ~ a --> ~ c"
nipkow@17589
  2334
  by iprover
wenzelm@11979
  2335
wenzelm@12020
  2336
haftmann@30531
  2337
subsection {* Inverse image of a function *}
wenzelm@12257
  2338
wenzelm@12257
  2339
constdefs
wenzelm@12257
  2340
  vimage :: "('a => 'b) => 'b set => 'a set"    (infixr "-`" 90)
haftmann@28562
  2341
  [code del]: "f -` B == {x. f x : B}"
wenzelm@12257
  2342
haftmann@30531
  2343
haftmann@30531
  2344
subsubsection {* Basic rules *}
haftmann@30531
  2345
wenzelm@12257
  2346
lemma vimage_eq [simp]: "(a : f -` B) = (f a : B)"
wenzelm@12257
  2347
  by (unfold vimage_def) blast
wenzelm@12257
  2348
wenzelm@12257
  2349
lemma vimage_singleton_eq: "(a : f -` {b}) = (f a = b)"
wenzelm@12257
  2350
  by simp
wenzelm@12257
  2351
wenzelm@12257
  2352
lemma vimageI [intro]: "f a = b ==> b:B ==> a : f -` B"
wenzelm@12257
  2353
  by (unfold vimage_def) blast
wenzelm@12257
  2354
wenzelm@12257
  2355
lemma vimageI2: "f a : A ==> a : f -` A"
wenzelm@12257
  2356
  by (unfold vimage_def) fast
wenzelm@12257
  2357
wenzelm@12257
  2358
lemma vimageE [elim!]: "a: f -` B ==> (!!x. f a = x ==> x:B ==> P) ==> P"
wenzelm@12257
  2359
  by (unfold vimage_def) blast
wenzelm@12257
  2360
wenzelm@12257
  2361
lemma vimageD: "a : f -` A ==> f a : A"
wenzelm@12257
  2362
  by (unfold vimage_def) fast
wenzelm@12257
  2363
haftmann@30531
  2364
haftmann@30531
  2365
subsubsection {* Equations *}
haftmann@30531
  2366
wenzelm@12257
  2367
lemma vimage_empty [simp]: "f -` {} = {}"
wenzelm@12257
  2368
  by blast
wenzelm@12257
  2369
wenzelm@12257
  2370
lemma vimage_Compl: "f -` (-A) = -(f -` A)"
wenzelm@12257
  2371
  by blast
wenzelm@12257
  2372
wenzelm@12257
  2373
lemma vimage_Un [simp]: "f -` (A Un B) = (f -` A) Un (f -` B)"
wenzelm@12257
  2374
  by blast
wenzelm@12257
  2375
wenzelm@12257
  2376
lemma vimage_Int [simp]: "f -` (A Int B) = (f -` A) Int (f -` B)"
wenzelm@12257
  2377
  by fast
wenzelm@12257
  2378
wenzelm@12257
  2379
lemma vimage_Union: "f -` (Union A) = (UN X:A. f -` X)"
wenzelm@12257
  2380
  by blast
wenzelm@12257
  2381
wenzelm@12257
  2382
lemma vimage_UN: "f-`(UN x:A. B x) = (UN x:A. f -` B x)"
wenzelm@12257
  2383
  by blast
wenzelm@12257
  2384
wenzelm@12257
  2385
lemma vimage_INT: "f-`(INT x:A. B x) = (INT x:A. f -` B x)"
wenzelm@12257
  2386
  by blast
wenzelm@12257
  2387
wenzelm@12257
  2388
lemma vimage_Collect_eq [simp]: "f -` Collect P = {y. P (f y)}"
wenzelm@12257
  2389
  by blast
wenzelm@12257
  2390
wenzelm@12257
  2391
lemma vimage_Collect: "(!!x. P (f x) = Q x) ==> f -` (Collect P) = Collect Q"
wenzelm@12257
  2392
  by blast
wenzelm@12257
  2393
wenzelm@12257
  2394
lemma vimage_insert: "f-`(insert a B) = (f-`{a}) Un (f-`B)"
wenzelm@12257
  2395
  -- {* NOT suitable for rewriting because of the recurrence of @{term "{a}"}. *}
wenzelm@12257
  2396
  by blast
wenzelm@12257
  2397
wenzelm@12257
  2398
lemma vimage_Diff: "f -` (A - B) = (f -` A) - (f -` B)"
wenzelm@12257
  2399
  by blast
wenzelm@12257
  2400
wenzelm@12257
  2401
lemma vimage_UNIV [simp]: "f -` UNIV = UNIV"
wenzelm@12257
  2402
  by blast
wenzelm@12257
  2403
wenzelm@12257
  2404
lemma vimage_eq_UN: "f-`B = (UN y: B. f-`{y})"
wenzelm@12257
  2405
  -- {* NOT suitable for rewriting *}
wenzelm@12257
  2406
  by blast
wenzelm@12257
  2407
wenzelm@12897
  2408
lemma vimage_mono: "A \<subseteq> B ==> f -` A \<subseteq> f -` B"
wenzelm@12257
  2409
  -- {* monotonicity *}
wenzelm@12257
  2410
  by blast
wenzelm@12257
  2411
haftmann@26150
  2412
lemma vimage_image_eq [noatp]: "f -` (f ` A) = {y. EX x:A. f x = f y}"
haftmann@26150
  2413
by (blast intro: sym)
haftmann@26150
  2414
haftmann@26150
  2415
lemma image_vimage_subset: "f ` (f -` A) <= A"
haftmann@26150
  2416
by blast
haftmann@26150
  2417
haftmann@26150
  2418
lemma image_vimage_eq [simp]: "f ` (f -` A) = A Int range f"
haftmann@26150
  2419
by blast
haftmann@26150
  2420
haftmann@26150
  2421
lemma image_Int_subset: "f`(A Int B) <= f`A Int f`B"
haftmann@26150
  2422
by blast
haftmann@26150
  2423
haftmann@26150
  2424
lemma image_diff_subset: "f`A - f`B <= f`(A - B)"
haftmann@26150
  2425
by blast
haftmann@26150
  2426
haftmann@26150
  2427
lemma image_UN: "(f ` (UNION A B)) = (UN x:A.(f ` (B x)))"
haftmann@26150
  2428
by blast
haftmann@26150
  2429
wenzelm@12257
  2430
haftmann@30531
  2431
subsection {* Getting the Contents of a Singleton Set *}
haftmann@30531
  2432
haftmann@30531
  2433
definition contents :: "'a set \<Rightarrow> 'a" where
haftmann@30531
  2434
  [code del]: "contents X = (THE x. X = {x})"
haftmann@30531
  2435
haftmann@30531
  2436
lemma contents_eq [simp]: "contents {x} = x"
haftmann@30531
  2437
  by (simp add: contents_def)
haftmann@30531
  2438
haftmann@30531
  2439
haftmann@30531
  2440
subsection {* Transitivity rules for calculational reasoning *}
haftmann@30531
  2441
haftmann@30531
  2442
lemma set_rev_mp: "x:A ==> A \<subseteq> B ==> x:B"
haftmann@30531
  2443
  by (rule subsetD)
haftmann@30531
  2444
haftmann@30531
  2445
lemma set_mp: "A \<subseteq> B ==> x:A ==> x:B"
haftmann@30531
  2446
  by (rule subsetD)
haftmann@30531
  2447
haftmann@30531
  2448
lemmas basic_trans_rules [trans] =
haftmann@30531
  2449
  order_trans_rules set_rev_mp set_mp
haftmann@30531
  2450
haftmann@30531
  2451
haftmann@30531
  2452
subsection {* Least value operator *}