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