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